Skip to main content
Reading progress: 0%

Practical Project 1: Daily Focus & Habit Tracker

Difficulty: Beginner (Recommended First Project)
Estimated Effort: 1 weekend (working in small, calm 30–45 minute sessions)
Core Skills Practiced: Tight MVP scoping, intentional UI design, vertical-slice implementation, timezone bug debugging, unit & integration testing, Git workflow, and simple deployment.


Overview​

In this walkthrough, you will build a calm Daily Focus & Habit Tracker—a focused single-user web app where someone picks 1–5 daily habits, checks them off for today, and sees their daily completion count persist across page refreshes.

We intentionally avoid bloated features (no social feeds, no login walls in v1, no decorative charts) so you master the complete 9-phase workflow cleanly.


Phase 1: Idea & Product Thinking​

Problem Statement​

Self-directed learners and remote workers want to track 3–5 simple daily habits in under 10 seconds a day, because complex productivity apps feel overwhelming and end up abandoned after week one.

Challenging AI Assumptions​

  • AI initially suggested: "Add user accounts, streak leaderboards, push notifications, and weekly analytics charts!"
  • Your engineering decision: Reject all four. A single person opening their tracker on their primary computer/phone does not need a login wall in v1, and leaderboards add clutter.

MVP Scope​

  • Essential (In Scope for v1):
    1. View today's habits with a simple completed / total counter.
    2. Add a new habit (1–80 characters).
    3. Toggle a habit complete/incomplete for today's date.
    4. Delete a habit cleanly.
  • Out of Scope (Later): User accounts, multi-device sync, reminders, streaks history graphs, dark mode toggle.

Phase 2: Requirements & Planning​

Sample User Stories & Acceptance Criteria​

  • Story 1 (Add Habit): As a learner, I want to add a daily habit so it appears in today's checklist.
    • Blank or whitespace-only titles are rejected with an inline message.
    • Valid titles appear immediately and survive a browser refresh.
  • Story 2 (Toggle Complete): As a learner, I want to check off a habit for today so I can track daily progress.
    • Clicking toggles completion visually and updates the X / Y done counter.
    • Completion state persists across browser refresh for today's date.
  • Story 3 (Delete Habit): As a learner, I want to remove an unwanted habit so my list stays tidy.
    • Clicking Delete removes the habit immediately and updates the counter.

Development Plan (Milestones)​

  1. Milestone 1: Initialize repo, .gitignore, docs/, and verify blank starter runs on localhost.
  2. Milestone 2 (Slice 1): Database table + GET/POST /api/habits + Today Screen list & Add form + verify persistence.
  3. Milestone 3 (Slice 2): PATCH /api/habits/:id/toggle & DELETE /api/habits/:id + UI controls.
  4. Milestone 4: Fix edge cases, write automated tests, review security/code, deploy & smoke test.

Phase 3: UI/UX & Design​

Screen Inventory (1 Screen!)​

  • / (Today Screen): Header with today's readable date + X / Y pill, inline "Add habit" form, clean habit list (plus friendly empty state when 0 habits exist).

Text Wireframe​

+----------------------------------------------------+
| Daily Focus Tue, Dec 2 [1 / 3] |
+----------------------------------------------------+
| [ e.g. Read 15 pages... ] [ + Add ] |
+----------------------------------------------------+
| [x] Read 15 pages [Delete] |
| [ ] Walk 20 minutes [Delete] |
| [ ] Drink 2L water [Delete] |
+----------------------------------------------------+

Design Direction Rules​

  • Tone: Calm paper index card (#FAF9F6 page background, #FFFFFF card, #1E293B text, #15803D green accent).
  • Avoid: Purple gradients, floating cards with random percentages, cramped icon toolbars.
  • Mobile check: Single centered column (max-width: 600px), large tap targets (>= 44px height).

Phase 4: System Design & Architecture​

Chosen Stack (Simple & Portable)​

  • Option Chosen: Single unified web server (e.g., Node.js + Express or Python + FastAPI serving clean HTML/CSS/JS frontend files) backed by SQLite locally (or PostgreSQL if deploying to a stateless host).
  • Why: Zero separate frontend build servers to coordinate, easy for beginners to read end-to-end, works cleanly in every AI agent.

Data Model​

  • habits table: id (integer primary key), title (text, not null), last_completed_date (text YYYY-MM-DD, nullable), created_at (timestamp).

Phase 5: Project Setup​

(See Lesson 5.3: Setting Up Your Database for a step-by-step walkthrough of SQLite vs. PostgreSQL.)

  1. Create a folder daily-focus-tracker and run git init.
  2. Add docs/prd.md, docs/design-direction.md, docs/architecture.md.
  3. Create .gitignore (excluding .env, node_modules/, .venv/, *.db local database files) and .env.example (PORT=3000, DATABASE_URL=./data/habits.db).
  4. Set up your local SQLite database & table: No separate database software is needed for SQLite—have your starter setup script create ./data/habits.db and run your initial habits table creation query automatically on startup (or via a db:migrate script).
  5. Scaffold the minimal starter server with one GET /api/health endpoint checking database connectivity ({"ok": true, "database": "connected"}) and one index.html showing "Daily Focus" on http://localhost:3000.
  6. Run git status, verify .env and *.db do not appear, commit "chore: initial project skeleton and docs", and push to GitHub.

Phase 6: AI-Assisted Implementation (One Slice at a Time)​

Slice 1 Prompt Pattern (Inspect -> Plan -> Backend -> Frontend)​

  1. Inspect & Plan: Ask the agent to read docs/prd.md and docs/architecture.md, inspect existing files, and propose the exact files for Milestone 2 (habits table + GET/POST /api/habits + Add form).
  2. Backend first: Implement habits schema creation and GET /api/habits + POST /api/habits (checking title.trim() length 1–80, returning 400 with a clear JSON error if empty).
    • Verify yourself: Test GET /api/habits and POST /api/habits (both valid and empty "" title) before touching HTML/JS.
  3. Frontend second: Connect index.html + app.js to fetch and render habits, show the friendly empty state when habits.length === 0, and handle POST errors inline.
    • Verify yourself: Add 2 habits, refresh the page, confirm they remain; submit blank spaces, confirm inline error appears.
  4. Slice 2: Repeat the exact same workflow on a new branch (feat/toggle-and-delete) for PATCH toggle and DELETE.

Phase 7: Debugging & Quality​

Classic Beginner Bug Caught Here (Timezone Mismatch!)​

Suppose at 9:30 PM local time you check off a habit, refresh the page, and it shows unchecked!

  • Investigate instead of guessing: Inspect Browser DevTools Network response for GET /api/habits -> last_completed_date says "2026-12-03", while your browser's local date is "2026-12-02"!
  • Root Cause: The server used UTC (new Date().toISOString().slice(0, 10)), which already flipped to tomorrow in UTC while your laptop was still on today's evening date!
  • Targeted Fix: Pass the user's local YYYY-MM-DD date explicitly from the browser (or compute consistently using the agreed date logic) and add a unit/integration test checking date comparison.

Automated Tests to Write & Run​

  • Unit test: validateHabitTitle(" ") returns an error; validateHabitTitle("Read") passes.
  • Integration tests:
    • POST /api/habits with valid title returns 201 and appears in GET /api/habits.
    • POST /api/habits with blank title returns 400.
    • DELETE /api/habits/:id removes the item and returns 404 if deleted twice.

Phase 8: Git & Collaboration​

  1. Keep each milestone on its own short branch (feat/create-list-habits, feat/toggle-delete, test/api-coverage).
  2. Check git diff before committing—make sure no leftover console.log("debug") lines remain.
  3. Push each branch to GitHub, open a Pull Request, read the Files changed diff in GitHub, and merge into main.

Phase 9: Deployment & Verification​

  1. Check persistence before deploying: If your chosen host resets local disk files on redeploy, switch the production connection from a local SQLite file to a managed PostgreSQL database (or attach a persistent volume).
  2. Configure PORT (provided by host) and DATABASE_URL in the hosting dashboard's Environment Variables.
  3. Deploy main and run the Incognito Smoke Test:
    • Open the https:// URL on desktop and on your phone.
    • Confirm empty state loads cleanly.
    • Add 2 habits, check 1 off, refresh -> both habits and check state survive.
    • Delete 1 habit, refresh -> stays deleted.
    • Inspect hosting Runtime Logs -> zero 500 errors.

Next Walkthrough: Project 2: Personal Bookmark & Reading Vault →