# atharvapanegai/api-radar-api architecture

> Architecture diagram of the GitHub repository atharvapanegai/api-radar-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atharvapanegai/api-radar-api
- Repository: https://github.com/atharvapanegai/api-radar-api

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["Garuda UI"]:::frontend
        NPM["API Radar NPM"]:::frontend
    end

    %% Backend Container
    subgraph "API Backend (Docker Container)"
        ExpressInit["Express Init\n(app.js,index.js)"]:::app
        click ExpressInit "https://github.com/atharvapanegai/api-radar-api/blob/master/app.js"

        subgraph "Routes & Middleware"
            ProjectRoutes["project.routes.js"]:::app
            click ProjectRoutes "https://github.com/atharvapanegai/api-radar-api/blob/master/routes/project.routes.js"
            RadarRoutes["radar.routes.js"]:::app
            click RadarRoutes "https://github.com/atharvapanegai/api-radar-api/blob/master/routes/radar.routes.js"
            UserRoutes["user.routes.js"]:::app
            click UserRoutes "https://github.com/atharvapanegai/api-radar-api/blob/master/routes/user.routes.js"
            AuthMW["auth.middleware.js"]:::app
            click AuthMW "https://github.com/atharvapanegai/api-radar-api/blob/master/middlewares/auth.middleware.js"
            BigPromise["BigPromise.js"]:::app
            click BigPromise "https://github.com/atharvapanegai/api-radar-api/blob/master/middlewares/BigPromise.js"
            UserLookup["user.middleware.js"]:::app
            click UserLookup "https://github.com/atharvapanegai/api-radar-api/blob/master/middlewares/user.middleware.js"
        end

        subgraph "Controllers"
            ProjectCtrl["project.controller.js"]:::app
            click ProjectCtrl "https://github.com/atharvapanegai/api-radar-api/blob/master/controllers/project.controller.js"
            RadarCtrl["radar.controller.js"]:::app
            click RadarCtrl "https://github.com/atharvapanegai/api-radar-api/blob/master/controllers/radar.controller.js"
            UserCtrl["user.controller.js"]:::app
            click UserCtrl "https://github.com/atharvapanegai/api-radar-api/blob/master/controllers/user.controller.js"
        end

        subgraph "Services"
            AlertSvc["alert.service.js"]:::app
            click AlertSvc "https://github.com/atharvapanegai/api-radar-api/blob/master/services/alert.service.js"
            KafkaSvc["kafka.service.js"]:::app
            click KafkaSvc "https://github.com/atharvapanegai/api-radar-api/blob/master/services/kafka.service.js"
            RedisSvc["redis.service.js"]:::app
            click RedisSvc "https://github.com/atharvapanegai/api-radar-api/blob/master/services/redis.service.js"
        end

        subgraph "Models / DB Layer"
            APIModel["api.model.js"]:::data
            click APIModel "https://github.com/atharvapanegai/api-radar-api/blob/master/models/api.model.js"
            IncidentModel["incident.model.js"]:::data
            click IncidentModel "https://github.com/atharvapanegai/api-radar-api/blob/master/models/incident.model.js"
            ProjectModel["project.model.js"]:::data
            click ProjectModel "https://github.com/atharvapanegai/api-radar-api/blob/master/models/project.model.js"
            RadarModel["radar.model.js"]:::data
            click RadarModel "https://github.com/atharvapanegai/api-radar-api/blob/master/models/radar.model.js"
            UserModel["user.model.js"]:::data
            click UserModel "https://github.com/atharvapanegai/api-radar-api/blob/master/models/user.model.js"
        end

        subgraph "Configuration"
            DBConfig["dbConfig.js"]:::app
            click DBConfig "https://github.com/atharvapanegai/api-radar-api/blob/master/config/dbConfig.js"
            Env["Environment\nVariables"]:::app
        end
    end

    %% Data & Messaging
    MongoDB["MongoDB"]:::data
    RedisCache["Redis Cache"]:::data
    KafkaBroker["Kafka Broker"]:::data
    SMTP["SMTP Email Provider"]:::external
    APIExternal["External APIs"]:::external

    %% Flows
    UI -->|"HTTP Request"| ExpressInit
    NPM -->|"HTTP Request"| ExpressInit
    ExpressInit --> RouteMW
    RouteMW --> Controllers
    Controllers --> Services
    Services --> Models
    Services --> MongoDB
    Services --> RedisCache
    Services --> KafkaBroker
    KafkaBroker -->|"consume incidents"| AlertSvc
    AlertSvc -->|"SMTP sendEmail"| SMTP
    APIExternal -->|"monitored APIs"| NPM

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0277BD,color:#0277BD;
    classDef app fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef data fill:#FFF3E0,stroke:#FF8F00,color:#EF6C00;
    classDef external fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A;
```
