# sagarpanchal/smur architecture

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

- Interactive diagram: https://gitdiagram.com/sagarpanchal/smur
- Repository: https://github.com/sagarpanchal/smur

## Overview

##### Main Components
- Client / Frontend: Represent the browser or client, which serves static assets from the /public folder.
- API Server: The core Node.js application that includes:
- Routes – as seen in the “routes” directory (auth.routes, docs.routes, media.routes, etc.)
- Controllers – in the “controllers” directory (auth.controller.js, media.controller.js)
- Middleware – a robust collection (error handling, auth, JSON body parsing, multer error handling, passport integration, etc.)
- Utilities – modular functionalities (JWT handling, email sending, AWS S3 helper, Redis redlock, etc.)
- Configuration – centralized config files in “config” and referenced in “config.md”
- Database: MongoDB (required per README prerequisites)
- External Services:
- AWS S3 (as evident in utils/aws/AwsS3Helper.js)
- Email services (utilities for sending emails such as password resets and verification emails)
- OAuth integrations via Passport (with Facebook and Google strategies)
- Optional Redis caching (and redlock mechanism for distributed locking)
- Logging & Monitoring: Winston-based logging (and production management with PM2)

##### Out Relationships and Interactions
- Client to the API Server, clearly directing traffic:
- Requests reaching API endpoints (under “/api*”) are routed through middleware (authentication, error handling, JSON parsing).
- Non-matching GET requests redirect to static files (the “/public/index.html” for frontend routing).
- Within the server, include layers:
- Middleware sits early in the request processing pipeline.
- Routes pass requests to the appropriate controllers.
- Controllers handle business logic and invoke utility services.
- Logging and error reporting across components (e.g., controllers using Winston utilities from utils/winston).

##### Architectural Patterns and Design Choices
- Layered Architecture: Clearly separate the API server into middleware, routing, controller, and utility/service layers.
- Use of modular, utility-based design (notice many modules in “utils”) to keep concerns separated.
- Integration Patterns: External integrations like AWS, email, and OAuth are handled by abstracted modules ensuring easier testing and maintenance.
- Optional Scalability: Production mode runs with PM2 in cluster mode indicating that the application is built to scale horizontally.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client / Frontend (Static Assets)"]:::client
    B["Index (API Server Entry)"]:::entry

    A -->|"HTTP_Request"| B

    subgraph "API Server"
        direction TB
        C["Middleware (Auth,Error,JSON,...)"]:::middleware
        D["Routes (API Endpoints)"]:::routes
        E["Controllers"]:::controllers
        F["Utilities & Services"]:::utils
        G["Config & Environment"]:::config
    end

    B -->|"LoadConfig"| G
    B -->|"ProcessRequest"| C
    C -->|"DetermineRoute"| D
    D -->|"InvokeController"| E
    E -->|"UseUtilities"| F
    E -->|"DB_Operations"| H["MongoDB"]:::database
    F -->|"MediaOps"| I["AWS S3 Helper"]:::external
    F -->|"EmailOps"| J["Email Services"]:::external
    F -->|"JWT_Handling"| K["JWT Utilities"]:::external
    F -->|"OAuth"| L["Passport / OAuth"]:::external
    F -->|"Caching"| M["Redis Redlock"]:::external
    E -->|"LogActivity"| N["Logging (Winston)"]:::external
    B -->|"ManagedBy"| O["PM2 Process Manager"]:::pm2

    click A "https://github.com/sagarpanchal/smur/tree/master/public/"
    click B "https://github.com/sagarpanchal/smur/blob/master/index.js"
    click C "https://github.com/sagarpanchal/smur/tree/master/middleware/"
    click D "https://github.com/sagarpanchal/smur/tree/master/routes/"
    click E "https://github.com/sagarpanchal/smur/tree/master/controllers/"
    click I "https://github.com/sagarpanchal/smur/blob/master/utils/aws/AwsS3Helper.js"
    click J "https://github.com/sagarpanchal/smur/tree/master/utils/email/"
    click K "https://github.com/sagarpanchal/smur/tree/master/utils/jwt/"
    click L "https://github.com/sagarpanchal/smur/tree/master/utils/passport/"
    click M "https://github.com/sagarpanchal/smur/blob/master/utils/redis/redlock.js"
    click N "https://github.com/sagarpanchal/smur/tree/master/utils/winston/"
    click G "https://github.com/sagarpanchal/smur/tree/master/config/"
    click H "https://github.com/sagarpanchal/smur/tree/master/models/"

    classDef client fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef entry fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef middleware fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef routes fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef controllers fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef utils fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef config fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef database fill:#fdfd96,stroke:#f0ad4e,stroke-width:2px;
    classDef external fill:#d1cfe2,stroke:#6f42c1,stroke-width:2px;
    classDef pm2 fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
```
