# chandrakantamandal/ai-mentor architecture

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

- Interactive diagram: https://gitdiagram.com/chandrakantamandal/ai-mentor
- Repository: https://github.com/chandrakantamandal/ai-mentor

## Overview

1. **Repository shape**
   - This is a multi-app monorepo with three runtime boundaries: a **Node/Express backend**, a **React/Vite learner-facing frontend**, and a **Python/FastAPI AI microservice**. There is also a separate **frontendAdmin** app, likely for staff/admin operations.

2. **Primary user-facing app**
   - `frontend/` is the main SPA. It uses React 19, Vite, and Tailwind, with route-level pages for login/signup, dashboard, courses, learning, discussions, analytics, certificates, settings, watched videos, and profile completion.
   - Shared UI is organized into reusable components like `DashboardLayout`, `Sidebar`, `Header`, `ProtectedRoute`, theme controls, video player/transcript, and auth widgets.

3. **Frontend state and integration layer**
   - The frontend centralizes cross-cutting state in React contexts: `AuthContext`, `SidebarContext`, and `ThemeContext`.
   - `src/lib/api.js` is the main HTTP client boundary to the backend. `firebase.js` and the auth components indicate Firebase is used for Google OAuth/client-side identity, while the backend issues or validates the app’s JWT-based session.
   - `stripe.js` suggests payment/checkout UI integration lives here, with the backend handling the secure server-side payment flow.

4. **Backend API as the core application hub**
   - `backend/` is an Express REST API split by domain controllers and routes: auth, users, courses, analytics, community/discussions, notifications, preferences, certificates, sidebar, contact-us, AI, and payment/webhook.
   - Middleware includes auth protection and request validation, so the backend is the central enforcement point for authenticated access and schema correctness.

5. **Data model and persistence**
   - Sequelize models define the persistent domain in PostgreSQL. Key entities include `User`, `Course`, `Module`, `Lesson`, `LessonContent`, `Discussion`, `CommunityPost`, `Notification`, `Preference`, `Report`, `AIVideo`, and `Contactmessage`.
   - `modelAssociations.js` is the relationship hub, indicating the app is strongly relational: users enroll in courses, courses contain modules/lessons, lessons track content/progress, and users create discussions/posts and receive notifications.

6. **AI lesson-generation subsystem**
   - `ai_service/` is a separate Python/FastAPI service exposed independently from the main backend. It is configured via its own `.env` and listens on a different port.
   - The service uses **Google Gemini**, text-to-speech, and **FFmpeg** to generate AI lesson videos. The presence of `assets/celebrities`, `input`, and `temp` folders suggests a pipeline that assembles media, produces intermediate artifacts, and renders/export videos before handing them off.

7. **AI integration boundary**
   - The Node backend points to the AI service through `AI_SERVICE_URL`, so the backend likely orchestrates generation requests and persists the resulting metadata in `AIVideo`.
   - The AI service itself also references Cloudinary, which implies final media artifacts are uploaded externally rather than stored only on the app server.

8. **External services and integrations**
   - **PostgreSQL** is the system of record for the main app.
   - **Cloudinary** is used for media storage/delivery.
   - **Stripe** is used for purchases/payments, with a dedicated webhook route for asynchronous payment confirmation.
   - **Email delivery** is handled by backend utilities, likely for password reset, account events, and transactional notifications.

9. **Security and access control**
   - The repo uses a mixed auth model: Firebase for OAuth login on the client side and JWT-backed API authorization on the backend.
   - `authMiddleware` protects private routes, while `validate.js` and the various `schemas/*` files indicate structured request validation before controllers mutate data.

10. **Content, certificates, and learning lifecycle**
   - Course content is bootstrapped and maintained through scripts and seed data (`scripts/`, `seeds/`, JSON data files), indicating the platform supports curated catalog initialization and migrations.
   - Certificate generation is handled on the backend with a template module, tying completion data to document generation.
   - Analytics and notification subsystems sit on top of learning events, so the architecture supports progress tracking, reporting, and user engagement feedback loops.

11. **Admin surface**
   - `frontendAdmin/` is a separate frontend application, isolated from the learner SPA. Its small footprint suggests a dedicated administrative UI rather than a shared route set, which is useful to show as a distinct presentation layer in an architecture diagram.

12. **What to diagram as the key flows**
   - Main flow: **Learner UI → Express API → PostgreSQL**.
   - AI flow: **Backend → FastAPI AI service → Gemini/TTS/FFmpeg → Cloudinary → Backend/UI**.
   - Payment flow: **Frontend → Backend payment routes → Stripe → webhook callback → backend state update**.
   - Auth flow: **Frontend/Firebase login → backend JWT authorization → protected app/data access**.

Main entry points: [`backend/routes/auth.js`](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/auth.js) (API Routes), [`backend/controllers/courseController.js`](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/controllers/courseController.js) (Domain Controllers), [`frontend/src/App.jsx`](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/App.jsx) (Learner SPA), [`backend/server.js`](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/server.js) (Express API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_frontend_app["Learner SPA<br/>React/Vite app<br/>[App.jsx]"]
  node_frontend_shell["App Shell<br/>layout/components"]
  node_frontend_context["Client State<br/>React contexts<br/>[AuthContext.jsx]"]
  node_frontend_api["API Client<br/>HTTP integration<br/>[api.js]"]
  node_frontend_pages["Learner Pages<br/>route pages<br/>[Dashboard.jsx]"]
  node_frontend_admin["Admin UI<br/>React admin app<br/>[App.jsx]"]
end

subgraph group_backend["API Backend"]
  node_backend_server["Express API<br/>Node backend<br/>[server.js]"]
  node_backend_routes["API Routes<br/>route layer<br/>[auth.js]"]
  node_backend_controllers["Domain Controllers<br/>request handlers"]
  node_backend_middleware["Middleware<br/>auth/validation<br/>[authMiddleware.js]"]
  node_backend_models[("Data Models<br/>Sequelize models")]
  node_backend_templates["Certificate Template<br/>document generation"]
  node_backend_utils["Email and Utils<br/>backend utilities<br/>[sendEmail.js]"]
  node_backend_payment["Payments<br/>Stripe integration<br/>[payment.js]"]
  node_backend_ai_route["AI Bridge<br/>service proxy<br/>[aiRoutes.js]"]
end

subgraph group_ai["AI Service"]
  node_ai_service_app["AI Microservice<br/>FastAPI service<br/>[api.py]"]
  node_ai_pipeline["Media Pipeline<br/>generation pipeline<br/>[config.py]"]
end

subgraph group_data["Data and Integrations"]
  node_backend_db[("Postgres DB<br/>database<br/>[db.js]")]
  node_backend_cloudinary["Media Storage<br/>Cloudinary client<br/>[cloudinary.js]"]
  node_external_firebase{{"Firebase<br/>auth provider"}}
  node_external_stripe{{"Stripe<br/>payments"}}
  node_external_gemini{{"Gemini/TTS/FFmpeg<br/>media AI tools"}}
  node_external_cloudinary{{"Cloudinary<br/>media CDN"}}
end

node_frontend_app -->|"uses"| node_frontend_shell
node_frontend_shell -->|"reads state"| node_frontend_context
node_frontend_pages -->|"calls"| node_frontend_api
node_frontend_app -->|"routes to"| node_frontend_pages
node_frontend_app -->|"login"| node_external_firebase
node_frontend_api -->|"requests"| node_backend_server
node_frontend_admin -->|"admin API"| node_backend_server
node_backend_server -->|"mounts"| node_backend_routes
node_backend_routes -->|"protects/validates"| node_backend_middleware
node_backend_routes -->|"dispatches"| node_backend_controllers
node_backend_controllers -->|"persists via"| node_backend_models
node_backend_models -->|"stores in"| node_backend_db
node_backend_controllers -->|"renders"| node_backend_templates
node_backend_controllers -->|"sends email"| node_backend_utils
node_backend_routes -->|"payment flow"| node_backend_payment
node_backend_payment -->|"connects to"| node_external_stripe
node_backend_routes -->|"orchestrates"| node_backend_ai_route
node_backend_ai_route -->|"invokes"| node_ai_service_app
node_ai_service_app -->|"runs"| node_ai_pipeline
node_ai_pipeline -->|"uses"| node_external_gemini
node_ai_service_app -->|"uploads"| node_external_cloudinary
node_backend_cloudinary -->|"stores media"| node_external_cloudinary
node_backend_controllers -->|"uploads media"| node_backend_cloudinary
node_frontend_app -->|"checkout"| node_backend_payment
node_backend_server -->|"reads/writes"| node_backend_db

click node_frontend_app "https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/App.jsx"
click node_frontend_shell "https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/components/DashboardLayout.jsx"
click node_frontend_context "https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/context/AuthContext.jsx"
click node_frontend_api "https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/lib/api.js"
click node_frontend_pages "https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/pages/Dashboard.jsx"
click node_frontend_admin "https://github.com/chandrakantamandal/ai-mentor/blob/main/frontendAdmin/src/App.jsx"
click node_backend_server "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/server.js"
click node_backend_routes "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/auth.js"
click node_backend_controllers "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/controllers/courseController.js"
click node_backend_middleware "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/middleware/authMiddleware.js"
click node_backend_models "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/models/modelAssociations.js"
click node_backend_db "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/config/db.js"
click node_backend_templates "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/templates/certificateTemplate.js"
click node_backend_utils "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/utils/sendEmail.js"
click node_backend_payment "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/payment.js"
click node_backend_ai_route "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/aiRoutes.js"
click node_backend_cloudinary "https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/config/cloudinary.js"
click node_ai_service_app "https://github.com/chandrakantamandal/ai-mentor/blob/main/ai_service/backend/api.py"
click node_ai_pipeline "https://github.com/chandrakantamandal/ai-mentor/blob/main/ai_service/backend/config.py"

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_shell,node_frontend_context,node_frontend_api,node_frontend_pages,node_frontend_admin toneBlue
class node_backend_server,node_backend_routes,node_backend_controllers,node_backend_middleware,node_backend_models,node_backend_templates,node_backend_utils,node_backend_payment,node_backend_ai_route toneAmber
class node_ai_service_app,node_ai_pipeline toneMint
class node_backend_db,node_backend_cloudinary,node_external_firebase,node_external_stripe,node_external_gemini,node_external_cloudinary toneRose
```

## Components

### Presentation

User-facing apps and client-side state

- [Learner SPA](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/App.jsx): React/Vite app · Main learner-facing single-page app · `frontend/src/App.jsx`
- [App Shell](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/components/DashboardLayout.jsx): layout/components · Shared layout, navigation, protected routing, and auth UI · `frontend/src/components/DashboardLayout.jsx`
- [Client State](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/context/AuthContext.jsx): React contexts · Auth, sidebar, and theme state providers · `frontend/src/context/AuthContext.jsx`
- [API Client](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/lib/api.js): HTTP integration · Frontend boundary for backend requests and service calls · `frontend/src/lib/api.js`
- [Learner Pages](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontend/src/pages/Dashboard.jsx): route pages · Dashboard, courses, learning, discussions, analytics, certificates, settings, and auth pages · `frontend/src/pages/Dashboard.jsx`
- [Admin UI](https://github.com/chandrakantamandal/ai-mentor/blob/main/frontendAdmin/src/App.jsx): React admin app · Separate frontend for staff and admin operations · `frontendAdmin/src/App.jsx`

### API Backend

Express application and domain modules

- [Express API](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/server.js): Node backend · Main application server and REST API entrypoint · `backend/server.js`
- [API Routes](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/auth.js): route layer · Auth, courses, community, analytics, notifications, preferences, certificates, payment, and AI routes · `backend/routes/auth.js`
- [Domain Controllers](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/controllers/courseController.js): request handlers · Business logic for users, courses, discussions, analytics, certificates, and notifications · `backend/controllers/courseController.js`
- [Middleware](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/middleware/authMiddleware.js): auth/validation · JWT protection and schema validation · `backend/middleware/authMiddleware.js`
- [Data Models](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/models/modelAssociations.js): Sequelize models · Relational domain entities and associations · `backend/models/modelAssociations.js`
- [Certificate Template](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/templates/certificateTemplate.js): document generation · Backend certificate rendering logic · `backend/templates/certificateTemplate.js`
- [Email and Utils](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/utils/sendEmail.js): backend utilities · Email delivery and shared helper functions · `backend/utils/sendEmail.js`
- [Payments](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/payment.js): Stripe integration · Checkout and webhook flow for purchases · `backend/routes/payment.js`
- [AI Bridge](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/routes/aiRoutes.js): service proxy · Backend endpoint that orchestrates AI generation requests · `backend/routes/aiRoutes.js`

### AI Service

Python media-generation service

- [AI Microservice](https://github.com/chandrakantamandal/ai-mentor/blob/main/ai_service/backend/api.py): FastAPI service · Separate Python service for lesson video generation · `ai_service/backend/api.py`
- [Media Pipeline](https://github.com/chandrakantamandal/ai-mentor/blob/main/ai_service/backend/config.py): generation pipeline · Gemini, TTS, and FFmpeg assembly and rendering flow · `ai_service/backend/config.py`

### Data and Integrations

Persistent models and external services

- [Postgres DB](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/config/db.js): database · Primary system of record · `backend/config/db.js`
- [Media Storage](https://github.com/chandrakantamandal/ai-mentor/blob/main/backend/config/cloudinary.js): Cloudinary client · Backend media upload and delivery integration · `backend/config/cloudinary.js`
- **Firebase**: auth provider · Client-side identity and Google OAuth
- **Stripe**: payments · External checkout and webhook provider
- **Gemini/TTS/FFmpeg**: media AI tools · Model, speech, and rendering toolchain
- **Cloudinary**: media CDN · External media storage and delivery

## Connections

- Learner SPA → App Shell: uses · Pages are wrapped by shared layout and route protection
- App Shell → Client State: reads state · Layout and UI consume auth, sidebar, and theme contexts
- Learner Pages → API Client: calls · Route pages load and mutate data through the API client
- Learner SPA → Learner Pages: routes to · Main SPA is composed of page-level screens
- Learner SPA → Firebase: login · Client uses Firebase for OAuth and identity
- API Client → Express API: requests · Frontend talks to the Express API boundary
- Admin UI → Express API: admin API · Admin surface consumes the same backend services
- Express API → API Routes: mounts · Server exposes domain routes and webhooks
- API Routes → Middleware: protects/validates · Routes are guarded and validated before mutation
- API Routes → Domain Controllers: dispatches · HTTP handlers delegate to domain controllers
- Domain Controllers → Data Models: persists via · Controllers read and write the relational model layer
- Data Models → Postgres DB: stores in · Sequelize models map to PostgreSQL
- Domain Controllers → Certificate Template: renders · Completion flows generate certificates
- Domain Controllers → Email and Utils: sends email · Transactional and account emails are handled in utilities
- API Routes → Payments: payment flow · Checkout and webhook routes handle purchase confirmation
- Payments → Stripe: connects to · Stripe processes payments and async callbacks
- API Routes → AI Bridge: orchestrates · Backend exposes AI generation entrypoints
- AI Bridge → AI Microservice: invokes · Node backend forwards generation requests to the Python service
- AI Microservice → Media Pipeline: runs · FastAPI service coordinates media generation steps
- Media Pipeline → Gemini/TTS/FFmpeg: uses · AI pipeline relies on model, speech, and rendering tools
- AI Microservice → Cloudinary: uploads · Generated media artifacts are published externally
- Media Storage → Cloudinary: stores media · Main backend also integrates with Cloudinary
- Domain Controllers → Media Storage: uploads media · Controllers attach media handling to domain workflows
- Learner SPA → Payments: checkout · UI triggers purchase-related backend routes
- Express API → Postgres DB: reads/writes · Application state ultimately persists in PostgreSQL
