# tonnyrogers/rotery-server-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/tonnyrogers/rotery-server-v2
- Repository: https://github.com/tonnyrogers/rotery-server-v2

## Overview

##### Project type and purpose
- This is a NestJS–based, monolithic backend application written in TypeScript.
- It exposes both RESTful HTTP endpoints (via Controllers) and real–time WebSocket gateways for features like chat, notifications, and subscriptions.
- Domain: a travel/itinerary management platform with modules for users, itineraries, messaging, payments, content, etc.

##### File structure
- Root files: Dockerfile(.dev), docker-compose.yml, .env.example, migrations/, seeders/, tsconfig, README.
- src/ contains:
- app.module.ts, main.ts – Nest application bootstrap
- config.ts, mikro-orm.config.ts – configuration for environment and ORM
- modules/ – a directory of ~35 feature modules (auth, users, itineraries, chat, payments, files, notifications, etc.), each following the Controller → Service → Repository pattern and using DTOs, interfaces, providers, and enums.
- entities/ – MikroORM entity definitions matching the modules.
- migrations/ – DB schema migrations.
- seeders/ – initial data loaders.
- providers/ and transporter/ – wrappers around Redis, RabbitMQ, email and storage clients.
- utils/, subscribers/, resources/ – utility functions, domain event subscribers, and email templates.

##### README for additional insights
- Build/test scripts are standard (npm run start, start:dev, migrations, seeders, tests).

a. Main components
1. Client Layer
- End users (web or mobile) invoking HTTP REST APIs or opening WebSocket connections.
2. API Layer (NestJS application)
- HTTP Controllers (one per module)
- WebSocket Gateways (chat.gateway.ts, notifications.gateway.ts, subscriptions.gateway.ts, direct-messages.gateway.ts)
3. Business Logic Layer
- Services per feature module
- Domain event subscribers (src/subscribers)
4. Data Access Layer
- Repositories per feature module
- MikroORM entities + migrations
5. Infrastructure / Integration Layer
- Message broker: RabbitMQ (rabbit-publisher.ts, transporter/rabbit-send-email.*)
- Cache/queue: Redis (email.redis.ts)
- File storage: DigitalOcean Spaces or S3 (spaces.ts)
- Email service (mail.ts), Firebase (firebase.ts)
- External payment gateway (Stripe via PaymentsService)
6. Persistence
- Relational database (PostgreSQL / MySQL – configured via mikro-orm.config.ts)
7. DevOps
- Docker containers: App, DB, RabbitMQ, Redis
- docker-compose orchestrates multi-container dev environment

b. Relationships & interactions
- Client → HTTP → NestJS Controllers → Services → Repositories → Database
- Client → WebSocket → NestJS Gateways → Services → Repositories → Database
- Services publish domain events → RabbitMQ → Transporter → External systems (email, push)
- EmailService or subscriber listens on events → pushes to Redis/Rabbit → mail provider
- File uploads/downloads: Client → FilesController → FilesService → Spaces (object storage)
- Payments: PaymentsController → PaymentsService → External payment API → Webhook module → SubscriptionsService

c. Architectural patterns/design principles
- Modular Monolith (feature modules)
- MVC (Controllers → Services → Repositories)
- Dependency injection (Nest providers)
- Repository pattern (MikroORM)
- Event-driven extensions via RabbitMQ and Subscribers
- Separation of concerns: each module has its own DTOs, interfaces, providers, tests

d. Relevant technologies
- NestJS (framework), TypeScript
- MikroORM (ORM) + migrations + seeders
- Docker, docker-compose
- RabbitMQ, Redis
- PostgreSQL/MySQL
- WebSocket (Socket.IO under the hood)
- External services: Stripe, Firebase, S3/Spaces, SMTP/email provider

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef external fill:#f2f2f2,stroke:#999,stroke-width:1px
    classDef api fill:#cce5ff,stroke:#3399ff,stroke-width:1px
    classDef service fill:#e6f7ff,stroke:#33aaff,stroke-width:1px
    classDef db fill:#d9ead3,stroke:#6aa84f,stroke-width:1px
    classDef database fill:#b6d7a8,stroke:#38761d,stroke-width:1px
    classDef broker fill:#fce5cd,stroke:#e69138,stroke-width:1px
    classDef storage fill:#d0e0e3,stroke:#45818e,stroke-width:1px
    classDef externalsvc fill:#eeeeee,stroke:#666666,stroke-width:1px

    Client["Client (Web/Mobile)"]:::external

    subgraph "NestJS Application"
        subgraph "Bootstrap & Config"
            Bootstrap["Application Bootstrap"]:::service
            Config["Configuration"]:::service
        end
        subgraph "API Layer"
            AuthController["AuthController"]:::api
            UsersController["UsersController"]:::api
            ItinerariesController["ItinerariesController"]:::api
            PaymentsController["PaymentsController"]:::api
            FilesController["FilesController"]:::api
            NotificationsController["NotificationsController"]:::api
            ChatGateway["ChatGateway"]:::api
            NotificationsGateway["NotificationsGateway"]:::api
            SubscriptionsGateway["SubscriptionsGateway"]:::api
            DirectMessagesGateway["DirectMessagesGateway"]:::api
        end
        subgraph "Business Logic Layer"
            AuthService["AuthService"]:::service
            UsersService["UsersService"]:::service
            ItinerariesService["ItinerariesService"]:::service
            ChatService["ChatService"]:::service
            PaymentsService["PaymentsService"]:::service
            FilesService["FilesService"]:::service
            NotificationsService["NotificationsService"]:::service
            SubscriptionsService["SubscriptionsService"]:::service
            ResetPasswordSubscriber["ResetPasswordSubscriber"]:::service
        end
        subgraph "Data Access Layer"
            RefreshTokenRepo["RefreshTokenRepository"]:::db
            UsersRepo["UsersRepository"]:::db
            ItinerariesRepo["ItinerariesRepository"]:::db
            ChatRepo["ChatRepository"]:::db
            PaymentsRepo["PaymentsRepository"]:::db
            FilesRepo["FilesRepository"]:::db
            NotificationEntity["NotificationEntity"]:::db
            OtherEntities["Other Entities"]:::db
        end
    end

    %% Client interactions
    Client -->|"HTTP/REST"| AuthController
    Client -->|"HTTP/REST"| UsersController
    Client -->|"HTTP/REST"| ItinerariesController
    Client -->|"HTTP/REST"| PaymentsController
    Client -->|"HTTP/REST"| FilesController
    Client -->|"HTTP/REST"| NotificationsController
    Client -->|"WebSocket"| ChatGateway
    Client -->|"WebSocket"| NotificationsGateway
    Client -->|"WebSocket"| SubscriptionsGateway
    Client -->|"WebSocket"| DirectMessagesGateway

    %% Controller to Services
    AuthController -->|"calls"| AuthService
    UsersController -->|"calls"| UsersService
    ItinerariesController -->|"calls"| ItinerariesService
    PaymentsController -->|"calls"| PaymentsService
    FilesController -->|"calls"| FilesService
    NotificationsController -->|"calls"| NotificationsService

    ChatGateway -->|"uses"| ChatService
    NotificationsGateway -->|"uses"| NotificationsService
    SubscriptionsGateway -->|"uses"| SubscriptionsService
    DirectMessagesGateway -->|"uses"| ChatService

    %% Services to Repositories
    AuthService -->|"uses"| RefreshTokenRepo
    UsersService -->|"uses"| UsersRepo
    ItinerariesService -->|"uses"| ItinerariesRepo
    ChatService -->|"uses"| ChatRepo
    PaymentsService -->|"uses"| PaymentsRepo
    FilesService -->|"uses"| FilesRepo
    NotificationsService -->|"uses"| NotificationEntity
    SubscriptionsService -->|"uses"| OtherEntities

    %% Subscribers and Event Bus
    AuthService -->|"publishes events"| RabbitMQ
    ResetPasswordSubscriber -->|"listens"| RabbitMQ

    %% Persistence and infra
    RefreshTokenRepo -->|"read/write"| DB
    UsersRepo -->|"read/write"| DB
    ItinerariesRepo -->|"read/write"| DB
    ChatRepo -->|"read/write"| DB
    PaymentsRepo -->|"read/write"| DB
    FilesRepo -->|"read/write"| DB
    NotificationEntity -->|"read/write"| DB
    OtherEntities -->|"read/write"| DB

    FilesService -->|"upload/download"| Spaces
    PaymentsService -->|"calls"| Stripe
    EmailService["Email Service"]:::service
    RabbitMQ -->|"push events"| EmailService
    EmailService -->|"cache queue"| Redis
    EmailService -->|"SMTP"| SMTP
    Firebase["Firebase"]:::externalsvc

    %% Infra nodes
    DB["PostgreSQL Database"]:::database
    RabbitMQ["RabbitMQ"]:::broker
    Redis["Redis"]:::broker
    Spaces["Spaces/S3"]:::storage
    Stripe["Stripe"]:::externalsvc
    SMTP["SMTP Provider"]:::externalsvc

    %% Click events
    click Bootstrap "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/main.ts"
    click Bootstrap "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/app.module.ts"
    click Config "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/config.ts"
    click Config "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/mikro-orm.config.ts"
    click AuthController "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/auth/auth.controller.ts"
    click UsersController "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/users/users.controller.ts"
    click ItinerariesController "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/itineraries/itineraries.controller.ts"
    click PaymentsController "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/payments/payments.controller.ts"
    click FilesController "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/files/files.controller.ts"
    click NotificationsController "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/notifications/notifications.controller.ts"
    click ChatGateway "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/chat/chat.gateway.ts"
    click NotificationsGateway "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/notifications/notifications.gateway.ts"
    click SubscriptionsGateway "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/subscriptions/subscriptions.gateway.ts"
    click DirectMessagesGateway "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/direct-messages/direct-messages.gateway.ts"
    click AuthService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/auth/auth.service.ts"
    click UsersService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/users/users.service.ts"
    click ItinerariesService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/itineraries/itineraries.service.ts"
    click ChatService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/chat/chat.service.ts"
    click PaymentsService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/payments/payments.service.ts"
    click FilesService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/files/files.service.ts"
    click NotificationsService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/notifications/notifications.service.ts"
    click SubscriptionsService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/subscriptions/subscriptions.service.ts"
    click RefreshTokenRepo "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/auth/repositories/refresh-token.repository.ts"
    click UsersRepo "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/users/users.repository.ts"
    click ItinerariesRepo "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/itineraries/repositories/itineraries.repository.ts"
    click ChatRepo "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/chat/chat.respository.ts"
    click PaymentsRepo "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/payments/payments.repository.ts"
    click FilesRepo "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/modules/files/files.repository.ts"
    click NotificationEntity "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/entities/notification.entity.ts"
    click RabbitMQ "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/providers/rabbit-publisher.ts"
    click Redis "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/providers/email.redis.ts"
    click EmailService "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/providers/mail.ts"
    click Firebase "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/providers/firebase.ts"
    click Spaces "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/providers/spaces.ts"
    click RabbitMQ "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/transporter/rabbit-send-email.client.ts"
    click RabbitMQ "https://github.com/tonnyrogers/rotery-server-v2/blob/main/src/transporter/rabbit-send-email.strategy.ts"
```
