HabitSphere is a full-stack habit tracking application for creating routines, recording daily progress, reviewing consistency, and generating data-driven reports. It is built as a responsive single-page application (SPA) with a framework-free Python JSON API and a MySQL database.
- Secure user registration, login, logout, and server-side sessions
- Create, view, edit, delete, search, filter, activate, and deactivate habits
- Daily habit tracking with completion counts, notes, target-aware completion, and a date selector
- Dashboard with active habits, progress, streaks, weekly activity, and current calendar week/month goals
- Habit analytics: completion percentage, current streak, longest streak, consistency score, success rate, and missed days
- Weekly and monthly Insight views
- Downloadable CSV and TXT reports generated from MySQL data
- Matplotlib bar, pie, weekly-progress, and monthly-trend charts
- JSON-managed application preferences: theme, default section, weekly/monthly goals, and export preference
- Logging and validation for important application operations
| Layer | Technologies |
|---|---|
| Frontend | HTML, CSS, JavaScript |
| Backend | Python with the built-in http.server and a custom JSON API handler |
| Database | MySQL with mysql-connector-python |
| Analytics | Pandas, Python date/time handling |
| Visualisation | Matplotlib |
| Settings | JSON |
No Flask, Django, React, Bootstrap, Tailwind CSS, or other web framework is used.
Browser SPA (index.html + static/css/style.css + static/js/app.js)
│ fetch() JSON requests
▼
Python built-in HTTP server (app.py)
▼
Business logic, validation, analytics, reports, charts (habit_tracker.py)
▼
MySQL database + JSON settings + generated reports/charts/logs
The frontend remains on one HTML page. JavaScript shows and hides SPA sections without full page navigation.
The database name is habit_tracker. The schema in database/schema.sql contains these tables:
| Table | Purpose |
|---|---|
USERS |
Registered account details and password hashes |
HABITS |
User habits, categories, goals, targets, start dates, and statuses |
HABIT_COMPLETION |
Dated completion counts and notes |
HABIT_ANALYTICS |
Persisted habit performance metrics |
IMPROVEMENT_TIPS |
Reserved by the approved schema for rule-based suggestions |
USERS (user_id)
└──< HABITS (habit_id, user_id)
├──< HABIT_COMPLETION (completion_id, habit_id)
├──< HABIT_ANALYTICS (analytics_id, habit_id)
└──< IMPROVEMENT_TIPS (tip_id, habit_id)
USERS → HABITS and HABITS → child tables are enforced with foreign keys and cascade deletion rules in the schema.
HabitSphere/
├── app.py # Framework-free HTTP server and JSON API routes
├── habit_tracker.py # OOP services: DB, auth, habits, tracking, analytics, reports, charts
├── index.html # Single-page application markup
├── requirements.txt # Pinned Python packages
├── database/
│ └── schema.sql # MySQL database schema
├── json/
│ └── settings.json # Application and database configuration
├── static/
│ ├── css/style.css # Responsive SPA styling
│ ├── js/app.js # SPA interaction and API requests
│ └── charts/ # Matplotlib charts generated at runtime
├── logs/
│ └── app.log # Application logs
├── reports/
│ ├── csv/ # Generated CSV reports
│ └── txt/ # Generated TXT reports
└── venv/ # Local virtual environment (created locally)
The current web application uses app.py, habit_tracker.py, MySQL, and json/settings.json.
- A user registers and signs in through the SPA.
- The Python server creates a secure, short-lived server-side session and sends an
HttpOnlycookie. - Habits and completions are stored in MySQL through JSON API requests.
- The dashboard retrieves live MySQL totals, today's active habits, calendar-week/month goals, and seven-day activity.
- Analytics calculate performance values from real completion records.
- Reports and charts are generated from those analytics and completion records.
- Habit completion percentage
- Current and longest daily streak
- Consistency score
- Success rate
- Missed days
- Most and least consistent habits
- Week (7-day) and month (30-day) Insight periods
The Reports page generates:
- Daily, weekly, and monthly CSV reports
- Daily, weekly, and monthly TXT reports
- Habit completion bar chart
- Completed-versus-missed pie chart
- Seven-day progress line chart
- Six-month trend line chart
Generated files are stored in reports/ and static/charts/.
- Python 3.13 or compatible Python 3 release
- MySQL Server running locally
- A MySQL account permitted to create/use the
habit_trackerdatabase
From the project root in PowerShell:
python -m venv venv
.\venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txtIf PowerShell blocks activation for the current terminal session:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
.\venv\Scripts\Activate.ps1- Start your local MySQL Server.
- Update the
databaseobject injson/settings.jsonwith your MySQL host, port, username, password, and database name. - Initialise the schema once:
python -c "from habit_tracker import DatabaseManager; DatabaseManager().initialize_schema()"The supplied schema creates the habit_tracker database and the required tables when they do not already exist.
Two settings areas are available:
json/settings.jsoncontains database/server configuration and default application preferences.- The in-app Settings SPA page updates theme, default section, weekly goal, monthly goal, and default report export format immediately.
For local development, the default server address is configured as 127.0.0.1:8000.
Activate the virtual environment, then run:
python app.pyOpen the application in a browser:
http://127.0.0.1:8000
Keep the terminal open while using the application. Press Ctrl + C to stop the server.
- Passwords are stored with PBKDF2-SHA256 hashing and a unique random salt.
- Passwords are not stored as plain text.
- Sessions use random server-side tokens with an expiry period.
- Session cookies are sent with
HttpOnlyandSameSite=Laxattributes. - API operations require an authenticated session where applicable.
- SQL parameters are passed through
mysql-connector-pythonparameterised queries.
For production deployment, move database credentials out of settings.json, use HTTPS, set Secure cookies, and use persistent session storage.
- Sessions are held in server memory; restarting the server logs users out.
- JSON preferences are application-wide rather than per-user.
- The approved database schema stores completion dates but does not include a separate completion-time column.
- The project is configured for local development and does not include production deployment configuration.
- Per-user preference storage
- Persistent session storage
- Scheduled reminders
- Rule-based improvement-tip generation using
IMPROVEMENT_TIPS - Calendar month view and historical completion heat map
- Account password reset workflow
- Production configuration with environment-based secrets and HTTPS
SHAIK AKHIL AHMED
HabitSphere was developed as a Python full-stack habit tracking and analytics project.