# ninjatechdevops/nodejs-sample-code architecture

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

- Interactive diagram: https://gitdiagram.com/ninjatechdevops/nodejs-sample-code
- Repository: https://github.com/ninjatechdevops/nodejs-sample-code

## Overview

##### Project type and purpose
- This is a backend-focused, full-stack (API-only) TypeScript/Node.js application named “foreplay.”
- It exposes HTTP/HTTPS endpoints (using Express), handles authentication, user management, and real-time events via WebSocket.
- It’s containerized (Docker) and fronted by Nginx for SSL termination and routing.

##### File structure
- Top-level config & infra:
- docker-compose.yml & dockerfile → container orchestration
- nginx.conf → reverse proxy/SSL termination
- ecosystem.config.js → PM2 process management
- jenkinsfile-staging → CI/CD pipeline
- Source code under src/:
- server.ts / app.ts → Express app bootstrap
- routes/ → endpoint definitions (auth, user)
- controllers/ → request handlers
- services/ → business logic (auth.service, user.service)
- database/ → DB connection setup
- models/ → data schemas (users.model)
- middlewares/ → auth guard, validation, error handling
- socket/ → real-time event entry point
- utils/ → logger, mailer (external SMTP), constants
- Tests in src/test/ using Jest.

##### Key README insights
- Standard npm scripts for dev (“npm run dev”) and production (“npm run prod”).

##### Detail
- Middleware layers and how validation/auth flow works.
- Where DTOs and interfaces enforce contracts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        Jenkins["Jenkins Pipeline"]:::external
        DockerCompose["Docker Orchestration\n(docker-compose.yml)"]:::container
        PM2["PM2 Process Manager\n(ecosystem.config.js)"]:::container
    end
    Jenkins -->|"triggers build"| DockerCompose
    DockerCompose -->|"uses Dockerfile"| Dockerfile["Dockerfile"]:::container
    DockerCompose --> PM2

    click Jenkins "https://github.com/ninjatechdevops/nodejs-sample-code/tree/dev_shrey/jenkinsfile-staging"
    click DockerCompose "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/docker-compose.yml"
    click Dockerfile "https://github.com/ninjatechdevops/nodejs-sample-code/tree/dev_shrey/dockerfile"
    click PM2 "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/ecosystem.config.js"

    %% Clients
    Clients["Clients\n(Browser/Mobile)"]:::external

    %% Nginx Proxy Container
    subgraph "Nginx Proxy Container" 
        direction TB
        Nginx["Nginx Proxy"]:::container
        SSL["SSL Certificates"]:::module
    end
    SSL_cert["cert.pem"]:::module
    SSL_chain["chain.pem"]:::module
    SSL_key["privkey.pem"]:::module
    SSL --> SSL_cert
    SSL --> SSL_chain
    SSL --> SSL_key

    click Nginx "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/nginx.conf"
    click SSL_cert "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/ssl/cert.pem"
    click SSL_chain "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/ssl/chain.pem"
    click SSL_key "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/ssl/privkey.pem"

    %% API Server Container
    subgraph "API Server Container" 
        direction TB
        ExpressAPI["Express API (app.ts/server.ts)"]:::container
        Config["Configuration Module"]:::module
        Routes["HTTP Routes"]:::module
        Controllers["Controllers"]:::module
        Services["Services"]:::module
        DBConn["Database Connection"]:::module
        Models["Data Models"]:::module
        DTOs["DTOs"]:::module
        Interfaces["Interfaces"]:::module
        Middlewares["Middlewares"]:::module
        Socket["WebSocket Entry Point"]:::module
        Utils["Utility Modules"]:::module
    end

    click ExpressAPI "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/app.ts"
    click ExpressAPI "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/server.ts"
    click Config "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/config/index.ts"
    click Routes "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/routes/auth.route.ts"
    click Routes "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/routes/user.route.ts"
    click Controllers "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/controllers/auth.controller.ts"
    click Controllers "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/controllers/user.controller.ts"
    click Services "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/services/auth.service.ts"
    click Services "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/services/user.service.ts"
    click DBConn "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/database/index.ts"
    click Models "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/models/users.model.ts"
    click DTOs "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/dtos/user.dto.ts"
    click Interfaces "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/interfaces/auth.interface.ts"
    click Interfaces "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/interfaces/users.interface.ts"
    click Middlewares "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/middlewares/auth.middleware.ts"
    click Middlewares "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/middlewares/validation.middleware.ts"
    click Middlewares "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/middlewares/error.middleware.ts"
    click Socket "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/socket/index.js"
    click Utils "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/utils/logger.ts"
    click Utils "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/utils/mailer.ts"
    click Utils "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/utils/constant.ts"
    click Utils "https://github.com/ninjatechdevops/nodejs-sample-code/blob/dev_shrey/src/utils/utils.ts"

    %% External Services
    SMTP["SMTP Email Provider"]:::external
    Database["Database Service"]:::db

    %% Connections
    Clients -->|"HTTPS Request"| Nginx
    Nginx -->|"Proxy HTTP"| ExpressAPI
    Nginx -->|"Proxy WS"| Socket
    ExpressAPI -->|"CRUD Operations"| Database
    ExpressAPI -->|"- Sends Email"| SMTP
    Clients -->|"WebSocket"| Socket

    DockerCompose --> Nginx
    DockerCompose --> ExpressAPI

    %% Styles
    classDef container fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef external fill:#FFFACD,stroke:#FFD700,stroke-width:2px;
    classDef db fill:#98FB98,stroke:#008000,stroke-width:2px;
    classDef module fill:#E6E6FA,stroke:#9370DB,stroke-width:1px;
```
