# saikrishna1355/node_repo architecture

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

- Interactive diagram: https://gitdiagram.com/saikrishna1355/node_repo
- Repository: https://github.com/saikrishna1355/node_repo

## Overview

##### Project type and purpose
- This is a Node.js backend API.
- It provides JWT‐based authentication/authorization, abstracts over MongoDB and MySQL, supports asynchronous jobs/queues, daily log rotation, environment-specific configs, and PM2 clustering.

##### File structure
- Entry point: src/app.js
- Configuration: config/config.js, .env*, ecosystem.json for PM2
- Database adapters: src/database/mysql.js and src/database/mongo.js
- Data layers:
- Models: src/models/User.js
- Repositories: src/repositories/authRepo.js
- Business logic (Service layer): src/services/authService.js, src/services/userService.js
- API layer: src/routes/api_v1.js with Express + middlewares/authMiddleware.js
- Job/Queue subsystem:
- Job definitions: src/jobs/addEmailJob.js
- Queue wrapper: src/queues/emailQueue.js
- Worker process: src/workers/emailWorker.js
- Utilities: src/utils (asyncHandler, jwt, logger)
- Migrations & Seeders: migrations/*.js, seeders/*.js
- Logs directory with Winston‐rotated files

##### README for additional insights
- Multi-environment configuration (dev, SIT, UAT, prod)
- PM2 process manager workflows (NODE-DEV, NODE-PROD)
- db migrations / seeding commands

##### Capturing essential architectural elements
- Include:
- Entry point (app.js + PM2)
- Middleware and routing path
- Service → repo → DB adapter
- Job producer and consumer
- Logging path
- Config loader

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["API Client"]:::external

    subgraph "PM2 Cluster" 
        classDef orchestration fill:#dddddd,stroke:#999999;
        classDef compute fill:#cce5ff,stroke:#2a6cb0;
        classDef util fill:#e6f7ff,stroke:#66b2ff;
        direction TB
        App["Entry Point: app.js"]:::compute
        Config["Configuration Loader"]:::orchestration
        subgraph "Express Pipeline"
            direction TB
            Middleware["Auth Middleware"]:::compute
            Routes["API Routes"]:::compute
        end
        subgraph "Service Layer"
            direction TB
            AuthService["authService"]:::compute
            UserService["userService"]:::compute
        end
        subgraph "Data Access Layer"
            direction TB
            AuthRepo["authRepo"]:::compute
            UserModel["User Model"]:::compute
            subgraph "DB Adapters"
                direction TB
                MySQLAdapter["MySQL Adapter"]:::compute
                MongoAdapter["MongoDB Adapter"]:::compute
            end
        end
        subgraph "Job Producer"
            direction TB
            JobDef["addEmailJob"]:::compute
            QueueWrap["emailQueue"]:::compute
        end
        subgraph "Utilities"
            direction TB
            AsyncUtil["asyncHandler"]:::util
            JwtUtil["jwt"]:::util
            LoggerUtil["logger"]:::util
        end
    end

    MySQL[(MySQL)]:::db
    Mongo[(MongoDB)]:::db
    Queue[(Queue: Redis/RabbitMQ)]:::queue
    Worker["Email Worker"]:::compute
    Logs["Logging Subsystem"]:::logging

    Client -->|HTTP Request| App
    App --> Config
    App --> Middleware
    Middleware --> Routes
    Routes --> AuthService
    Routes --> UserService
    AuthService --> AuthRepo
    UserService --> AuthRepo
    AuthRepo --> MySQLAdapter
    AuthRepo --> MongoAdapter
    MySQLAdapter --> MySQL
    MongoAdapter --> Mongo
    AuthService --> JobDef
    JobDef --> QueueWrap
    QueueWrap --> Queue
    Queue --> Worker
    Worker -->|Executes Job| Logs
    App -->|Logs| Logs
    Middleware -->|Logs| Logs
    AuthService -->|Logs| Logs
    AuthRepo -->|Logs| Logs
    JobDef -->|Logs| Logs

    classDef db fill:#d4edda,stroke:#2f6627;
    classDef queue fill:#ffe5b4,stroke:#cc8400;
    classDef logging fill:#f3e6ff,stroke:#9d58b5;
    classDef external fill:#f0f0f0,stroke:#999999;

    click App "https://github.com/saikrishna1355/node_repo/blob/main/src/app.js"
    click Config "https://github.com/saikrishna1355/node_repo/blob/main/config/config.js"
    click Middleware "https://github.com/saikrishna1355/node_repo/blob/main/src/middlewares/authMiddleware.js"
    click Routes "https://github.com/saikrishna1355/node_repo/blob/main/src/routes/api_v1.js"
    click AuthService "https://github.com/saikrishna1355/node_repo/blob/main/src/services/authService.js"
    click UserService "https://github.com/saikrishna1355/node_repo/blob/main/src/services/userService.js"
    click AuthRepo "https://github.com/saikrishna1355/node_repo/blob/main/src/repositories/authRepo.js"
    click UserModel "https://github.com/saikrishna1355/node_repo/blob/main/src/models/User.js"
    click MySQLAdapter "https://github.com/saikrishna1355/node_repo/blob/main/src/database/mysql.js"
    click MongoAdapter "https://github.com/saikrishna1355/node_repo/blob/main/src/database/mongo.js"
    click JobDef "https://github.com/saikrishna1355/node_repo/blob/main/src/jobs/addEmailJob.js"
    click QueueWrap "https://github.com/saikrishna1355/node_repo/blob/main/src/queues/emailQueue.js"
    click Worker "https://github.com/saikrishna1355/node_repo/blob/main/src/workers/emailWorker.js"
    click AsyncUtil "https://github.com/saikrishna1355/node_repo/blob/main/src/utils/asyncHandler.js"
    click JwtUtil "https://github.com/saikrishna1355/node_repo/blob/main/src/utils/jwt.js"
    click LoggerUtil "https://github.com/saikrishna1355/node_repo/blob/main/src/utils/logger.js"
    click Logs "https://github.com/saikrishna1355/node_repo/tree/main/logs/"
    class App,Config,Middleware,Routes,AuthService,UserService,AuthRepo,UserModel,MySQLAdapter,MongoAdapter,JobDef,QueueWrap,AsyncUtil,JwtUtil,LoggerUtil compute
    class Client external
    class MySQL,Mongo db
    class Queue queue
    class Logs logging
```
