How atharvapanegai/api-radar-api works
Project type and purpose
• This repo is the core backend for “Garuda API Radar,” a real-time API health monitoring and alerting system.
• It exposes REST endpoints (Express.js), persists data to MongoDB, uses Redis for caching, Kafka for event streaming, and sends alert emails.
File structure
• Top-level:
• app.js / index.js – Express app initialization and server startup
• config/ – database and environment configuration
• controllers/ – HTTP-route handlers (project, radar, user)
• routes/ – Express route definitions
• models/ – Mongoose schemas (user, project, radar hit, incident, API model)
• services/ – business logic and integrations (alerting, Kafka, Redis)
• middlewares/ – request lifecycle (authentication, promise wrapper, user lookup)
• utils/ – helper functions and error classes
• templates/ – email templates for alerts and support
• Dockerfile – containerization
README for additional insights
• Confirms tech stack: Node.js, Express, MongoDB, Redis, Kafka/RabbitMQ, email service.
• Mentions “Garuda UI” (React) and “Garuda Caching Service” as other system components.
• Key features: API onboarding, hit processing, incident detection, alert delivery, reports.
Main components
a. Client layer
• Garuda UI (React dashboard)
• API Radar NPM package (instrumentation library)
b. API Gateway / Backend (this repo)
• Express.js server
• Route layer → Controller layer → Service layer → Model (MongoDB)
• Middleware (auth via JWT, logging, error handling)
c. Data stores & messaging
• MongoDB (primary persistence for users, projects, incidents, metrics)
• Redis (caching layer, e.g., recent metrics or rate limits)
• Kafka (event streaming for hits/alerts)
d. Notification channel
• Email SMTP provider (via alert.service, email templates)
e. Deployment
• Docker container running Node.js app
f. External integrations
• Third-party SMTP
• Any external APIs your users monitor
Relationships and data flows
1. Client (UI or API Radar) → HTTP(S) request → Express route
2. Route middleware (auth, BigPromise) → Controller
3. Controller calls Service:
• radar.service: ingests hits → publishes to Kafka → stores in MongoDB
• alert.service: subscribes to Kafka incidents → generates email via templates
• kafka.service, redis.service used internally by services
4. Service writes/reads from MongoDB and Redis
5. On certain thresholds, alert.service sends emails
6. Client retrieves reports via project.controller → aggregated from MongoDB
Architectural patterns and design principles
• Layered (MVC-style) organization: routes → controllers → services → models
• Pub/Sub via Kafka for decoupled hit ingestion & alerting
• Caching layer abstraction (Redis service)
• Separation of concerns: authentication, business logic, persistence
• Config-first approach: config/dbConfig.js and environment variables