# thangtranse/node-express-mongoose-template architecture

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

- Interactive diagram: https://gitdiagram.com/thangtranse/node-express-mongoose-template
- Repository: https://github.com/thangtranse/node-express-mongoose-template

## Overview

##### Project type and purpose
- This is a backend‐focused, monolithic RESTful API built with Node.js and Express.
- Its primary features are user authentication (including Google OAuth), JWT access/refresh tokens, file uploads, and a mini CRM for managing customers and posts.
- It uses MongoDB as the primary data store and Redis for token/session storage or caching.

##### File structure
- Top‐level Docker and CI/CD artifacts:
- Dockerfile, docker-compose.yml, a docker/ directory for MongoDB containers
- GitHub Actions workflows in .github/workflows (CI, CD, branch cleanup, sync)
- src/ directory follows a layered pattern:
- configs/ – Express middleware configuration (CORS, Helmet, Multer)
- constants/ – Shared constants (e.g., campaign codes)
- controllers/ – Routing logic handlers (user, post, CRM customer, transport, static files)
- services/ – Business logic grouped by domain (user, post, uploadFile, crmCustomer)
- models/ – Mongoose schemas and plugins (e.g., soft‐delete)
- routes/ – Express route definitions that invoke controllers
- databases/ – Connection setup for MongoDB (single & multi) and Redis
- helpers/ and utils/ – Token generation, JWT service, validation, logging, file utilities
- Public assets: public/uploads for storing uploaded files, static‐file controller serves them.
- scripts/ contains production startup scripts.

##### README for additional insights
- Lists out all major services (register, login/logout, Google login, token refresh, list users, upload file, mini CRM).
- Specifies dependencies and environment variables: ports, DB URLs, JWT secrets, Google client ID.
- References Docker images for MongoDB and Redis Commander.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Clients" 
        direction TB
        Clients["Postman/Browser"]:::external
    end

    %% Express App
    subgraph "Express App"
        direction TB
        Server["API Gateway / Express Server"]:::api
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Routes["Route Layer"]:::api
        Controllers["Controller Layer"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        PostService["Post Service"]:::service
        UploadService["Upload Service"]:::service
        CRMService["CRM Customer Service"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Models["Mongoose Models & Plugins"]:::data
        DBConn["Database Connections"]:::data
        Datastores["Databases"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GoogleOAuth["Google OAuth"]:::external
        FileStorage["Local File Storage\n(public/uploads)"]:::external
    end

    %% DevOps
    subgraph "DevOps"
        direction TB
        Docker["Docker & Compose"]:::devops
        CICD["CI/CD Pipelines"]:::devops
    end

    %% Relationships
    Clients -->|"HTTP/HTTPS"| Server
    Server -->|"uses"| Routes
    Routes -->|"invokes"| Controllers
    Controllers -->|"calls"| PostService
    Controllers -->|"calls"| UploadService
    Controllers -->|"calls"| CRMService
    PostService -->|"reads/writes"| Models
    UploadService -->|"stores metadata"| Models
    CRMService -->|"reads/writes"| Models
    Models -->|"plugin"| ModelsPlugins["Soft-Delete Plugin"]:::data
    Models -->|"connects via"| DBConn
    DBConn -->|"connects to"| Datastores
    PostService -->|"caches/tokens"| DBConn
    Controllers -->|"serves files"| FileStorage
    UploadService -->|"writes files"| FileStorage
    PostService -->|"calls OAuth"| GoogleOAuth
    CICD -->|"builds images"| Docker
    Docker -->|"deploys to"| Server

    %% Click Events
    click Server "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/server.js"
    click Routes "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/routes/index.js"
    click Routes "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/routes/user.route.js"
    click Routes "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/routes/post.route.js"
    click Routes "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/routes/crm-customer.route.js"
    click Routes "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/routes/static-file.route.js"
    click Routes "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/routes/transport.route.js"
    click Controllers "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/controllers/user.controller.js"
    click Controllers "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/controllers/post.controller.js"
    click Controllers "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/controllers/crm-customer.controller.js"
    click Controllers "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/controllers/static-file.controller.js"
    click Controllers "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/controllers/transport.controller.js"
    click PostService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/services/post/post.service.js"
    click PostService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/services/post/index.js"
    click UploadService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/services/uploadFile/upload.service.js"
    click UploadService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/services/uploadFile/index.js"
    click CRMService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/services/crmCustomer/crmCustomer.service.js"
    click CRMService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/services/crmCustomer/index.js"
    click Models "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/models/user.model.js"
    click Models "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/models/post.model.js"
    click Models "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/models/crm-customer.model.js"
    click Models "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/models/upload.model.js"
    click Models "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/models/apiKey.model.js"
    click ModelsPlugins "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/models/plugins/soft-delete.plugin.js"
    click DBConn "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/databases/connection.mongodb.js"
    click DBConn "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/databases/connection.multi.mongodb.js"
    click DBConn "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/databases/connection.redis.js"
    click CORSConfig "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/configs/cors.config.js"
    click HelmetConfig "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/configs/helmet.config.js"
    click MulterConfig "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/configs/multer.config.js"
    click JWTService "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/helpers/jwt_service.js"
    click GenerateKey "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/helpers/generate_key.js"
    click Validation "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/helpers/validation.js"
    click Logs "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/helpers/logs_events.js"
    click FileUtil "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/utils/fileUpload.js"
    click PromiseUtil "https://github.com/thangtranse/node-express-mongoose-template/blob/main/src/utils/promise-utils.js"
    click Docker "https://github.com/thangtranse/node-express-mongoose-template/tree/main/Dockerfile"
    click Docker "https://github.com/thangtranse/node-express-mongoose-template/blob/main/docker-compose.yml"
    click Docker "https://github.com/thangtranse/node-express-mongoose-template/blob/main/docker/mongodb/docker-compose.yml"
    click Docker "https://github.com/thangtranse/node-express-mongoose-template/blob/main/docker/mongodb/enable-mongodb.sh"
    click Docker "https://github.com/thangtranse/node-express-mongoose-template/blob/main/docker/mongodb/stop-mongodb.sh"
    click CICD "https://github.com/thangtranse/node-express-mongoose-template/blob/main/.github/workflows/ci.yml"
    click CICD "https://github.com/thangtranse/node-express-mongoose-template/blob/main/.github/workflows/cd.yml"
    click CICD "https://github.com/thangtranse/node-express-mongoose-template/blob/main/.github/workflows/delete-branch-on-closed-pr.yml"
    click CICD "https://github.com/thangtranse/node-express-mongoose-template/blob/main/.github/workflows/sync-production-to-main.yml"
    click ProdScript "https://github.com/thangtranse/node-express-mongoose-template/blob/main/scripts/prod.sh"

    %% Styles
    classDef api fill:#cce5ff,stroke:#1f78b4,color:#0b3d91;
    classDef service fill:#d4edda,stroke:#28a745,color:#155724;
    classDef data fill:#fff3cd,stroke:#e09b00,color:#8a6d3b;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#343a40;
    classDef devops fill:#f5e6ff,stroke:#8e44ad,color:#4a235a;
```
