A microservices-based backend system providing real-time air quality monitoring, prediction, and analytics APIs
This monorepo contains the complete backend infrastructure for AQMRG's AI Analytics Platform. It provides APIs for air quality data ingestion, processing, ML-powered predictions, and advanced analytics, designed to be consumed by the existing React/Sanity frontend.
The platform follows a microservices architecture with the following key components:
- API Gateway: Central entry point for all client requests
- Authentication Service: JWT-based auth with role-based access control
- Data Ingestion: Real-time sensor data streaming and validation
- Model Serving: ML model inference and prediction endpoints
- Analytics Service: Data processing and reporting
- Notification Service: Alert generation and delivery
- Sensor Adapters: Multi-manufacturer sensor integration
- Export Service: Data export and custom reports
- Runtime: Node.js (Express/NestJS) or Python (FastAPI/Django)
- API: REST + optional GraphQL
- Authentication: JWT with refresh tokens
- Message Queue: Apache Kafka
- Relational DB: PostgreSQL
- Time-Series DB: InfluxDB
- Cache: Redis
- Model Serving: TensorFlow Serving
- Experiment Tracking: MLflow
- ML Libraries: TensorFlow, PyTorch, scikit-learn
- Workflow Orchestration: Apache Airflow
- Containerization: Docker
- Orchestration: Kubernetes
- IaC: Terraform
- Monitoring: Prometheus, Grafana
- Logging: ELK Stack
.
├── services/ # Microservices
│ ├── api-gateway/ # Request routing, rate limiting, CORS
│ ├── auth-service/ # JWT authentication & authorization
│ ├── data-ingestion-service/ # Real-time sensor data streaming
│ ├── model-serving-service/ # ML model inference endpoints
│ ├── analytics-service/ # Data processing & reporting APIs
│ ├── notification-service/ # Alert generation & delivery
│ ├── sensor-adapter-service/ # Multi-manufacturer integration
│ └── export-service/ # Data export & report generation
│
├── ml/ # Machine Learning
│ ├── models/ # Trained model artifacts
│ ├── training/ # Training scripts & experiments
│ ├── feature-engineering/ # Feature extraction pipelines
│ ├── model-registry/ # MLflow configurations
│ └── evaluation/ # Model validation & testing
│
├── data-pipeline/ # Data Processing
│ ├── kafka/ # Kafka producers, consumers, topics
│ ├── airflow/ # Airflow DAGs for ETL
│ ├── stream-processors/ # Real-time transformations
│ ├── sensor-adapters/ # Manufacturer-specific adapters
│ └── data-validators/ # Quality checks & anomaly detection
│
├── infrastructure/ # Infrastructure as Code
│ ├── kubernetes/ # K8s manifests
│ ├── terraform/ # Cloud infrastructure
│ ├── docker/ # Dockerfiles & base images
│ ├── helm/ # Helm charts
│ └── monitoring/ # Prometheus, Grafana configs
│
├── databases/ # Database Schemas
│ ├── postgres/ # PostgreSQL migrations & schemas
│ ├── influxdb/ # Time-series configurations
│ └── redis/ # Cache schemas
│
├── shared/ # Shared Code
│ ├── proto/ # Protocol buffer definitions
│ ├── types/ # TypeScript/Python types
│ ├── utils/ # Common utilities
│ ├── config/ # Configuration schemas
│ ├── constants/ # API codes, errors, enums
│ ├── middleware/ # Auth, logging, error handling
│ └── validators/ # Request/response validation
│
├── api-contracts/ # API Specifications
│ ├── openapi/ # OpenAPI/Swagger specs
│ ├── graphql/ # GraphQL schemas
│ └── asyncapi/ # Async API specs
│
├── scripts/ # Automation Scripts
│ ├── deployment/ # Deployment automation
│ ├── database/ # DB management utilities
│ ├── monitoring/ # Health checks & diagnostics
│ ├── data-migration/ # Data migration tools
│ └── seed-data/ # Development data seeding
│
├── tests/ # Testing
│ ├── integration/ # Cross-service tests
│ ├── e2e/ # End-to-end API tests
│ ├── load/ # Performance & load tests
│ └── contract/ # API contract tests
│
├── docs/ # Documentation
│ ├── api/ # API documentation
│ ├── architecture/ # Architecture diagrams & ADRs
│ ├── deployment/ # Deployment guides
│ ├── integration/ # Third-party integration guides
│ └── runbooks/ # Operational runbooks
│
└── config/ # Configuration
├── environments/ # Environment-specific configs
└── feature-flags/ # Feature toggles
GET /api/v1/dashboard/realtime- Real-time air quality dashboard dataGET /api/v1/predictions/current- Current air quality predictions
GET /api/v1/analytics/*- Advanced analytics and filteringPOST /api/v1/data/export- Data export and custom reportsPOST /api/v1/alerts/*- Alert configuration
POST /api/v1/admin/models/*- Model deployment and managementPOST /api/v1/admin/sensors/*- Sensor configurationGET /api/v1/admin/monitoring/*- System monitoring
POST /api/v1/auth/login- User loginPOST /api/v1/auth/refresh- Refresh access tokenPOST /api/v1/auth/logout- User logout
- Docker & Docker Compose
- Node.js 18+ (if using Node.js services)
- Python 3.10+ (if using Python services)
- Kubernetes cluster (for production deployment)
- Terraform (for infrastructure provisioning)
-
Clone the repository
git clone https://github.com/affrentice/aqmrg-api.git cd aqmrg-api -
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Start all services with Docker Compose
docker-compose up -d
-
Run database migrations
make migrate
-
Seed development data
make seed
-
Access services
- API Gateway: http://localhost:8000
- Grafana: http://localhost:3000
- MLflow: http://localhost:5000
Each service can be run independently for development:
cd services/api-gateway
npm install
npm run dev- Create service directory under
/services - Follow the service template structure
- Add service to
docker-compose.yml - Update API gateway routing
- Add integration tests
- Update documentation
- Train and validate model
- Register in MLflow
- Export model artifacts to
/ml/models - Update model serving service
- Deploy via admin API
- Use template in
/data-pipeline/sensor-adapters/template - Implement required interfaces
- Add configuration to adapter service
- Test data ingestion pipeline
- Deploy and monitor
# Run all tests
make test
# Run integration tests
make test-integration
# Run load tests
make test-load
# Run contract tests
make test-contractmake deploy-stagingmake deploy-productioncd infrastructure/terraform
terraform init
terraform plan
terraform apply- Metrics: Prometheus + Grafana dashboards
- Logs: ELK Stack (Elasticsearch, Logstash, Kibana)
- Tracing: Jaeger for distributed tracing
- Alerts: Alertmanager for critical notifications
Access monitoring dashboards:
- Grafana: http://localhost:3000
- Prometheus: http://localhost:9090
- Kibana: http://localhost:5601
- No authentication required
- Access to real-time dashboards
- Basic air quality predictions
- Current conditions
- Enhanced analytics features
- Custom data exports
- Personalized alerts
- Historical data access
- Model deployment
- System configuration
- Sensor management
- Performance monitoring
- All APIs use HTTPS in production
- JWT-based authentication with refresh tokens
- Role-based access control (RBAC)
- Rate limiting on all endpoints
- API key authentication for external integrations
- Secrets managed via external secret management (e.g., AWS Secrets Manager)
- Real-time Processing: Dashboard updates within 30 seconds
- Concurrent Users: Support 1,000+ simultaneous users
- Prediction Latency: <5 seconds for forecast generation
- Data Throughput: Handle 10,000 sensor readings/minute
- Uptime: 99.5% availability
- Create a feature branch
- Make your changes
- Add tests
- Update documentation
- Submit pull request
This project is licensed under the MIT License - see the LICENSE file for details.
The MIT License is a permissive open-source license that allows:
- ✅ Commercial use
- ✅ Modification
- ✅ Distribution
- ✅ Private use
For questions or issues:
- Email: hello@affrentice.com
- Issue Tracker: https://github.com/affrentice/aqmrg-api/issues
- Discussions: https://github.com/affrentice/aqmrg-api/discussions
See CHANGELOG.md for version history and release notes.
Maintained by: AQMRG Development Team Last Updated: January 2026