# nazmul-islam00/courshera architecture

> Architecture diagram of the GitHub repository nazmul-islam00/courshera, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nazmul-islam00/courshera
- Repository: https://github.com/nazmul-islam00/courshera

## Overview

1. **Overall shape**
   - This repository is a full-stack learning platform clone with a **React single-page frontend** and a **Node/Express backend API**.
   - The backend owns authentication, course data, user profile data, and payment-related endpoints; the frontend renders the learning experience and calls the API.

2. **Frontend boundary**
   - The frontend is built with **Vite + React** and packaged separately from the backend.
   - In production it is served as static assets behind **Nginx** in the `frontend` Docker image.
   - The app is organized by page-level routes such as Home, Category, Course Outline/Content, My Learning, Profile, Search, Quiz pages, and Payment Result.

3. **Frontend state and API access**
   - Global app state is split into focused contexts:
     - `AuthContext/AuthProvider` for signed-in user state and session handling.
     - `CheckoutContext/CheckoutProvider` for checkout/payment flow state.
   - `frontend/src/api/api.js` is the shared API client boundary between UI components and the backend.

4. **Backend API structure**
   - The backend is an **Express-style service** with feature-based routes:
     - `auth.js` and `regular_auth.js` for login/signup/auth flows.
     - `me.js` for current-user/profile access.
     - `courses.js` for course/catalog content.
     - `payment.js` for payment and saved-card flows.
   - `server.js` is the API entry point and wires the middleware, routes, and database layer together.

5. **Authentication and authorization**
   - Authentication is split into multiple concerns:
     - `passport.js` indicates Passport-based auth strategy support.
     - `utils/jwtGenerator.js` indicates token-based sessions using JWTs.
     - `middleware/authorization.js` protects authenticated endpoints.
     - `middleware/validInfo.js` validates incoming auth payloads.
   - `smsParser.js` suggests an SMS/OTP-related auth path or message parsing support, which is part of the auth boundary.
   - The frontend’s `ProtectedRoute` and auth modal components consume this auth layer.

6. **Course and content domain**
   - Course browsing is a major domain: home page course cards, course outline pages, course content pages, category pages, and search all revolve around course discovery and enrollment.
   - The frontend includes fallback utilities like `courseOutlineFallback.js` and `fallbackCourseImages.js`, implying the UI can render even when backend content is partial or missing.
   - `CoursesFromBackend.jsx` is the bridge component that pulls live course data into the UI.

7. **Checkout and payment flow**
   - The checkout experience is represented both in frontend state and backend endpoints.
   - Frontend checkout UI includes `Checkout.jsx`, saved cards, and payment result screens.
   - `routes/payment.js` is the backend boundary for payment-related operations, likely including payment creation, confirmation, and user card/account state.

8. **Quiz subsystem**
   - Quizzes are a largely self-contained frontend feature with dedicated layouts, headers, footers, sidebar, catalog, take page, past quizzes, and certificate page.
   - `frontend/src/data/quizData.js` indicates at least part of the quiz content is local/static rather than fetched from the backend.
   - This subsystem is separate from the course/payment flow and can be diagrammed as its own client-side feature area.

9. **Data layer**
   - The backend uses **Prisma** (`prisma/schema.prisma`, `prisma.config.ts`) as the ORM boundary to the database.
   - `db.js` likely centralizes the database connection/client instance used by the route handlers.
   - `sqlfiles/ddl.sql` provides the raw schema definition or provisioning script for database setup outside Prisma.

10. **Containerization and runtime**
    - The project is designed to run as two containers: one for the backend and one for the frontend.
    - The backend listens on port **5000** and the frontend container serves on **80**, exposed as **3000** on the host in the README examples.
    - `docker-compose.yml` exists, but the README notes that “docker compose up is no longer supported,” so current deployment appears to be container-per-service.

11. **Operational and repo tooling**
    - GitHub Actions includes a **CI workflow** and a **health-check workflow**, so the repo has automated validation and runtime probing.
    - `api_docs.yaml` suggests the backend API is documented in an OpenAPI-style spec, which is useful for frontend/backend contract alignment.

12. **How the main data flow works**
    - User enters the frontend SPA → frontend components call the API client → backend route handlers process auth/course/payment requests → middleware enforces session/authorization → Prisma/db layer reads or writes persistent data → responses return to the SPA, which updates contexts and page state.

Main entry points: [`frontend/src/App.jsx`](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/App.jsx) (App shell), [`backend/server.js`](https://github.com/nazmul-islam00/courshera/blob/main/backend/server.js) (Server entry), [`backend/db.js`](https://github.com/nazmul-islam00/courshera/blob/main/backend/db.js) (Database layer), [`backend/routes/auth.js`](https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/auth.js) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_frontend_app["App shell<br/>React/Vite SPA<br/>[App.jsx]"]
  node_frontend_api["API client<br/>HTTP client<br/>[api.js]"]
  node_auth_context(("Auth state<br/>context<br/>[AuthContext.jsx]"))
  node_checkout_context(("Checkout state<br/>context"))
  node_protected_route{{"Protected route<br/>route guard<br/>[ProtectedRoute.jsx]"}}
  node_home_courses["Course home<br/>feature UI<br/>[HomePage.jsx]"]
  node_course_bridge["Backend courses<br/>data bridge"]
  node_checkout_ui["Checkout UI<br/>payment UI<br/>[Checkout.jsx]"]
  node_payment_result["Payment result<br/>status page<br/>[PaymentResult.jsx]"]
  node_profile_pages["Profile pages<br/>account UI<br/>[ProfilePage.jsx]"]
  node_quiz_system["Quiz system<br/>client feature<br/>[QuizHomePage.jsx]"]
  node_frontend_fallbacks["UI fallbacks"]
end

subgraph group_backend["Backend API"]
  node_server_entry["Server entry<br/>Express app<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>route group<br/>[auth.js]"]
  node_me_routes["Me routes<br/>route group<br/>[me.js]"]
  node_course_routes["Course routes<br/>route group<br/>[courses.js]"]
  node_payment_routes["Payment routes<br/>route group<br/>[payment.js]"]
  node_auth_middleware{{"Auth middleware<br/>[authorization.js]"}}
  node_session_layer{{"Session layer<br/>auth support<br/>[passport.js]"}}
  node_db_layer[("Database layer<br/>Prisma/db<br/>[db.js]")]
  node_schema["Prisma schema<br/>data model<br/>[schema.prisma]"]
  node_sql_init["SQL bootstrap<br/>schema script<br/>[ddl.sql]"]
end

subgraph group_ops["Ops & Docs"]
  node_api_docs["API docs<br/>contract spec<br/>[api_docs.yaml]"]
  node_ci_cd["CI checks<br/>workflow<br/>[ci.yml]"]
  node_deployment["Container setup<br/>deployment<br/>[docker-compose.yml]"]
end

node_frontend_app -->|"calls"| node_frontend_api
node_frontend_app -->|"uses"| node_auth_context
node_frontend_app -->|"uses"| node_checkout_context
node_frontend_app -->|"guards"| node_protected_route
node_frontend_app -->|"routes"| node_home_courses
node_home_courses -->|"loads"| node_course_bridge
node_home_courses -.->|"falls back"| node_frontend_fallbacks
node_frontend_app -->|"renders"| node_checkout_ui
node_checkout_ui -->|"finishes"| node_payment_result
node_frontend_app -->|"routes"| node_profile_pages
node_frontend_app -->|"routes"| node_quiz_system
node_server_entry -->|"mounts"| node_auth_routes
node_server_entry -->|"mounts"| node_me_routes
node_server_entry -->|"mounts"| node_course_routes
node_server_entry -->|"mounts"| node_payment_routes
node_auth_routes -->|"protects"| node_auth_middleware
node_me_routes -->|"protects"| node_auth_middleware
node_payment_routes -->|"protects"| node_auth_middleware
node_auth_routes -->|"issues"| node_session_layer
node_server_entry -->|"uses"| node_db_layer
node_db_layer -->|"maps to"| node_schema
node_db_layer -.->|"bootstraps"| node_sql_init
node_course_routes -->|"reads/writes"| node_db_layer
node_me_routes -->|"reads/writes"| node_db_layer
node_payment_routes -->|"reads/writes"| node_db_layer
node_auth_routes -->|"reads/writes"| node_db_layer
node_api_docs -.->|"describes"| node_server_entry
node_ci_cd -.->|"checks"| node_server_entry
node_deployment -.->|"packages"| node_server_entry
node_deployment -.->|"packages"| node_frontend_app

click node_frontend_app "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/App.jsx"
click node_frontend_api "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/api/api.js"
click node_auth_context "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/context/auth/AuthContext.jsx"
click node_checkout_context "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/context/checkout/CheckoutContext.jsx"
click node_protected_route "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/auth/ProtectedRoute.jsx"
click node_home_courses "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/pages/HomePage.jsx"
click node_course_bridge "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/CoursesFromBackend.jsx"
click node_checkout_ui "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/checkout/Checkout.jsx"
click node_payment_result "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/payment-result/PaymentResult.jsx"
click node_profile_pages "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/pages/ProfilePage.jsx"
click node_quiz_system "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/pages/QuizHomePage.jsx"
click node_frontend_fallbacks "https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/utils/courseOutlineFallback.js"
click node_server_entry "https://github.com/nazmul-islam00/courshera/blob/main/backend/server.js"
click node_auth_routes "https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/auth.js"
click node_me_routes "https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/me.js"
click node_course_routes "https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/courses.js"
click node_payment_routes "https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/payment.js"
click node_auth_middleware "https://github.com/nazmul-islam00/courshera/blob/main/backend/middleware/authorization.js"
click node_session_layer "https://github.com/nazmul-islam00/courshera/blob/main/backend/passport.js"
click node_db_layer "https://github.com/nazmul-islam00/courshera/blob/main/backend/db.js"
click node_schema "https://github.com/nazmul-islam00/courshera/blob/main/backend/prisma/schema.prisma"
click node_sql_init "https://github.com/nazmul-islam00/courshera/blob/main/sqlfiles/ddl.sql"
click node_api_docs "https://github.com/nazmul-islam00/courshera/blob/main/api_docs.yaml"
click node_ci_cd "https://github.com/nazmul-islam00/courshera/blob/main/.github/workflows/ci.yml"
click node_deployment "https://github.com/nazmul-islam00/courshera/blob/main/docker-compose.yml"

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_api,node_auth_context,node_checkout_context,node_protected_route,node_home_courses,node_course_bridge,node_checkout_ui,node_payment_result,node_profile_pages,node_quiz_system,node_frontend_fallbacks toneBlue
class node_server_entry,node_auth_routes,node_me_routes,node_course_routes,node_payment_routes,node_auth_middleware,node_session_layer,node_db_layer,node_schema,node_sql_init toneAmber
class node_api_docs,node_ci_cd,node_deployment toneMint
```

## Components

### Frontend SPA

React/Vite client, page routes, and UI state.

- [App shell](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/App.jsx): React/Vite SPA · Root client application and route assembly. · `frontend/src/App.jsx`
- [API client](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/api/api.js): HTTP client · Shared frontend boundary for backend requests. · `frontend/src/api/api.js`
- [Auth state](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/context/auth/AuthContext.jsx): context · Signed-in user and session state. · `frontend/src/context/auth/AuthContext.jsx`
- [Checkout state](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/context/checkout/CheckoutContext.jsx): context · Payment and checkout flow state. · `frontend/src/context/checkout/CheckoutContext.jsx`
- [Protected route](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/auth/ProtectedRoute.jsx): route guard · Client-side access control for authenticated pages. · `frontend/src/components/auth/ProtectedRoute.jsx`
- [Course home](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/pages/HomePage.jsx): feature UI · Home, category, search, outline, content, and learning pages centered on course discovery. · `frontend/src/pages/HomePage.jsx`
- [Backend courses](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/CoursesFromBackend.jsx): data bridge · Pulls live course data into the UI. · `frontend/src/components/CoursesFromBackend.jsx`
- [Checkout UI](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/checkout/Checkout.jsx): payment UI · Frontend payment and saved-card experience. · `frontend/src/components/checkout/Checkout.jsx`
- [Payment result](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/components/payment-result/PaymentResult.jsx): status page · Payment outcome and confirmation screen. · `frontend/src/components/payment-result/PaymentResult.jsx`
- [Profile pages](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/pages/ProfilePage.jsx): account UI · My learning, profile, and account-facing pages. · `frontend/src/pages/ProfilePage.jsx`
- [Quiz system](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/pages/QuizHomePage.jsx): client feature · Self-contained quiz catalog, take flow, history, and certificate UI. · `frontend/src/pages/QuizHomePage.jsx`
- [UI fallbacks](https://github.com/nazmul-islam00/courshera/blob/main/frontend/src/utils/courseOutlineFallback.js): utility · Local fallback data for course outlines and images. · `frontend/src/utils/courseOutlineFallback.js`

### Backend API

Express service, auth, courses, payments, and persistence.

- [Server entry](https://github.com/nazmul-islam00/courshera/blob/main/backend/server.js): Express app · Backend application bootstrap and middleware wiring. · `backend/server.js`
- [Auth routes](https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/auth.js): route group · Login, signup, regular auth, and related session flows. · `backend/routes/auth.js`
- [Me routes](https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/me.js): route group · Current-user and profile endpoints. · `backend/routes/me.js`
- [Course routes](https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/courses.js): route group · Catalog and course content endpoints. · `backend/routes/courses.js`
- [Payment routes](https://github.com/nazmul-islam00/courshera/blob/main/backend/routes/payment.js): route group · Payment, saved-card, and checkout endpoints. · `backend/routes/payment.js`
- [Auth middleware](https://github.com/nazmul-islam00/courshera/blob/main/backend/middleware/authorization.js): middleware · Authorization and request validation gates. · `backend/middleware/authorization.js`
- [Session layer](https://github.com/nazmul-islam00/courshera/blob/main/backend/passport.js): auth support · Passport and JWT-based authentication support. · `backend/passport.js`
- [Database layer](https://github.com/nazmul-islam00/courshera/blob/main/backend/db.js): Prisma/db · Shared database client and ORM boundary. · `backend/db.js`
- [Prisma schema](https://github.com/nazmul-islam00/courshera/blob/main/backend/prisma/schema.prisma): data model · Database model definitions for the backend. · `backend/prisma/schema.prisma`
- [SQL bootstrap](https://github.com/nazmul-islam00/courshera/blob/main/sqlfiles/ddl.sql): schema script · Raw SQL provisioning and schema setup script. · `sqlfiles/ddl.sql`

### Ops & Docs

Containerization, CI, and API documentation.

- [API docs](https://github.com/nazmul-islam00/courshera/blob/main/api_docs.yaml): contract spec · OpenAPI-style backend API description. · `api_docs.yaml`
- [CI checks](https://github.com/nazmul-islam00/courshera/blob/main/.github/workflows/ci.yml): workflow · Automated validation and health-check workflows. · `.github/workflows/ci.yml`
- [Container setup](https://github.com/nazmul-islam00/courshera/blob/main/docker-compose.yml): deployment · Docker images and compose-based runtime packaging. · `docker-compose.yml`

## Connections

- App shell → API client: calls · UI data access goes through the shared API client.
- App shell → Auth state: uses · App-wide signed-in state and session handling.
- App shell → Checkout state: uses · Checkout state is shared across payment screens.
- App shell → Protected route: guards · Authenticated pages are wrapped by client-side protection.
- App shell → Course home: routes · Page-level course browsing and account experiences.
- Course home → Backend courses: loads · Live catalog data is bridged into course UI.
- Course home → UI fallbacks: falls back · Client uses local content when backend data is partial.
- App shell → Checkout UI: renders · Checkout screens drive the payment flow.
- Checkout UI → Payment result: finishes · Checkout transitions to payment outcome display.
- App shell → Profile pages: routes · My learning and profile pages are part of the SPA.
- App shell → Quiz system: routes · Dedicated quiz area is handled within the client.
- Server entry → Auth routes: mounts · Authentication endpoints are registered on the API.
- Server entry → Me routes: mounts · Current-user/profile endpoints are registered on the API.
- Server entry → Course routes: mounts · Catalog and course content endpoints are registered on the API.
- Server entry → Payment routes: mounts · Payment and saved-card endpoints are registered on the API.
- Auth routes → Auth middleware: protects · Authenticated actions are validated and authorized.
- Me routes → Auth middleware: protects · Profile access depends on authorization checks.
- Payment routes → Auth middleware: protects · Payment operations are constrained by auth checks.
- Auth routes → Session layer: issues · Auth flows rely on Passport and JWT support.
- Server entry → Database layer: uses · Route handlers share the database client.
- Database layer → Prisma schema: maps to · Prisma schema defines the persistent model.
- Database layer → SQL bootstrap: bootstraps · SQL scripts support database provisioning.
- Course routes → Database layer: reads/writes · Course data is served from persistence.
- Me routes → Database layer: reads/writes · User profile data is persisted here.
- Payment routes → Database layer: reads/writes · Payment and saved-card state is persisted here.
- Auth routes → Database layer: reads/writes · Auth flows create and verify user records and sessions.
- API docs → Server entry: describes · Contract documentation matches the backend surface.
- CI checks → Server entry: checks · CI and health workflows validate the service.
- Container setup → Server entry: packages · Backend is containerized as a service.
- Container setup → App shell: packages · Frontend is containerized and served as static assets.
