How varsha-1428/aihabittracker works
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: App.jsx Page router · axios.js API client · server.js HTTP server · aiController.js AI handlers
Components 29
Web application
- Page router
frontend/src/App.jsx - Auth state
frontend/src/context/AuthContext.jsx - Theme state
frontend/src/context/ThemeContext.jsx - Dashboard
frontend/src/pages/Dashboard.jsx - Habit manager
frontend/src/pages/Habits.jsx - Weekly view
frontend/src/pages/Weekly.jsx - Insights view
frontend/src/pages/Insights.jsx - Analytics view
frontend/src/pages/Stats.jsx - Habit suggestions
frontend/src/components/HabitSuggestionModal.jsx - Weekly grid
frontend/src/components/WeeklyGrid.jsx - API client
frontend/src/api/axios.js
Backend API
- HTTP server
backend/server.js - Auth routes
backend/routes/auth.js - Habit routes
backend/routes/habits.js - Log routes
backend/routes/logs.js - AI routes
backend/routes/ai.js - JWT guard
backend/middleware/auth.js - Account handlers
backend/controllers/authController.js - Habit handlers
backend/controllers/habitController.js - Log and stats
backend/controllers/logController.js
Habit data
- Habit records
backend/models/Habit.js - Completion logs
backend/models/HabitLog.js - User records
backend/models/User.js - AI insight records
backend/models/AIInsight.js
AI insights
- AI handlers
backend/controllers/aiController.js - Prompt service
backend/utils/aiService.js
Other components
- User
- Google Generative AI
- MongoDB
Connections 43
- User → Page router: uses
README.md - Page router → Auth state: protects pages
frontend/src/App.jsx - Page router → Dashboard: routes to
frontend/src/App.jsx - Page router → Habit manager: routes to
frontend/src/App.jsx - Page router → Weekly view: routes to
frontend/src/App.jsx - Page router → Insights view: routes to
frontend/src/App.jsx - Page router → Analytics view: routes to
frontend/src/App.jsx - Auth state → API client: calls
frontend/src/context/AuthContext.jsx - Dashboard → API client: uses API
frontend/src/pages/Dashboard.jsx - Habit manager → API client: uses API
frontend/src/pages/Habits.jsx - Weekly view → API client: uses API
frontend/src/pages/Weekly.jsx - Insights view → API client: uses API
frontend/src/pages/Insights.jsx - Analytics view → API client: uses API
frontend/src/pages/Stats.jsx - Dashboard → Habit suggestions: renders
frontend/src/pages/Dashboard.jsx - Weekly view → Weekly grid: renders
frontend/src/pages/Weekly.jsx - API client → HTTP server: sends requests
- HTTP server → Auth routes: mounts
backend/server.js - HTTP server → Habit routes: mounts
backend/server.js - HTTP server → Log routes: mounts
backend/server.js - HTTP server → AI routes: mounts
backend/server.js - Auth routes → Account handlers: dispatches
backend/routes/auth.js - Habit routes → Habit handlers: dispatches
backend/routes/habits.js - Log routes → Log and stats: dispatches
backend/routes/logs.js - AI routes → AI handlers: dispatches
backend/routes/ai.js - Auth routes → JWT guard: guards
backend/routes/auth.js - Habit routes → JWT guard: guards
backend/routes/habits.js - Log routes → JWT guard: guards
backend/routes/logs.js - AI routes → JWT guard: guards
backend/routes/ai.js - JWT guard → User records: loads user
backend/middleware/auth.js - Account handlers → User records: reads and writes
backend/controllers/authController.js - Habit handlers → Habit records: reads and writes
backend/controllers/habitController.js - Habit handlers → Completion logs: deletes logs
backend/controllers/habitController.js - Log and stats → Habit records: reads habits
backend/controllers/logController.js - Log and stats → Completion logs: reads and writes
backend/controllers/logController.js - AI handlers → Habit records: reads habits
backend/controllers/aiController.js - AI handlers → Completion logs: reads logs
backend/controllers/aiController.js - AI handlers → Prompt service: requests completions
backend/controllers/aiController.js - AI handlers → AI insight records: stores insights
backend/controllers/aiController.js - Prompt service → Google Generative AI: generates text
README.md - Habit records → MongoDB: persists in
README.md - Completion logs → MongoDB: persists in
README.md - User records → MongoDB: persists in
README.md - AI insight records → MongoDB: persists in
README.md