# sxxrya666/tour-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/sxxrya666/tour-management-system
- Repository: https://github.com/sxxrya666/tour-management-system

## Overview

##### Project Type & Purpose
- This is a backend‐focused web API (built with Node.js/Express) that powers a tour management frontend (not in this repo) and stores data in MongoDB.
- Purpose: Expose RESTful endpoints for tours, users, and reviews; secure those endpoints; and run in Docker.

##### Key Architectural Patterns
- MVC‐style separation:
- Routes → Controllers → Models
- Middleware pipeline for cross‐cutting concerns (security, rate limiting, error handling).
- Single monolithic service (Node/Express) with a single MongoDB database.
- Containerized deployment via Docker Compose.

##### Main Components
A. Clients
- Web or Mobile App (HTTP(S) client)
- Optional: Admin Dashboard
B. API Service
1. API Gateway (Express app entry points: app.js/server.js)
2. Middleware Layer
- Security (helmet, hpp, data sanitization)
- Rate limiter (globalRateLimit.js)
- Body parser, compression
- Error handlers (catchErrorsInEveryRoute, AppError)
3. Routing Layer
- /api/v1/tours → tour.routes.js
- /api/v1/users → user.routes.js
- /api/v1/reviews → review.routes.js
4. Controller Layer
- tour.controller.js, user.controller.js, review.controller.js, auth.controller.js, error.controller.js
5. Business Logic & Utilities
- APIfeatures (filtering/pagination)
- token.emailer, serverShutdown, dev‐data import
6. Data Access Layer (Models)
- tourModel.js, userModel.js, reviewModel.js (Mongoose schemas)
C. Database
- MongoDB instance (hosted or containerized)
D. Infrastructure/Deployment
- Docker (Dockerfile, Dockerfile.dev)
- Docker Compose (api service + mongo service)
- Environment variables (.env)

1. Client → API Gateway (HTTP request)
2. Gateway → Middleware (sequential pipeline)
3. Middleware → Router → Controller
4. Controller ↔ Model (CRUD ops on MongoDB)
5. Controller → Utilities (e.g., send email, import data)
6. Service → Database (MongoDB)
- Error flows: Controller → Error Handler → Client (error response)

##### Technologies & Patterns
- Express.js for HTTP
- Mongoose for data models
- Docker Compose for orchestration
- JWT for auth (handled in auth.controller.js)
- Rate limiting, helmet, hpp, compression as middleware
- MVC organization with clear layers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients" 
        direction TB
        WebApp["Web/Mobile App"]:::clients
        AdminDash["Admin Dashboard (Optional)"]:::clients
    end

    %% API Gateway
    subgraph "API Gateway" 
        direction TB
        AppJS["app.js"]:::gateway
        ServerJS["server.js"]:::gateway
    end

    %% Middleware Layer
    subgraph "Middleware Layer"
        direction TB
        RateLimiter["globalRateLimit.js"]:::middleware
        ErrorCatcher["catchErrorsInEveryRoute.js"]:::middleware
        AppError["AppError.js"]:::middleware
        Security["helmet, hpp, body-parser, compression"]:::middleware
    end

    %% Routing Layer
    subgraph "Routing Layer"
        direction TB
        TourRoutes["tour.routes.js"]:::routes
        UserRoutes["user.routes.js"]:::routes
        ReviewRoutes["review.routes.js"]:::routes
    end

    %% Controller Layer
    subgraph "Controller Layer"
        direction TB
        TourCtrl["tour.controller.js"]:::controllers
        UserCtrl["user.controller.js"]:::controllers
        ReviewCtrl["review.controller.js"]:::controllers
        AuthCtrl["auth.controller.js"]:::controllers
        ErrorCtrl["error.controller.js"]:::controllers
    end

    %% Business Logic & Utilities
    subgraph "Utilities & Business Logic"
        direction TB
        APIFeat["APIfeatures.js"]:::utils
        TokenEmailer["token.emailer.js"]:::utils
        Shutdown["serverShutdown.js"]:::utils
        DevData["import-dev-data.js"]:::utils
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        TourModel["tourModel.js"]:::models
        UserModel["userModel.js"]:::models
        ReviewModel["reviewModel.js"]:::models
    end

    %% Database
    MongoDB[(MongoDB)]:::database

    %% Infrastructure
    subgraph "Infrastructure / Deployment"
        direction TB
        Dockerfile["Dockerfile"]:::infra
        DockerfileDev["Dockerfile.dev"]:::infra
        Compose["docker-compose.yaml"]:::infra
        Env[".env.example"]:::infra
    end

    %% External Services
    EmailService["Email Service"]:::external

    %% Connections
    WebApp -->|"HTTP(S) request"| AppJS
    AdminDash -->|"HTTP(S) request"| AppJS

    AppJS --> ServerJS
    ServerJS --> RateLimiter
    RateLimiter --> Security
    Security --> ErrorCatcher
    ErrorCatcher --> AppError
    AppError --> TourRoutes
    AppError --> UserRoutes
    AppError --> ReviewRoutes

    TourRoutes -->|"POST/GET /api/v1/tours"| TourCtrl
    UserRoutes -->|"POST/GET /api/v1/users"| UserCtrl
    ReviewRoutes -->|"POST/GET /api/v1/reviews"| ReviewCtrl

    TourCtrl --> TourModel
    UserCtrl --> UserModel
    ReviewCtrl --> ReviewModel

    TourCtrl --> APIFeat
    UserCtrl --> APIFeat
    ReviewCtrl --> APIFeat

    AuthCtrl --> TokenEmailer
    AuthCtrl --> Shutdown
    AuthCtrl --> DevData

    TourCtrl --> EmailService
    AuthCtrl --> EmailService

    TourModel --> MongoDB
    UserModel --> MongoDB
    ReviewModel --> MongoDB

    ServerJS --> Compose
    Compose --> Dockerfile
    Compose --> DockerfileDev
    Compose --> MongoDB
    Compose --> AppJS
    Compose --> Env

    %% Click Events
    click AppJS "https://github.com/sxxrya666/tour-management-system/blob/master/app.js"
    click ServerJS "https://github.com/sxxrya666/tour-management-system/blob/master/server.js"
    click RateLimiter "https://github.com/sxxrya666/tour-management-system/blob/master/middleware/globalRateLimit.js"
    click ErrorCatcher "https://github.com/sxxrya666/tour-management-system/blob/master/utils/catchErrorsInEveryRoute.js"
    click AppError "https://github.com/sxxrya666/tour-management-system/blob/master/utils/AppError.js"
    click TourRoutes "https://github.com/sxxrya666/tour-management-system/blob/master/routes/tour.routes.js"
    click UserRoutes "https://github.com/sxxrya666/tour-management-system/blob/master/routes/user.routes.js"
    click ReviewRoutes "https://github.com/sxxrya666/tour-management-system/blob/master/routes/review.routes.js"
    click TourCtrl "https://github.com/sxxrya666/tour-management-system/blob/master/controllers/tour.controller.js"
    click UserCtrl "https://github.com/sxxrya666/tour-management-system/blob/master/controllers/user.controller.js"
    click ReviewCtrl "https://github.com/sxxrya666/tour-management-system/blob/master/controllers/review.controller.js"
    click AuthCtrl "https://github.com/sxxrya666/tour-management-system/blob/master/controllers/auth.controller.js"
    click ErrorCtrl "https://github.com/sxxrya666/tour-management-system/blob/master/controllers/error.controller.js"
    click APIFeat "https://github.com/sxxrya666/tour-management-system/blob/master/utils/APIfeatures.js"
    click TokenEmailer "https://github.com/sxxrya666/tour-management-system/blob/master/utils/token.emailer.js"
    click Shutdown "https://github.com/sxxrya666/tour-management-system/blob/master/utils/serverShutdown.js"
    click DevData "https://github.com/sxxrya666/tour-management-system/blob/master/utils/dev-data/import-dev-data.js"
    click TourModel "https://github.com/sxxrya666/tour-management-system/blob/master/models/tourModel.js"
    click UserModel "https://github.com/sxxrya666/tour-management-system/blob/master/models/userModel.js"
    click ReviewModel "https://github.com/sxxrya666/tour-management-system/blob/master/models/reviewModel.js"
    click Dockerfile "https://github.com/sxxrya666/tour-management-system/tree/master/Dockerfile"
    click DockerfileDev "https://github.com/sxxrya666/tour-management-system/blob/master/Dockerfile.dev"
    click Compose "https://github.com/sxxrya666/tour-management-system/blob/master/docker-compose.yaml"
    click Env "https://github.com/sxxrya666/tour-management-system/blob/master/.env.example"

    %% Styles
    classDef clients fill:#AED6F1,stroke:#1B4F72,color:#1B4F72
    classDef gateway fill:#ABEBC6,stroke:#145A32,color:#145A32
    classDef middleware fill:#D5F5E3,stroke:#196F3D,color:#196F3D
    classDef routes fill:#D5F5E3,stroke:#1D8348,color:#1D8348
    classDef controllers fill:#A9DFBF,stroke:#186A3B,color:#186A3B
    classDef utils fill:#E8DAEF,stroke:#512E5F,color:#512E5F
    classDef models fill:#F9E79F,stroke:#B7950B,color:#B7950B
    classDef database fill:#F5CBA7,stroke:#A04000,color:#A04000
    classDef infra fill:#D6DBDF,stroke:#566573,color:#566573
    classDef external fill:#D4E6F1,stroke:#154360,color:#154360
```
