Metrics microservice built with NestJS for the Melodía platform.
The application is deployed on Heroku and accessible at: https://melodia-metrics-e9ca6dea743b.herokuapp.com/
This Metrics Service provides comprehensive analytics and tracking for the Melodía platform, offering:
- Real-time Metrics Collection: Track user interactions, song plays, likes, and shares
- RabbitMQ Integration: Asynchronous message processing for scalable metrics collection
- MongoDB Storage: Efficient storage and querying of metrics data
- RESTful API: Comprehensive endpoints for metrics retrieval and analysis
The metrics service follows a microservices architecture pattern with event-driven communication:
- Metrics Collection Layer: Captures user interactions and system events
- RabbitMQ Integration: Asynchronous message processing for scalable data ingestion
- Data Storage Layer: MongoDB for efficient metrics storage and querying
This project uses one queue with one exchange, with one topic and multiple routing keys, the benefits of this approach are:
- Native RabbitMQ Routing: Leverages RabbitMQ's built-in routing capabilities rather than application-level logic
- Better Performance: Message routing happens at the broker level, which is more efficient
- Semantic Routing Keys: Keys like
metrics.song.playclearly express intent and message type
Format: metrics.<entity>.<action>
- Song metrics:
metrics.song.play,metrics.song.like,metrics.song.share - Album metrics:
metrics.album.like,metrics.album.share - User metrics:
metrics.user.registration,metrics.user.activity
- Node.js (>=18.0.0)
- npm or yarn
- MongoDB
- RabbitMQ
PORT=3000
MONGODB_URI=mongodb://admin:admin@localhost:27017/metrics?authSource=admin
RABBITMQ_URL=amqp://localhost:5672
# Or for CloudAMQP
CLOUDAMQP_URL=...$ npm install# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:covFor comprehensive API documentation, including all endpoints, request/response schemas, and interactive testing, visit our Swagger documentation:
Comprehensive test coverage tracked automatically via Codecov:
View Detailed Coverage Report & Interactive Graphs
- NestJS: Modern Node.js framework with TypeScript support
- MongoDB: NoSQL database for scalable metrics storage
- RabbitMQ: Message broker for asynchronous event processing
- Mongoose: MongoDB object modeling for Node.js
- Jest: Testing framework with mocking capabilities
- ESLint: Code quality and style enforcement
- TypeScript: Type safety and enhanced developer experience