# harmeet10000/shiksha-dost-backend architecture

> Architecture diagram of the GitHub repository harmeet10000/shiksha-dost-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harmeet10000/shiksha-dost-backend
- Repository: https://github.com/harmeet10000/shiksha-dost-backend

## Overview

##### Main Components

A. Core Application Layer
- Express.js Application Server (src/app.js)
- Authentication Service (controllers/authController.js)
- Route Handlers (src/routes/*)
- Middleware Layer (src/middlewares/*)

B. Data Layer
- MongoDB Database
- Data Models (src/models/*)
- Database Connection (src/db/connect.js)

C. External Services Integration
- AWS S3 for file storage (helpers/s3.js)
- Razorpay for payments (helpers/razorpay.js)
- Email Service (helpers/email.js)

D. Security Layer
- Authentication Middleware
- Rate Limiting
- Security Headers (Helmet)
- XSS Protection
- MongoDB Sanitization

**┌─────────────────────────────────────────────────────────┐**
- Client Applications                     │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- API Gateway Layer                      │
- (Rate Limiting, Security Headers, Authentication)       │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Core Application Layer                   │
- ┬─────────────────┬───────────────────┤
- Auth Service   │  Blog Service   │  Mentor Service   │
- User Service   │  DPP Service    │  Material Service │
- ┴─────────────────┴───────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Data Layer                          │
- MongoDB Models                        │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- External Services                       │
- AWS S3    │   Razorpay   │   Email Service (SES)    │
- ┘

##### Component Details

A. API Routes (src/routes/*)
- Auth Routes
- Blog Routes
- Mentorship Routes
- Material Routes
- Payment Routes
- User Routes

B. Controllers (src/controllers/*)
- Relationship between routes and controllers
- Factory pattern used (handlerFactory.js)

C. Middleware Chain
- Authentication
- Error Handling
- Visit Tracking

D. Models Layer
- User Model
- Blog Model
- Mentor Model
- Material Model
- Mentorship Model
- DPP Model
- Comment Model

##### Additional Elements

- GitHub Actions workflow for CI/CD
- Environment configuration flow
- Error handling paths
- Security checkpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications"]
        Mobile["Mobile App"]
        Web["Web App"]
    end

    subgraph Security["API Gateway Layer"]
        direction TB
        RateLimit["Rate Limiting"]
        Headers["Security Headers"]:::security
        Auth["Authentication"]:::security
    end

    subgraph Core["Core Application Layer"]
        direction TB
        Express["Express Server"]:::core
        click Express "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/app.js"
        
        subgraph Services["Service Layer"]
            direction TB
            AuthService["Authentication Service"]:::service
            click AuthService "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/controllers/authController.js"
            BlogService["Blog Service"]:::service
            MentorService["Mentor Service"]:::service
            MaterialService["Material Service"]:::service
            DPPService["DPP Service"]:::service
            UserService["User Service"]:::service
        end

        subgraph Middleware["Middleware Layer"]
            direction TB
            AuthMW["Auth Middleware"]:::middleware
            click AuthMW "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/middlewares/authMiddleware.js"
            ErrorMW["Error Handling"]:::middleware
            click ErrorMW "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/middlewares/errorMiddleware.js"
            VisitMW["Visit Tracking"]:::middleware
            click VisitMW "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/middlewares/increaseVisits.js"
        end

        subgraph Utils["Utilities"]
            direction TB
            Factory["Handler Factory"]:::util
            click Factory "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/controllers/handlerFactory.js"
            APIFeatures["API Features"]:::util
            click APIFeatures "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/utils/apiFeatures.js"
            ErrorUtil["Error Utilities"]:::util
            click ErrorUtil "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/utils/appError.js"
            AsyncHandler["Async Handler"]:::util
            click AsyncHandler "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/utils/catchAsync.js"
        end

        Routes["Route Handlers"]:::core
        click Routes "https://github.com/Harmeet10000/Shiksha-Dost-Backend/tree/main/src/routes/"
    end

    subgraph Data["Data Layer"]
        direction TB
        MongoDB[(MongoDB Database)]
        Models["Data Models"]:::data
        click Models "https://github.com/Harmeet10000/Shiksha-Dost-Backend/tree/main/src/models/"
        DBConnect["Database Connection"]:::data
        click DBConnect "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/db/connect.js"
    end

    subgraph External["External Services"]
        direction TB
        S3["AWS S3"]:::external
        click S3 "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/helpers/s3.js"
        Razorpay["Razorpay"]:::external
        click Razorpay "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/helpers/razorpay.js"
        Email["Email Service"]:::external
        click Email "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/helpers/email.js"
    end

    subgraph Deploy["Deployment"]
        direction TB
        Docker["Docker Container"]
        click Docker "https://github.com/Harmeet10000/Shiksha-Dost-Backend/tree/main/Dockerfile"
        GitHub["GitHub Actions"]
        click GitHub "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/.github/workflows/Deploy-Backend.yml"
        EnvConfig["Environment Config"]
        click EnvConfig "https://github.com/Harmeet10000/Shiksha-Dost-Backend/blob/main/src/config/dotenvConfig.js"
    end

    Client --> Security
    Security --> Express
    Express --> Routes
    Routes --> Services
    Services --> Middleware
    Services --> Utils
    Services --> Models
    Models --> MongoDB
    Services --> External

    %% Styling
    classDef core fill:#2374ab
    classDef security fill:#ff7f50
    classDef service fill:#4a90e2
    classDef middleware fill:#98c1d9
    classDef data fill:#95a5a6
    classDef external fill:#27ae60
    classDef util fill:#8e44ad

    %% Legend
    subgraph Legend
        direction TB
        L1["Core Components"]:::core
        L2["Security Components"]:::security
        L3["Services"]:::service
        L4["Middleware"]:::middleware
        L5["Data Components"]:::data
        L6["External Services"]:::external
        L7["Utilities"]:::util
    end
```
