How chandrakantamandal/ai-mentor works
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: auth.js API Routes · courseController.js Domain Controllers · App.jsx Learner SPA · server.js Express API
Components 23
Presentation
User-facing apps and client-side state
- Learner SPA · Main learner-facing single-page app
frontend/src/App.jsx - App Shell · Shared layout, navigation, protected routing, and auth UI
frontend/src/components/DashboardLayout.jsx - Client State · Auth, sidebar, and theme state providers
frontend/src/context/AuthContext.jsx - API Client · Frontend boundary for backend requests and service calls
frontend/src/lib/api.js - Learner Pages · Dashboard, courses, learning, discussions, analytics, certificates, settings, and auth pages
frontend/src/pages/Dashboard.jsx - Admin UI · Separate frontend for staff and admin operations
frontendAdmin/src/App.jsx
API Backend
Express application and domain modules
- Express API · Main application server and REST API entrypoint
backend/server.js - API Routes · Auth, courses, community, analytics, notifications, preferences, certificates, payment, and AI routes
backend/routes/auth.js - Domain Controllers · Business logic for users, courses, discussions, analytics, certificates, and notifications
backend/controllers/courseController.js - Middleware · JWT protection and schema validation
backend/middleware/authMiddleware.js - Data Models · Relational domain entities and associations
backend/models/modelAssociations.js - Certificate Template · Backend certificate rendering logic
backend/templates/certificateTemplate.js - Email and Utils · Email delivery and shared helper functions
backend/utils/sendEmail.js - Payments · Checkout and webhook flow for purchases
backend/routes/payment.js - AI Bridge · Backend endpoint that orchestrates AI generation requests
backend/routes/aiRoutes.js
AI Service
Python media-generation service
- AI Microservice · Separate Python service for lesson video generation
ai_service/backend/api.py - Media Pipeline · Gemini, TTS, and FFmpeg assembly and rendering flow
ai_service/backend/config.py
Data and Integrations
Persistent models and external services
- Postgres DB · Primary system of record
backend/config/db.js - Media Storage · Backend media upload and delivery integration
backend/config/cloudinary.js - Firebase · Client-side identity and Google OAuth
- Stripe · External checkout and webhook provider
- Gemini/TTS/FFmpeg · Model, speech, and rendering toolchain
- Cloudinary · External media storage and delivery
Connections 25
- 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