A production-oriented backend microservice for invoice analytics, reporting, PDF generation and monitoring, built with Node.js, Express, MongoDB, Redis, Docker and Swagger.
Reporting Service API is a standalone microservice responsible for invoice analytics and reporting.
The service aggregates invoice data stored in MongoDB, provides reporting endpoints, generates PDF reports, exposes monitoring endpoints, supports optional Redis caching and includes Swagger/OpenAPI documentation.
The project demonstrates common backend concepts such as:
- REST API design
- API-Key authentication
- JWT authentication
- Role-based authorization
- MongoDB aggregation
- PDF generation
- Health monitoring
- Automated testing
- Docker deployment
Swagger UI is available after starting the application:
http://localhost:4000/api-docs
The documentation includes:
- Available endpoints
- Request descriptions
- Response information
- API-Key authentication
- JWT authentication
Interactive API documentation with API-Key and JWT authentication support.
| Feature | Description |
|---|---|
| Invoice Analytics | Revenue and invoice statistics |
| Revenue Reports | Revenue grouped by day |
| PDF Export | Daily report generation as PDF |
| API-Key Security | Header-based API protection |
| JWT Authentication | Bearer token validation |
| Role Authorization | Role-based access control |
| Health Endpoint | Service monitoring |
| Metrics Endpoint | Runtime statistics |
| Redis Cache | Optional response caching |
| Docker Support | Container deployment |
| Swagger/OpenAPI | Interactive API documentation |
| Automated Tests | Jest + Supertest |
- Node.js
- Express.js
- MongoDB
- Mongoose
- Redis
- Docker
- Swagger / OpenAPI
- JWT
- Jest
- Supertest
- PDFKit
- node-cron
| Method | Endpoint | Description |
|---|---|---|
| GET | /reports/summary |
Invoice summary statistics |
| GET | /reports/revenue-per-day |
Revenue grouped by day |
| GET | /reports/daily-report.pdf |
Generate PDF report |
| GET | /health |
Service health check |
| GET | /metrics |
Runtime metrics |
Protected reporting endpoints require:
x-api-key: your_api_key_hereAuthorization: Bearer <jwt-token>Swagger supports both authentication methods through the Authorize button.
reporting-service-api/
├── controllers/
├── middleware/
├── models/
├── routes/
├── services/
├── swagger/
├── tests/
├── utils/
├── index.js
├── Dockerfile
├── package.json
├── .env.example
└── README.md
Create a local .env file based on .env.example.
PORT=4000
MONGODB_URI=mongodb://127.0.0.1:27017/reporting_service
API_KEY=your_api_key_here
JWT_SECRET=your_jwt_secret_here
# Optional
REDIS_URL=If Redis is not installed locally, leave REDIS_URL empty.
git clone https://github.com/tabari86/reporting-service-api.git
cd reporting-service-api
npm installnpm startnpm testAll current Jest test suites pass successfully.
Build image:
docker build -t reporting-service-api .Run container:
docker run -p 4000:4000 reporting-service-apiHealth endpoint:
http://localhost:4000/health
Metrics endpoint:
http://localhost:4000/metrics
The following files are ignored by Git:
.env
.env.test
Only .env.example is committed to the repository.
Moj Tabari
Website : https://mtintelligence.ai
GitHub: https://github.com/tabari86
LinkedIn : https://www.linkedin.com/in/moj-tabari-04a400227/
