# titanjagpreet/courseheaven architecture

> Architecture diagram of the GitHub repository titanjagpreet/courseheaven, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/titanjagpreet/courseheaven
- Repository: https://github.com/titanjagpreet/courseheaven

## Overview

##### Project type and purpose
- CourseHeaven is a full-stack backend server (no frontend code here) built with Node.js, Express, and MongoDB.
- Its purpose is to expose RESTful endpoints for user and admin signup/signin, JWT-protected course creation, preview, purchase, and purchase-history retrieval.

##### File structure
- Top-level entry: server.js – bootstraps Express, connects to MongoDB, installs global middleware.
- Directories:
- routes/ – defines Express routers (userRoutes, adminRoutes, courseRoutes)
- controllers/ – request handlers implementing business logic
- middlewares/ – authentication (JWT user/admin), input validation (Zod), rate limiting
- models/ – Mongoose schema & DB connection (db.js)
- Config and env: .env(.example) for secrets, package.json for dependencies, .gitignore.

##### README for additional insights
- JWT-based auth with separate user/admin secrets
- Zod used for request validation
- Future integrations: payment gateway (Stripe/Razorpay), video hosting (S3), frontend (React/EJS)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        UA["User App"]:::external
        AA["Admin App"]:::external
    end

    API["Express Server"]:::api
    click API "https://github.com/titanjagpreet/courseheaven/blob/main/server.js"

    subgraph "Routes Layer"
        UR["User Routes"]:::routes
        AR["Admin Routes"]:::routes
        CR["Course Routes"]:::routes
    end
    click UR "https://github.com/titanjagpreet/courseheaven/blob/main/routes/userRoutes.js"
    click AR "https://github.com/titanjagpreet/courseheaven/blob/main/routes/adminRoutes.js"
    click CR "https://github.com/titanjagpreet/courseheaven/blob/main/routes/courseRoutes.js"

    subgraph "Middleware Layer"
        VUS["Validate User Signup"]:::middleware
        VIS["Validate User Signin"]:::middleware
        VAS["Validate Admin Signup"]:::middleware
        VAI["Validate Admin Signin"]:::middleware
        UM["JWT Auth - User"]:::middleware
        AM["JWT Auth - Admin"]:::middleware
        RL["Rate Limiting"]:::middleware
    end
    click VUS "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/validateUserSignup.js"
    click VIS "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/validateUserSignin.js"
    click VAS "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/validateAdminSignup.js"
    click VAI "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/validateAdminSignin.js"
    click UM "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/userMw.js"
    click AM "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/adminMw.js"
    click RL "https://github.com/titanjagpreet/courseheaven/blob/main/middlewares/rateLimiter.js"

    subgraph "Controller Layer"
        UC["User Controller"]:::controller
        AC["Admin Controller"]:::controller
        CC["Course Controller"]:::controller
    end
    click UC "https://github.com/titanjagpreet/courseheaven/blob/main/controllers/userController.js"
    click AC "https://github.com/titanjagpreet/courseheaven/blob/main/controllers/adminController.js"
    click CC "https://github.com/titanjagpreet/courseheaven/blob/main/controllers/courseController.js"

    subgraph "Data Layer"
        DBConn["Mongoose Setup (db.js)"]:::data
    end
    click DBConn "https://github.com/titanjagpreet/courseheaven/blob/main/models/db.js"

    MDB[(MongoDB)]:::db

    subgraph "External Services"
        PG["Payment Gateway"]:::external
        VS["Video Storage"]:::external
    end

    UA -->|"HTTP"| API
    AA -->|"HTTP"| API

    API --> UR
    API --> AR
    API --> CR

    UR -->|"validate"| VUS -->|"validate"| UM -->|"authorize"| UC
    UR -->|"validate"| VIS -->|"validate"| UM -->|"authorize"| UC

    AR -->|"validate"| VAS -->|"validate"| AM -->|"authorize"| AC
    AR -->|"validate"| VAI -->|"validate"| AM -->|"authorize"| AC

    CR -->|"rate limit"| RL -->|"process"| CC

    UC -->|"access"| DBConn
    AC -->|"access"| DBConn
    CC -->|"access"| DBConn

    DBConn -->|"connects to"| MDB

    CC -->|"process payment"| PG -->|"callback"| CC
    CC -->|"upload video"| VS

    classDef api fill:#E3F2FD,stroke:#333
    classDef routes fill:#BBDEFB,stroke:#333
    classDef middleware fill:#C8E6C9,stroke:#333
    classDef controller fill:#FFE0B2,stroke:#333
    classDef data fill:#D7CCC8,stroke:#333
    classDef db fill:#B2DFDB,stroke:#333
    classDef external fill:#FFF9C4,stroke:#333
```
