How tonnyrogers/rotery-server-v2 works
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