How manoj-js/message-management-system works
Project Type and Purpose
• Modular Monolith Backend Service
• Provides REST APIs for message CRUD + full-text search
• Implements Domain-Driven Design (DDD) + event-driven communication
• Multi-tenant support and distributed caching
File Structure
• src/app.module.ts: the root NestJS module
• src/common: cross-cutting concerns (middleware, DTOs, guards, interceptors, tenant context)
• src/message: message bounded context (controllers, services, repositories, schemas/entities)
• src/search: search context (controllers, services)
• src/elastic-consumer: background consumer that reads Kafka events and indexes into Elasticsearch
• src/shared: shared infra modules (Kafka base consumer/producer, Elasticsearch client, Redis client)
• docker-compose.yml: local infra (MongoDB, Kafka, Zookeeper, Elasticsearch, Redis)
README Insights
• REST-based API layer with Swagger/OpenAPI docs
• Event flow: on message create/update, a Kafka event is emitted → consumed by ElasticConsumer → indexed into Elasticsearch
• Search flows directly query Elasticsearch via Search Module
• Redis used for caching (e.g., pagination results or hot items)
• Multi-tenant context injected via middleware and guards
Main Components & Interactions
a. API Clients (e.g., Web/Mobile, Postman)
b. NestJS Application
– Common Module (LoggerMiddleware, TenantMiddleware, AuthGuard, GlobalExceptionFilter, TransformInterceptor)
– Message Module
• MessageController → MessageApplicationService →
– MongoDB Repository (CRUD)
– Kafka Producer (emit message events)
– Search Module
• SearchController → SearchApplicationService → Elasticsearch (reads indexed data)
– Elastic-Consumer Module (Kafka Consumer)
• Reads events → ElasticConsumerService → writes to Elasticsearch
– Shared Module
• Kafka clients, Elasticsearch service, Redis service
– Config Module (environment variables, connection URIs)
– Main.ts (application bootstrap, Swagger setup)
c. External Systems
– MongoDB (primary data store)
– Kafka Cluster (message broker)
– Elasticsearch Cluster (search index)
– Redis (distributed cache)
Architectural Patterns & Design Principles
• Domain-Driven Design: separate bounded contexts (message, search)
• Modular Monolith: feature modules loaded into a single process
• Event-Driven: decoupled write (Message Module) and read (Search) via Kafka
• CQRS-like segregation: writes go to MongoDB; reads go to Elasticsearch
• Middleware & Guards enforce multi-tenancy and authentication