# 31133498/eyeon-api architecture

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

- Interactive diagram: https://gitdiagram.com/31133498/eyeon-api
- Repository: https://github.com/31133498/eyeon-api

## Overview

##### Project Type & Purpose
- This is a monolithic backend REST API built with NestJS.
- It serves as the core of an AI-powered CCTV system (“Witness API”), responsible for ingesting camera data, running predictions, storing events, and exposing endpoints for a dashboard or other clients.

##### High-Level Architecture Components
a. Edge Component
- CCTV Cameras (external hardware or streaming service)
b. AI/Inference Layer
- An external or embedded ML service that analyzes camera feeds and emits “alerts.”
c. Backend API (NestJS monolith)
- Modules:
- Auth (JWT/local strategies, guards)
- Cameras (CRUD operations for camera metadata)
- Alerts (create/read/update alert events)
- Analytics (aggregate/query historical alert data)
- Users (user management)
- Dashboard (API endpoints for UI metrics)
- Cross-cutting: Filters (exception handling), Guards (authorization), Strategies (JWT/local)
d. Persistence
- Relational or NoSQL Database (entities for users, cameras, alerts)
e. External Services
- Notification/email/SMS service (to send real-time alerts)
f. Client UIs
- Web Dashboard or Mobile App consuming the API

##### Data & Control Flow
1. Cameras stream video →
2. AI service processes frames →
3. When a crime is predicted, AI “pushes” an alert to the Alerts API →
4. Alerts module writes to DB; Analytics module may consume or aggregate these →
5. Dashboard/UI polls or subscribes for new data via the Dashboard and Analytics endpoints →
6. Auth module secures all endpoints using JWT tokens

##### Architectural Patterns & Principles
- Layered architecture: Controllers → Services → Repositories/Entities
- Feature-based modularization: each module encapsulates related DTOs, controllers, services, and entities
- Cross-cutting concerns (auth, error handling) centralized under src/common
- Dependency injection (NestJS) to wire controllers/services/strategies

##### Technologies & Frameworks
- Node.js, NestJS framework
- TypeScript, decorators, DI container
- JWT for authentication, Passport strategies (local/jwt)
- TypeORM or another ORM (entities under each module)
- Environment configuration via .env, nest-cli, tsconfig

##### Key Points to Capture
- Feature modules and their boundaries
- Central role of Auth and Guards for security
- Data flow from cameras → AI → alerts → persistence → analytics/dashboard
- Integration points with external systems (AI inference, notifications)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    Cameras["CCTV Cameras"]:::external
    AISvc["AI/Inference Service"]:::externalGreen
    Notifications["Notification Service"]:::externalGreen
    ClientUI["Client Dashboard/UI"]:::external

    %% Backend API
    subgraph "Backend API"
        direction TB
        AuthMod["Auth Module"]:::backend
        CamerasMod["Cameras Module"]:::backend
        AlertsMod["Alerts Module"]:::backend
        AnalyticsMod["Analytics Module"]:::backend
        UsersMod["Users Module"]:::backend
        DashboardMod["Dashboard Module"]:::backend

        subgraph "Common (Cross-cutting)"
            direction TB
            JWTStrat["JWT Strategy"]:::auth
            LocalStrat["Local Strategy"]:::auth
            JWTGuard["JWT Auth Guard"]:::auth
            LocalGuard["Local Auth Guard"]:::auth
            ExFilter["Global Exception Filter"]:::auth
        end
    end

    %% Persistence
    Database["Database"]:::database

    %% Data & Control Flows
    Cameras --> AISvc
    AISvc --> AlertsMod
    AlertsMod --> Database
    AlertsMod --> Notifications

    ClientUI --> AuthMod
    AuthMod --> DashboardMod
    AuthMod --> AnalyticsMod
    DashboardMod --> Database
    AnalyticsMod --> Database

    %% Click Events for component mappings
    click AuthMod "https://github.com/31133498/eyeon-api/blob/main/src/auth/auth.module.ts"
    click CamerasMod "https://github.com/31133498/eyeon-api/blob/main/src/cameras/cameras.module.ts"
    click AlertsMod "https://github.com/31133498/eyeon-api/blob/main/src/alerts/alerts.module.ts"
    click AnalyticsMod "https://github.com/31133498/eyeon-api/blob/main/src/analytics/analytics.module.ts"
    click UsersMod "https://github.com/31133498/eyeon-api/blob/main/src/users/users.module.ts"
    click DashboardMod "https://github.com/31133498/eyeon-api/blob/main/src/dashboard/dashboard.module.ts"
    click JWTStrat "https://github.com/31133498/eyeon-api/blob/main/src/common/strategies/jwt.strategy.ts"
    click LocalStrat "https://github.com/31133498/eyeon-api/blob/main/src/common/strategies/local.strategy.ts"
    click JWTGuard "https://github.com/31133498/eyeon-api/blob/main/src/common/guards/jwt-auth.guard.ts"
    click LocalGuard "https://github.com/31133498/eyeon-api/blob/main/src/common/guards/local-auth.guard.ts"
    click ExFilter "https://github.com/31133498/eyeon-api/blob/main/src/common/filters/all-exceptions.filter.ts"

    %% Styles
    classDef backend fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef external fill:#eceff1,stroke:#90a4ae,color:#455a64
    classDef externalGreen fill:#c8e6c9,stroke:#388e3c,color:#1b5e20
    classDef auth fill:#ffcdd2,stroke:#e53935,color:#b71c1c
    classDef database fill:#ffe0b2,stroke:#fb8c00,color:#e65100
```
