<<<<<<< HEAD <<<<<<< HEAD
Build consistency. Track progress. Stay accountable.
TRAC is a full-stack web application built with Django that enables users to create, track, and analyse personal habits. The system supports both daily and weekly habit cycles, automatically computes streak metrics, and provides a clean, responsive interface for long-term habit management.
TRAC is designed around a simple principle: consistency over intensity. The application provides users with actionable insights into their behaviour through streak tracking, historical visualization, and structured habit categorisation.
Each user operates in an isolated environment where they can:
- Define habits
- Track completion in real time
- Analyse performance over time
- Create, edit, and delete habits
- Support for daily and weekly periodicity
- Per-user data isolation
- One-click completion and undo functionality
- Asynchronous updates via Fetch API (no page reload)
- Current streak calculation
- Longest streak tracking
- Automatic streak start detection
- 30-day completion calendar per habit
- Visual distinction between completed and missed days
- Segregation of completed and incomplete habits
- Dedicated views for daily and weekly habits
- Highlighting of highest-performing habit
- User registration and login
- Ownership-based access restrictions
- Protected routes for all habit operations
| Layer | Technology |
|---|---|
| Backend | Django 5.1 |
| Language | Python 3.10+ |
| Database (Development) | SQLite |
| Database (Production) | PostgreSQL |
| Styling | Tailwind CSS (CDN) |
| Static File Serving | WhiteNoise |
| Application Server | Gunicorn |
| Environment Management | python-dotenv |
TRAC follows a modular, layered architecture consistent with standard Django practices.
trac/
├── habit/ # Core domain logic (models, views, tests)
├── habit_tracker/ # Project configuration
├── templates/ # Presentation layer
├── static/ # Frontend assets
├── manage.py # CLI entry point
Represents a user-defined behaviour to be tracked.
name— unique per userdescription— optional metadataperiodicity— daily or weeklyuser— ownership relationship- timestamps — creation and modification
Represents a completed instance of a habit.
habit— foreign key relationshipdate— completion date- unique constraint ensures one completion per day
-
Abstract Base Model Shared timestamp logic via a reusable base class
-
Custom Query Manager Encapsulates common filtering logic (
for_user,daily,weekly) -
Computed Properties Streak values exposed as properties for clean template access
-
Separation of Concerns Business logic is contained within models, not views
- Counts consecutive calendar days
- Iterates backward from today
- Stops at first missed day
- Based on ISO week definitions (Monday–Sunday)
- A week counts if at least one completion exists
- Tracks consecutive completed weeks
- Computed from historical completion records
- Resets on gaps in sequence
- Supports both daily and weekly modes
- Python 3.10+
- Git
git clone <repository-url>
cd tracpython -m venv venv
source venv/Scripts/activate # Windows (Git Bash)pip install -r requirements.txtcp .env.example .envGenerate a secret key:
python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"Update .env:
SECRET_KEY=your_secret_key
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhostpython manage.py migratepython manage.py createsuperuserpython manage.py runserverAccess the application:
http://127.0.0.1:8000
Users can define habits with a name, description, and periodicity.
Habits can be marked complete or undone instantly via the dashboard.
Each habit includes a detailed analytics page displaying:
- Current streak
- Longest streak
- Streak start date
- 30-day history
POST /habit/complete/<id>/
Response
{
"success": true,
"already_completed": false,
"current_streak": 5
}POST /habit/undo-complete/<id>/
Response
{
"success": true,
"current_streak": 4
}- Authentication required for all habit operations
- Ownership validation enforced at the view level
- CSRF protection enabled for all POST endpoints
- No cross-user data access permitted
For production environments:
- Switch database to PostgreSQL
- Set
DEBUG=False - Configure
ALLOWED_HOSTS - Use Gunicorn as the WSGI server
- Serve static files with WhiteNoise
f9509b7f8c0ce11bd64b8cdc09d9de9d24cc8ff5 =======
abd979236cb39310062b6b18457fcbc41c8d4f06