# rehan1605/momentum architecture

> Architecture diagram of the GitHub repository rehan1605/momentum, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rehan1605/momentum
- Repository: https://github.com/rehan1605/momentum

## Overview

Momentum is a personal habit and wellbeing tracker. Users register or sign in, manage scheduled habits, record daily completion and mood or journal entries, then review progress and achievements or request personalized coaching. The frontend’s API client connects the Next.js experience to an Express API; authenticated controllers read and update MongoDB-backed records, while analytics and badge services derive progress. AI coaching combines user records and analytics with an optional Ollama service. The README is empty, so product capabilities are inferred from the tree and sampled code; unsampled route wiring is shown only where the tree supports it.

Main entry points: [`backend/routes/index.js`](https://github.com/rehan1605/momentum/blob/main/backend/routes/index.js) (API router), [`backend/services/aiService.js`](https://github.com/rehan1605/momentum/blob/main/backend/services/aiService.js) (AI context and prompts), [`frontend/services/api.js`](https://github.com/rehan1605/momentum/blob/main/frontend/services/api.js) (API client), [`backend/services/statsService.js`](https://github.com/rehan1605/momentum/blob/main/backend/services/statsService.js) (Analytics service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web["Next.js app"]
  node_api_client["API client<br/>[api.js]"]
  node_auth_ui["Auth pages<br/>[page.js]"]
  node_habit_ui["Habit pages<br/>[page.js]"]
  node_wellbeing_ui["Mood and journal<br/>[page.js]"]
  node_insights_ui["Progress pages<br/>[page.js]"]
  node_ai_ui["AI coaching page<br/>[page.js]"]
end

subgraph group_api["API and identity"]
  node_server["Express API<br/>[server.js]"]
  node_routes["API router<br/>[index.js]"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_auth_controller["Identity handlers<br/>[authController.js]"]
  node_auth_guard["Auth middleware<br/>[authMiddleware.js]"]
  node_user_model[("User records<br/>[User.js]")]
end

subgraph group_tracking["Habit and wellbeing"]
  node_habit_routes["Habit routes<br/>[habitRoutes.js]"]
  node_habit_controller["Habit handlers<br/>[habitController.js]"]
  node_log_routes["Habit log routes<br/>[habitLogRoutes.js]"]
  node_log_controller["Habit log handlers"]
  node_wellbeing_routes["Wellbeing routes<br/>[journalRoutes.js]"]
  node_wellbeing_controller["Mood and journal handlers"]
  node_habit_model[("Habit records<br/>[Habit.js]")]
  node_log_model[("Completion records<br/>[HabitLog.js]")]
  node_mood_model[("Mood records<br/>[MoodLog.js]")]
  node_journal_model[("Journal records<br/>[JournalEntry.js]")]
end

subgraph group_insights["Progress and coaching"]
  node_stats_routes["Stats routes<br/>[statsRoutes.js]"]
  node_stats_controller["Stats handlers<br/>[statsController.js]"]
  node_stats_service["Analytics service<br/>[statsService.js]"]
  node_badge_routes["Badge routes<br/>[badgeRoutes.js]"]
  node_badge_controller["Badge handlers<br/>[badgeController.js]"]
  node_badge_service["Badge service<br/>[badgeService.js]"]
  node_ai_routes["AI routes<br/>[aiRoutes.js]"]
  node_ai_controller["AI handlers<br/>[aiController.js]"]
  node_ai_service["AI context and prompts<br/>[aiService.js]"]
end

node_user(("User"))
node_ollama["Ollama<br/>external service"]

node_user -->|"uses"| node_web
node_auth_ui -->|"requests auth"| node_api_client
node_habit_ui -->|"requests habits"| node_api_client
node_wellbeing_ui -->|"requests wellbeing"| node_api_client
node_insights_ui -->|"requests progress"| node_api_client
node_ai_ui -->|"requests coaching"| node_api_client
node_api_client -->|"sends API requests"| node_server
node_server -->|"mounts API"| node_routes
node_routes -->|"dispatches"| node_auth_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_controller -->|"reads and writes"| node_user_model
node_routes -->|"dispatches"| node_habit_routes
node_habit_routes -->|"protects routes"| node_auth_guard
node_habit_routes -->|"dispatches"| node_habit_controller
node_habit_controller -->|"reads and writes"| node_habit_model
node_routes -->|"dispatches"| node_log_routes
node_log_routes -->|"protects routes"| node_auth_guard
node_log_routes -->|"dispatches"| node_log_controller
node_log_controller -->|"checks habits"| node_habit_model
node_log_controller -->|"reads and writes"| node_log_model
node_routes -->|"dispatches"| node_wellbeing_routes
node_wellbeing_routes -->|"protects routes"| node_auth_guard
node_wellbeing_routes -->|"dispatches"| node_wellbeing_controller
node_wellbeing_controller -->|"reads and writes"| node_mood_model
node_wellbeing_controller -->|"reads and writes"| node_journal_model
node_routes -->|"dispatches"| node_stats_routes
node_stats_routes -->|"protects routes"| node_auth_guard
node_stats_routes -->|"dispatches"| node_stats_controller
node_stats_controller -->|"requests metrics"| node_stats_service
node_stats_service -->|"reads"| node_habit_model
node_stats_service -->|"reads"| node_log_model
node_routes -->|"dispatches"| node_badge_routes
node_badge_routes -->|"dispatches"| node_badge_controller
node_badge_controller -->|"requests awards"| node_badge_service
node_routes -->|"dispatches"| node_ai_routes
node_ai_routes -->|"dispatches"| node_ai_controller
node_ai_controller -->|"requests coaching"| node_ai_service
node_ai_service -->|"gets analytics"| node_stats_service
node_ai_service -->|"reads"| node_habit_model
node_ai_service -->|"reads"| node_log_model
node_ai_service -->|"reads"| node_mood_model
node_ai_service -.->|"generates coaching"| node_ollama

click node_web "https://github.com/rehan1605/momentum/tree/main/frontend/app"
click node_api_client "https://github.com/rehan1605/momentum/blob/main/frontend/services/api.js"
click node_auth_ui "https://github.com/rehan1605/momentum/blob/main/frontend/app/login/page.js"
click node_habit_ui "https://github.com/rehan1605/momentum/blob/main/frontend/app/habits/page.js"
click node_wellbeing_ui "https://github.com/rehan1605/momentum/blob/main/frontend/app/mood/page.js"
click node_insights_ui "https://github.com/rehan1605/momentum/blob/main/frontend/app/analytics/page.js"
click node_ai_ui "https://github.com/rehan1605/momentum/blob/main/frontend/app/ai/page.js"
click node_server "https://github.com/rehan1605/momentum/blob/main/backend/server.js"
click node_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/index.js"
click node_auth_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/authRoutes.js"
click node_auth_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/authController.js"
click node_auth_guard "https://github.com/rehan1605/momentum/blob/main/backend/middleware/authMiddleware.js"
click node_habit_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/habitRoutes.js"
click node_habit_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/habitController.js"
click node_log_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/habitLogRoutes.js"
click node_log_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/habitLogController.js"
click node_wellbeing_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/journalRoutes.js"
click node_wellbeing_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/wellbeingController.js"
click node_stats_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/statsRoutes.js"
click node_stats_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/statsController.js"
click node_stats_service "https://github.com/rehan1605/momentum/blob/main/backend/services/statsService.js"
click node_badge_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/badgeRoutes.js"
click node_badge_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/badgeController.js"
click node_badge_service "https://github.com/rehan1605/momentum/blob/main/backend/services/badgeService.js"
click node_ai_routes "https://github.com/rehan1605/momentum/blob/main/backend/routes/aiRoutes.js"
click node_ai_controller "https://github.com/rehan1605/momentum/blob/main/backend/controllers/aiController.js"
click node_ai_service "https://github.com/rehan1605/momentum/blob/main/backend/services/aiService.js"
click node_user_model "https://github.com/rehan1605/momentum/blob/main/backend/models/User.js"
click node_habit_model "https://github.com/rehan1605/momentum/blob/main/backend/models/Habit.js"
click node_log_model "https://github.com/rehan1605/momentum/blob/main/backend/models/HabitLog.js"
click node_mood_model "https://github.com/rehan1605/momentum/blob/main/backend/models/MoodLog.js"
click node_journal_model "https://github.com/rehan1605/momentum/blob/main/backend/models/JournalEntry.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_api_client,node_auth_ui,node_habit_ui,node_wellbeing_ui,node_insights_ui,node_ai_ui,node_user toneBlue
class node_server,node_routes,node_auth_routes,node_auth_controller,node_auth_guard,node_user_model toneAmber
class node_habit_routes,node_habit_controller,node_log_routes,node_log_controller,node_wellbeing_routes,node_wellbeing_controller,node_habit_model,node_log_model,node_mood_model,node_journal_model toneMint
class node_stats_routes,node_stats_controller,node_stats_service,node_badge_routes,node_badge_controller,node_badge_service,node_ai_routes,node_ai_controller,node_ai_service toneRose
class node_ollama toneIndigo
```

## Components

### User experience

- [Next.js app](https://github.com/rehan1605/momentum/tree/main/frontend/app): `frontend/app`
- [API client](https://github.com/rehan1605/momentum/blob/main/frontend/services/api.js): `frontend/services/api.js`
- [Auth pages](https://github.com/rehan1605/momentum/blob/main/frontend/app/login/page.js): `frontend/app/login/page.js`
- [Habit pages](https://github.com/rehan1605/momentum/blob/main/frontend/app/habits/page.js): `frontend/app/habits/page.js`
- [Mood and journal](https://github.com/rehan1605/momentum/blob/main/frontend/app/mood/page.js): `frontend/app/mood/page.js`
- [Progress pages](https://github.com/rehan1605/momentum/blob/main/frontend/app/analytics/page.js): `frontend/app/analytics/page.js`
- [AI coaching page](https://github.com/rehan1605/momentum/blob/main/frontend/app/ai/page.js): `frontend/app/ai/page.js`

### API and identity

- [Express API](https://github.com/rehan1605/momentum/blob/main/backend/server.js): `backend/server.js`
- [API router](https://github.com/rehan1605/momentum/blob/main/backend/routes/index.js): `backend/routes/index.js`
- [Auth routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Identity handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Auth middleware](https://github.com/rehan1605/momentum/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [User records](https://github.com/rehan1605/momentum/blob/main/backend/models/User.js): `backend/models/User.js`

### Habit and wellbeing

- [Habit routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/habitRoutes.js): `backend/routes/habitRoutes.js`
- [Habit handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/habitController.js): `backend/controllers/habitController.js`
- [Habit log routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/habitLogRoutes.js): `backend/routes/habitLogRoutes.js`
- [Habit log handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/habitLogController.js): `backend/controllers/habitLogController.js`
- [Wellbeing routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/journalRoutes.js): `backend/routes/journalRoutes.js`
- [Mood and journal handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/wellbeingController.js): `backend/controllers/wellbeingController.js`
- [Habit records](https://github.com/rehan1605/momentum/blob/main/backend/models/Habit.js): `backend/models/Habit.js`
- [Completion records](https://github.com/rehan1605/momentum/blob/main/backend/models/HabitLog.js): `backend/models/HabitLog.js`
- [Mood records](https://github.com/rehan1605/momentum/blob/main/backend/models/MoodLog.js): `backend/models/MoodLog.js`
- [Journal records](https://github.com/rehan1605/momentum/blob/main/backend/models/JournalEntry.js): `backend/models/JournalEntry.js`

### Progress and coaching

- [Stats routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/statsRoutes.js): `backend/routes/statsRoutes.js`
- [Stats handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/statsController.js): `backend/controllers/statsController.js`
- [Analytics service](https://github.com/rehan1605/momentum/blob/main/backend/services/statsService.js): `backend/services/statsService.js`
- [Badge routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/badgeRoutes.js): `backend/routes/badgeRoutes.js`
- [Badge handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/badgeController.js): `backend/controllers/badgeController.js`
- [Badge service](https://github.com/rehan1605/momentum/blob/main/backend/services/badgeService.js): `backend/services/badgeService.js`
- [AI routes](https://github.com/rehan1605/momentum/blob/main/backend/routes/aiRoutes.js): `backend/routes/aiRoutes.js`
- [AI handlers](https://github.com/rehan1605/momentum/blob/main/backend/controllers/aiController.js): `backend/controllers/aiController.js`
- [AI context and prompts](https://github.com/rehan1605/momentum/blob/main/backend/services/aiService.js): `backend/services/aiService.js`

### Other components

- **User**
- **Ollama**: external service

## Connections

- User → Next.js app: uses
- Auth pages → API client: requests auth
- Habit pages → API client: requests habits
- Mood and journal → API client: requests wellbeing
- Progress pages → API client: requests progress
- AI coaching page → API client: requests coaching
- API client → Express API: sends API requests
- Express API → API router: mounts API
- API router → Auth routes: dispatches
- Auth routes → Identity handlers: dispatches
- Identity handlers → User records: reads and writes
- API router → Habit routes: dispatches
- Habit routes → Auth middleware: protects routes
- Habit routes → Habit handlers: dispatches
- Habit handlers → Habit records: reads and writes
- API router → Habit log routes: dispatches
- Habit log routes → Auth middleware: protects routes
- Habit log routes → Habit log handlers: dispatches
- Habit log handlers → Habit records: checks habits
- Habit log handlers → Completion records: reads and writes
- API router → Wellbeing routes: dispatches
- Wellbeing routes → Auth middleware: protects routes
- Wellbeing routes → Mood and journal handlers: dispatches
- Mood and journal handlers → Mood records: reads and writes
- Mood and journal handlers → Journal records: reads and writes
- API router → Stats routes: dispatches
- Stats routes → Auth middleware: protects routes
- Stats routes → Stats handlers: dispatches
- Stats handlers → Analytics service: requests metrics
- Analytics service → Habit records: reads
- Analytics service → Completion records: reads
- API router → Badge routes: dispatches
- Badge routes → Badge handlers: dispatches
- Badge handlers → Badge service: requests awards
- API router → AI routes: dispatches
- AI routes → AI handlers: dispatches
- AI handlers → AI context and prompts: requests coaching
- AI context and prompts → Analytics service: gets analytics
- AI context and prompts → Habit records: reads
- AI context and prompts → Completion records: reads
- AI context and prompts → Mood records: reads
- AI context and prompts → Ollama: generates coaching
