A beautiful, calming habit-tracking web application built with Next.js, TypeScript, Prisma, and SQLite.
- ✨ Create & Track Habits: Choose from presets or create custom habits (measurable or yes/no)
- 📊 Daily Logging: Log progress for today with automatic aggregation for multiple entries
- 🔥 Streaks: Track consecutive days of completion
- 📅 Calendar View: Visualize your progress over the last 30 days
- 📈 Analytics: View completion rates, totals, and averages for each habit
- 🎯 Smart Restrictions:
- No backfilling - only log for today
- 24-hour edit window for logs
- One aggregated log per habit per day
- Frontend: Next.js 16 with React & TypeScript
- Styling: Tailwind CSS v4 with custom soft color palette
- Backend: Next.js API routes
- Database: SQLite with Prisma ORM
- State Management: React hooks
- Node.js 18+ and npm
-
Navigate to the project directory:
cd habit-tracker -
Install dependencies:
npm install
-
Initialize the database (already done, but if you need to reset):
npx prisma migrate reset npx prisma migrate dev --name init
-
Generate Prisma Client:
npx prisma generate
Start the development server:
npm run devOpen http://localhost:3000 in your browser.
habit-tracker/
├── app/
│ ├── api/ # API routes
│ │ ├── habits/ # Habit CRUD endpoints
│ │ ├── logs/ # Log CRUD endpoints
│ │ └── analytics/ # Analytics endpoints
│ ├── habit/[id]/ # Habit detail page
│ ├── analytics/ # Analytics overview page
│ ├── page.tsx # Main dashboard
│ ├── layout.tsx # Root layout
│ └── globals.css # Global styles with custom theme
├── components/ # React components
│ ├── HabitCard.tsx # Habit card with logging
│ ├── Calendar.tsx # 30-day calendar view
│ └── AddHabitModal.tsx # Modal for adding habits
├── lib/
│ ├── prisma.ts # Prisma client singleton
│ ├── types.ts # TypeScript types & preset habits
│ └── utils.ts # Utility functions (dates, streaks)
├── prisma/
│ ├── schema.prisma # Database schema
│ └── dev.db # SQLite database
└── README.md
Logs can only be edited or deleted within 24 hours of creation. This is enforced in:
/lib/utils.ts-canEditLog()function- API routes check this before allowing updates/deletes
Multiple logs for the same habit on the same day are aggregated:
- For measurable habits: values are summed
- For boolean habits: latest value is kept
- Implemented via Prisma's
upsertlogic in/api/logs/route.ts
Users can only create logs for today's date:
- Enforced in
POST /api/logsendpoint - Frontend only shows today's logging interface
Streaks are calculated on-the-fly:
- Counts consecutive days from today backwards
- Allows for "grace day" (if today not logged yet, starts from yesterday)
- Implementation in
/lib/utils.ts-calculateStreak()
Represents "days with at least one habit completed" - more encouraging for MVP users.
- Single default user for MVP (no auth)
id,name,type(MEASURABLE | BOOLEAN)unit(for measurable habits)userId(foreign key)
id,habitId,date(YYYY-MM-DD)numericValue(for measurable)booleanValue(for boolean)createdAt,updatedAt- Unique constraint on
(habitId, date)
- Weekly/custom frequency habits
- Reminders & notifications
- Social features (sharing streaks)
- Advanced analytics & comparisons
- User authentication
- Mobile app
The UI uses a soft, calming color palette:
- Primary: Soft teal/mint (#4fd1c5)
- Secondary: Warm coral/peach (#fc8181)
- Success: Gentle green (#68d391)
- Background: Light off-white (#fafbfc)
Encouraging microcopy throughout:
- "One small step is still progress."
- "You showed up today. That counts."
MIT