# achintya1205/ai-study-planner architecture

> Architecture diagram of the GitHub repository achintya1205/ai-study-planner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/achintya1205/ai-study-planner
- Repository: https://github.com/achintya1205/ai-study-planner

## Overview

1. The repository is a split full-stack application with two runtimes: a React 19 frontend in `study-planner-frontend` and an Express/Node.js backend in `backend`. The frontend is the presentation layer; the backend owns all business rules, persistence, authentication, and AI orchestration.

2. The frontend is a Vite app organized around route-level pages: Dashboard, Subjects, Topics, Tests, StudySession, Studyplan, Analytics, and Auth. Shared UI is minimal and centralized in `components/navbar.jsx`, with global styling through Tailwind, `App.css`, and `index.css`.

3. Frontend data access is isolated in `src/api`. `axios.js` configures the HTTP client, while `auth.api.js` and `study.api.js` wrap calls to backend REST endpoints. This keeps page components focused on rendering and state, not request construction.

4. The backend entrypoint is `server.js`, which wires Express, database connection, routes, and middleware. `config/db.js` handles the MongoDB Atlas connection, making MongoDB the system of record for all user academic data.

5. Authentication is JWT-based. `routes/auth.js` handles register/login, and `middleware/auth.js` protects private routes by verifying the token and binding requests to the authenticated user. This creates a strict per-user data boundary across subjects, topics, tests, and sessions.

6. The data model is centered on five Mongoose collections: `User`, `Subject`, `Topic`, `Test`, and `StudySession`. Subjects own topics; tests can belong either to a topic or directly to a subject; study sessions are tracked separately as productivity records.

7. The backend is organized by domain routes rather than by UI page. `routes/subjects.js`, `topics.js`, `tests.js`, and `sessions.js` expose CRUD-style endpoints for the study workflow, while `routes/ai.js` exposes AI-generated analysis and planning endpoints. This is the main API surface consumed by the frontend.

8. A key architectural detail is the automatic progress synchronization layer in `backend/utils`. `updateTopicScore.js` and `updateSubjectProgress.js` are shared business-logic helpers that recalculate mastery after new tests or changes in related records, avoiding duplicated scoring logic inside route handlers.

9. The scoring model is not manual; it is derived from assessment history. Topic mastery is updated from recent tests, subject mastery aggregates topic and subject-level exams, and the system supports whole-subject tests without forcing them into a topic. This is what drives dashboard stats, analytics, and weak-area detection.

10. The AI subsystem is backend-orchestrated and data-driven. `routes/ai.js` collects the authenticated user’s subjects, topics, tests, and study sessions, builds a contextual prompt, and sends it to Google Gemini. The frontend only requests analysis or study plans and renders the returned text or plan output.

11. The main data flow is: user action in React → Axios API call → Express route → MongoDB read/write and/or utility recalculation → optional Gemini call for AI features → response back to the React page. Most pages therefore behave as thin clients over a centralized backend.

12. Deployment is intentionally separated: the frontend is configured for Vercel (`vercel.json`), while the backend is designed for a Node hosting platform such as Render, with MongoDB Atlas and Gemini as external services. The architecture is a classic MERN-style split, but with added AI and automated progress-synchronization subsystems.

Main entry points: [`backend/server.js`](https://github.com/achintya1205/ai-study-planner/blob/main/backend/server.js) (Server), [`backend/routes/subjects.js`](https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/subjects.js) (Study routes), [`backend/routes/ai.js`](https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/ai.js) (AI routes), [`study-planner-frontend/src/App.jsx`](https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/App.jsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>React/Vite SPA<br/>[App.jsx]"]
  node_frontend_pages["Pages<br/>route views"]
  node_frontend_api["API layer<br/>axios wrappers"]
  node_frontend_navbar["Navbar<br/>shared UI<br/>[navbar.jsx]"]
  node_frontend_style["Styling<br/>global styles<br/>[index.css]"]
end

subgraph group_backend["Backend"]
  node_backend_server["Server<br/>Express entrypoint<br/>[server.js]"]
  node_backend_routes_auth["Auth routes<br/>JWT auth<br/>[auth.js]"]
  node_backend_routes_study["Study routes<br/>study CRUD<br/>[subjects.js]"]
  node_backend_routes_ai["AI routes<br/>Gemini orchestration<br/>[ai.js]"]
  node_backend_middleware_auth["Auth guard<br/>JWT middleware<br/>[auth.js]"]
  node_backend_db[("Mongo connect<br/>database config<br/>[db.js]")]
  node_backend_models[("Data model<br/>Mongoose collections")]
  node_backend_utils["Progress sync<br/>scoring helpers"]
end

subgraph group_external["External Services"]
  node_external_mongo[("MongoDB Atlas<br/>external database")]
  node_external_gemini(("Gemini<br/>AI service"))
  node_external_vercel(("Vercel<br/>hosting"))
end

node_frontend_app -->|"renders"| node_frontend_pages
node_frontend_app -->|"shares UI"| node_frontend_navbar
node_frontend_app -->|"styles with"| node_frontend_style
node_frontend_pages -->|"fetches via"| node_frontend_api
node_frontend_api -->|"calls"| node_backend_server
node_backend_server -->|"connects"| node_backend_db
node_backend_server -->|"mounts"| node_backend_routes_auth
node_backend_server -->|"mounts"| node_backend_routes_study
node_backend_server -->|"mounts"| node_backend_routes_ai
node_backend_routes_auth -->|"uses"| node_backend_models
node_backend_routes_study -->|"protects with"| node_backend_middleware_auth
node_backend_routes_study -->|"persists"| node_backend_models
node_backend_routes_study -->|"recalculates"| node_backend_utils
node_backend_routes_ai -->|"protects with"| node_backend_middleware_auth
node_backend_routes_ai -->|"reads"| node_backend_models
node_backend_routes_ai -->|"invokes"| node_external_gemini
node_backend_db -->|"connects to"| node_external_mongo
node_backend_routes_study -.->|"feeds context"| node_backend_routes_ai
node_frontend_app -->|"deploys to"| node_external_vercel

click node_frontend_app "https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/App.jsx"
click node_frontend_pages "https://github.com/achintya1205/ai-study-planner/tree/main/study-planner-frontend/src/pages"
click node_frontend_api "https://github.com/achintya1205/ai-study-planner/tree/main/study-planner-frontend/src/api"
click node_frontend_navbar "https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/components/navbar.jsx"
click node_frontend_style "https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/index.css"
click node_backend_server "https://github.com/achintya1205/ai-study-planner/blob/main/backend/server.js"
click node_backend_routes_auth "https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/auth.js"
click node_backend_routes_study "https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/subjects.js"
click node_backend_routes_ai "https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/ai.js"
click node_backend_middleware_auth "https://github.com/achintya1205/ai-study-planner/blob/main/backend/middleware/auth.js"
click node_backend_db "https://github.com/achintya1205/ai-study-planner/blob/main/backend/config/db.js"
click node_backend_models "https://github.com/achintya1205/ai-study-planner/tree/main/backend/models"
click node_backend_utils "https://github.com/achintya1205/ai-study-planner/tree/main/backend/utils"

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_frontend_app,node_frontend_pages,node_frontend_api,node_frontend_navbar,node_frontend_style toneBlue
class node_backend_server,node_backend_routes_auth,node_backend_routes_study,node_backend_routes_ai,node_backend_middleware_auth,node_backend_db,node_backend_models,node_backend_utils toneAmber
class node_external_mongo,node_external_gemini,node_external_vercel toneMint
```

## Components

### Frontend

React/Vite presentation layer and API client

- [App shell](https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/App.jsx): React/Vite SPA · Top-level frontend composition and routing entry. · `study-planner-frontend/src/App.jsx`
- [Pages](https://github.com/achintya1205/ai-study-planner/tree/main/study-planner-frontend/src/pages): route views · Dashboard, subjects, topics, tests, sessions, planning, analytics, and auth screens. · `study-planner-frontend/src/pages`
- [API layer](https://github.com/achintya1205/ai-study-planner/tree/main/study-planner-frontend/src/api): axios wrappers · Centralized HTTP client and request helpers for backend calls. · `study-planner-frontend/src/api`
- [Navbar](https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/components/navbar.jsx): shared UI · Shared navigation component used across the app. · `study-planner-frontend/src/components/navbar.jsx`
- [Styling](https://github.com/achintya1205/ai-study-planner/blob/main/study-planner-frontend/src/index.css): global styles · Tailwind and global CSS for app-wide presentation. · `study-planner-frontend/src/index.css`

### Backend

Express API, domain logic, persistence, and AI orchestration

- [Server](https://github.com/achintya1205/ai-study-planner/blob/main/backend/server.js): Express entrypoint · Bootstraps the API server, middleware, routes, and database connection. · `backend/server.js`
- [Auth routes](https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/auth.js): JWT auth · Register and login endpoints that issue and verify tokens. · `backend/routes/auth.js`
- [Study routes](https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/subjects.js): study CRUD · Core REST endpoints for subjects, topics, tests, and sessions. · `backend/routes/subjects.js`
- [AI routes](https://github.com/achintya1205/ai-study-planner/blob/main/backend/routes/ai.js): Gemini orchestration · Builds context from user data and returns analysis or study plans. · `backend/routes/ai.js`
- [Auth guard](https://github.com/achintya1205/ai-study-planner/blob/main/backend/middleware/auth.js): JWT middleware · Verifies tokens and binds requests to the authenticated user. · `backend/middleware/auth.js`
- [Mongo connect](https://github.com/achintya1205/ai-study-planner/blob/main/backend/config/db.js): database config · MongoDB Atlas connection setup. · `backend/config/db.js`
- [Data model](https://github.com/achintya1205/ai-study-planner/tree/main/backend/models): Mongoose collections · User, Subject, Topic, Test, and StudySession collections. · `backend/models`
- [Progress sync](https://github.com/achintya1205/ai-study-planner/tree/main/backend/utils): scoring helpers · Shared recalculation logic for topic score and subject progress. · `backend/utils`

### External Services

Hosted services used by the application

- **MongoDB Atlas**: external database · System of record for user academic data.
- **Gemini**: AI service · Generates analysis and planning outputs from user context.
- **Vercel**: hosting · Frontend deployment target.

## Connections

- App shell → Pages: renders · App composes the route-level pages.
- App shell → Navbar: shares UI · Common navigation is used across pages.
- App shell → Styling: styles with · Global styling is applied at app level.
- Pages → API layer: fetches via · Pages delegate backend communication to API wrappers.
- API layer → Server: calls · HTTP requests go to the Express backend.
- Server → Mongo connect: connects · Server initializes the Mongo connection.
- Server → Auth routes: mounts · Auth routes are exposed by the server.
- Server → Study routes: mounts · Study workflow routes are exposed by the server.
- Server → AI routes: mounts · AI endpoints are exposed by the server.
- Auth routes → Data model: uses · Auth flow reads and writes user data.
- Study routes → Auth guard: protects with · Private study endpoints require authentication.
- Study routes → Data model: persists · Study CRUD operates on the Mongoose collections.
- Study routes → Progress sync: recalculates · Progress and mastery are synchronized after changes.
- AI routes → Auth guard: protects with · AI requests are scoped to the authenticated user.
- AI routes → Data model: reads · AI context is built from stored academic data.
- AI routes → Gemini: invokes · Prompts are sent to Gemini for analysis and planning.
- Mongo connect → MongoDB Atlas: connects to · MongoDB Atlas is the backing datastore.
- Study routes → AI routes: feeds context · Shared user data powers both study tracking and AI features.
- App shell → Vercel: deploys to · Frontend is configured for Vercel hosting.
