# varsha-1428/aihabittracker architecture

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

- Interactive diagram: https://gitdiagram.com/varsha-1428/aihabittracker
- Repository: https://github.com/varsha-1428/aihabittracker

## Overview

AI Habit Tracker is a MERN web app for creating habits, recording completions, and reviewing streaks and activity analytics, with AI-generated reports, suggestions, chat, motivation, and recovery plans. Users enter through public or authenticated pages; protected app pages use the API to work with habit and log data, while the AI endpoints build responses from that data. The graph preserves documented dashboard and analytics capabilities, but unsampled UI-to-API calls are shown only as unverified links. Backend controller/model relationships and the principal route wiring are supported by excerpts or the source index.

Main entry points: [`frontend/src/App.jsx`](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/App.jsx) (Page router), [`frontend/src/api/axios.js`](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/api/axios.js) (API client), [`backend/server.js`](https://github.com/varsha-1428/aihabittracker/blob/main/backend/server.js) (HTTP server), [`backend/controllers/aiController.js`](https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/aiController.js) (AI handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Page router<br/>[App.jsx]"]
  node_authui["Auth state<br/>[AuthContext.jsx]"]
  node_theme["Theme state<br/>[ThemeContext.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_habitsui["Habit manager<br/>[Habits.jsx]"]
  node_weeklyui["Weekly view<br/>[Weekly.jsx]"]
  node_insightsui["Insights view<br/>[Insights.jsx]"]
  node_statsui["Analytics view<br/>[Stats.jsx]"]
  node_suggestions["Habit suggestions"]
  node_weeklygrid["Weekly grid<br/>[WeeklyGrid.jsx]"]
  node_api_client["API client<br/>[axios.js]"]
end

subgraph group_api["Backend API"]
  node_server["HTTP server<br/>[server.js]"]
  node_authroutes["Auth routes<br/>[auth.js]"]
  node_habitroutes["Habit routes<br/>[habits.js]"]
  node_logroutes["Log routes<br/>[logs.js]"]
  node_airoutes["AI routes<br/>[ai.js]"]
  node_authguard["JWT guard<br/>[auth.js]"]
  node_authcontroller["Account handlers<br/>[authController.js]"]
  node_habitcontroller["Habit handlers<br/>[habitController.js]"]
  node_logcontroller["Log and stats<br/>[logController.js]"]
end

subgraph group_domain["Habit data"]
  node_habitmodel[("Habit records<br/>[Habit.js]")]
  node_logmodel[("Completion logs<br/>[HabitLog.js]")]
  node_usermodel[("User records<br/>[User.js]")]
  node_insightmodel[("AI insight records<br/>[AIInsight.js]")]
end

subgraph group_ai["AI insights"]
  node_aicontroller["AI handlers<br/>[aiController.js]"]
  node_aiservice["Prompt service<br/>[aiService.js]"]
end

node_user(("User"))
node_gemini["Google Generative AI"]
node_mongo[("MongoDB")]

node_user -->|"uses"| node_app
node_app -->|"protects pages"| node_authui
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_habitsui
node_app -->|"routes to"| node_weeklyui
node_app -->|"routes to"| node_insightsui
node_app -->|"routes to"| node_statsui
node_authui -->|"calls"| node_api_client
node_dashboard -.->|"uses API"| node_api_client
node_habitsui -.->|"uses API"| node_api_client
node_weeklyui -.->|"uses API"| node_api_client
node_insightsui -.->|"uses API"| node_api_client
node_statsui -.->|"uses API"| node_api_client
node_dashboard -->|"renders"| node_suggestions
node_weeklyui -->|"renders"| node_weeklygrid
node_api_client -.->|"sends requests"| node_server
node_server -->|"mounts"| node_authroutes
node_server -->|"mounts"| node_habitroutes
node_server -->|"mounts"| node_logroutes
node_server -->|"mounts"| node_airoutes
node_authroutes -->|"dispatches"| node_authcontroller
node_habitroutes -->|"dispatches"| node_habitcontroller
node_logroutes -->|"dispatches"| node_logcontroller
node_airoutes -->|"dispatches"| node_aicontroller
node_authroutes -->|"guards"| node_authguard
node_habitroutes -->|"guards"| node_authguard
node_logroutes -->|"guards"| node_authguard
node_airoutes -->|"guards"| node_authguard
node_authguard -->|"loads user"| node_usermodel
node_authcontroller -->|"reads and writes"| node_usermodel
node_habitcontroller -->|"reads and writes"| node_habitmodel
node_habitcontroller -->|"deletes logs"| node_logmodel
node_logcontroller -->|"reads habits"| node_habitmodel
node_logcontroller -->|"reads and writes"| node_logmodel
node_aicontroller -->|"reads habits"| node_habitmodel
node_aicontroller -->|"reads logs"| node_logmodel
node_aicontroller -->|"requests completions"| node_aiservice
node_aicontroller -->|"stores insights"| node_insightmodel
node_aiservice -.->|"generates text"| node_gemini
node_habitmodel -.->|"persists in"| node_mongo
node_logmodel -.->|"persists in"| node_mongo
node_usermodel -.->|"persists in"| node_mongo
node_insightmodel -.->|"persists in"| node_mongo

click node_app "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/context/AuthContext.jsx"
click node_theme "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/context/ThemeContext.jsx"
click node_dashboard "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Dashboard.jsx"
click node_habitsui "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Habits.jsx"
click node_weeklyui "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Weekly.jsx"
click node_insightsui "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Insights.jsx"
click node_statsui "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Stats.jsx"
click node_suggestions "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/components/HabitSuggestionModal.jsx"
click node_weeklygrid "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/components/WeeklyGrid.jsx"
click node_api_client "https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/api/axios.js"
click node_server "https://github.com/varsha-1428/aihabittracker/blob/main/backend/server.js"
click node_authroutes "https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/auth.js"
click node_habitroutes "https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/habits.js"
click node_logroutes "https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/logs.js"
click node_airoutes "https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/ai.js"
click node_authguard "https://github.com/varsha-1428/aihabittracker/blob/main/backend/middleware/auth.js"
click node_authcontroller "https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/authController.js"
click node_habitcontroller "https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/habitController.js"
click node_logcontroller "https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/logController.js"
click node_aicontroller "https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/aiController.js"
click node_aiservice "https://github.com/varsha-1428/aihabittracker/blob/main/backend/utils/aiService.js"
click node_habitmodel "https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/Habit.js"
click node_logmodel "https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/HabitLog.js"
click node_usermodel "https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/User.js"
click node_insightmodel "https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/AIInsight.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_app,node_authui,node_theme,node_dashboard,node_habitsui,node_weeklyui,node_insightsui,node_statsui,node_suggestions,node_weeklygrid,node_api_client,node_user toneBlue
class node_server,node_authroutes,node_habitroutes,node_logroutes,node_airoutes,node_authguard,node_authcontroller,node_habitcontroller,node_logcontroller,node_mongo toneAmber
class node_habitmodel,node_logmodel,node_usermodel,node_insightmodel toneMint
class node_aicontroller,node_aiservice toneRose
class node_gemini toneIndigo
```

## Components

### Web application

- [Page router](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Auth state](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Theme state](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/context/ThemeContext.jsx): `frontend/src/context/ThemeContext.jsx`
- [Dashboard](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Habit manager](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Habits.jsx): `frontend/src/pages/Habits.jsx`
- [Weekly view](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Weekly.jsx): `frontend/src/pages/Weekly.jsx`
- [Insights view](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Insights.jsx): `frontend/src/pages/Insights.jsx`
- [Analytics view](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/pages/Stats.jsx): `frontend/src/pages/Stats.jsx`
- [Habit suggestions](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/components/HabitSuggestionModal.jsx): `frontend/src/components/HabitSuggestionModal.jsx`
- [Weekly grid](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/components/WeeklyGrid.jsx): `frontend/src/components/WeeklyGrid.jsx`
- [API client](https://github.com/varsha-1428/aihabittracker/blob/main/frontend/src/api/axios.js): `frontend/src/api/axios.js`

### Backend API

- [HTTP server](https://github.com/varsha-1428/aihabittracker/blob/main/backend/server.js): `backend/server.js`
- [Auth routes](https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/auth.js): `backend/routes/auth.js`
- [Habit routes](https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/habits.js): `backend/routes/habits.js`
- [Log routes](https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/logs.js): `backend/routes/logs.js`
- [AI routes](https://github.com/varsha-1428/aihabittracker/blob/main/backend/routes/ai.js): `backend/routes/ai.js`
- [JWT guard](https://github.com/varsha-1428/aihabittracker/blob/main/backend/middleware/auth.js): `backend/middleware/auth.js`
- [Account handlers](https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Habit handlers](https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/habitController.js): `backend/controllers/habitController.js`
- [Log and stats](https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/logController.js): `backend/controllers/logController.js`

### Habit data

- [Habit records](https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/Habit.js): `backend/models/Habit.js`
- [Completion logs](https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/HabitLog.js): `backend/models/HabitLog.js`
- [User records](https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/User.js): `backend/models/User.js`
- [AI insight records](https://github.com/varsha-1428/aihabittracker/blob/main/backend/models/AIInsight.js): `backend/models/AIInsight.js`

### AI insights

- [AI handlers](https://github.com/varsha-1428/aihabittracker/blob/main/backend/controllers/aiController.js): `backend/controllers/aiController.js`
- [Prompt service](https://github.com/varsha-1428/aihabittracker/blob/main/backend/utils/aiService.js): `backend/utils/aiService.js`

### Other components

- **User**
- **Google Generative AI**
- **MongoDB**

## Connections

- User → Page router: uses (evidence: `README.md`)
- Page router → Auth state: protects pages (evidence: `frontend/src/App.jsx`)
- Page router → Dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Page router → Habit manager: routes to (evidence: `frontend/src/App.jsx`)
- Page router → Weekly view: routes to (evidence: `frontend/src/App.jsx`)
- Page router → Insights view: routes to (evidence: `frontend/src/App.jsx`)
- Page router → Analytics view: routes to (evidence: `frontend/src/App.jsx`)
- Auth state → API client: calls (evidence: `frontend/src/context/AuthContext.jsx`)
- Dashboard → API client: uses API (evidence: `frontend/src/pages/Dashboard.jsx`)
- Habit manager → API client: uses API (evidence: `frontend/src/pages/Habits.jsx`)
- Weekly view → API client: uses API (evidence: `frontend/src/pages/Weekly.jsx`)
- Insights view → API client: uses API (evidence: `frontend/src/pages/Insights.jsx`)
- Analytics view → API client: uses API (evidence: `frontend/src/pages/Stats.jsx`)
- Dashboard → Habit suggestions: renders (evidence: `frontend/src/pages/Dashboard.jsx`)
- Weekly view → Weekly grid: renders (evidence: `frontend/src/pages/Weekly.jsx`)
- API client → HTTP server: sends requests
- HTTP server → Auth routes: mounts (evidence: `backend/server.js`)
- HTTP server → Habit routes: mounts (evidence: `backend/server.js`)
- HTTP server → Log routes: mounts (evidence: `backend/server.js`)
- HTTP server → AI routes: mounts (evidence: `backend/server.js`)
- Auth routes → Account handlers: dispatches (evidence: `backend/routes/auth.js`)
- Habit routes → Habit handlers: dispatches (evidence: `backend/routes/habits.js`)
- Log routes → Log and stats: dispatches (evidence: `backend/routes/logs.js`)
- AI routes → AI handlers: dispatches (evidence: `backend/routes/ai.js`)
- Auth routes → JWT guard: guards (evidence: `backend/routes/auth.js`)
- Habit routes → JWT guard: guards (evidence: `backend/routes/habits.js`)
- Log routes → JWT guard: guards (evidence: `backend/routes/logs.js`)
- AI routes → JWT guard: guards (evidence: `backend/routes/ai.js`)
- JWT guard → User records: loads user (evidence: `backend/middleware/auth.js`)
- Account handlers → User records: reads and writes (evidence: `backend/controllers/authController.js`)
- Habit handlers → Habit records: reads and writes (evidence: `backend/controllers/habitController.js`)
- Habit handlers → Completion logs: deletes logs (evidence: `backend/controllers/habitController.js`)
- Log and stats → Habit records: reads habits (evidence: `backend/controllers/logController.js`)
- Log and stats → Completion logs: reads and writes (evidence: `backend/controllers/logController.js`)
- AI handlers → Habit records: reads habits (evidence: `backend/controllers/aiController.js`)
- AI handlers → Completion logs: reads logs (evidence: `backend/controllers/aiController.js`)
- AI handlers → Prompt service: requests completions (evidence: `backend/controllers/aiController.js`)
- AI handlers → AI insight records: stores insights (evidence: `backend/controllers/aiController.js`)
- Prompt service → Google Generative AI: generates text (evidence: `README.md`)
- Habit records → MongoDB: persists in (evidence: `README.md`)
- Completion logs → MongoDB: persists in (evidence: `README.md`)
- User records → MongoDB: persists in (evidence: `README.md`)
- AI insight records → MongoDB: persists in (evidence: `README.md`)
