How fabiodeandrade/microservice1-listner works
Project type and purpose
• This is a backend microservice built in TypeScript using Express.
• Its purpose is to consume messages from a RabbitMQ queue, persist them into MongoDB, and expose a REST API for clients to retrieve the stored data.
File structure
• src/main.ts: entry point that wires everything together.
• src/domains: domain services for message consumption (rabbitmq.domain.ts) and persistence (mongoose.domain.ts).
• src/infra: low-level infrastructure adapters (queue-consume infra, environment constants).
• src/interfaces: application interfaces, DTOs, controllers, routes, services, and dependency container.
• Docker artifacts (dockerfile, docker-compose.yaml) define RabbitMQ and MongoDB containers plus the app.
• CI workflow (.github/workflows/ci.yaml) automates linting/build/testing.
README for additional insights
• Follows Domain-Driven Design (DDD) to decouple business logic (domains) from infrastructure.
• Uses Docker Compose for dev/test with RabbitMQ & MongoDB.
• Exposes health check (/) and two GET routes (/get/products, /get/product/:id).
Main components & their interactions
a. Components
• External Systems:
• RabbitMQ broker
• MongoDB database
• Infrastructure Layer:
• Queue Consumer Infra (reads from RabbitMQ)
• Mongoose Infra (writes/reads to MongoDB)
• Env Constants Loader
• Domain Layer:
• message-consumer domain (parses & validates incoming messages)
• persist domain (transforms domain objects to persistence entities)
• Application Layer (Interfaces):
• REST API (Express Server)
– Controllers: product.controller
– Routes: main.router
– Services: product.service (fetches from domains)
• Dependency Container: wires infra ↔ domain ↔ interfaces
• Application Entry: main.ts (bootstraps Express, configures DI container, starts consumer)
b. Interactions and data flow
1. On startup, main.ts loads env constants, initializes DI container.
2. RabbitMQ consumer adapter connects to queue and subscribes.
3. Incoming message → message-consumer domain → persist domain → mongoose adapter → MongoDB.
4. Express server starts; client calls GET endpoints → controller → service → persist domain (read) → mongoose adapter → MongoDB → response.
c. Architectural patterns & design principles
• Layered / Hexagonal (Ports & Adapters) architecture separating domain from infra.
• Dependency Injection container to provide loose coupling and easy swapping of adapters.
• Domain-Driven Design: business logic in src/domains, persistence & queue encapsulated behind domain interfaces.
d. Key technologies & libraries
• TypeScript, Express, RabbitMQ client library, Mongoose, Docker Compose, ts-node (or compiled JS), GitHub Actions for CI.
Elements
• Clear labels: RabbitMQ Exchange/Queue, MessageConsumer Domain, Persist Domain, ProductController, ProductService.