# mukandkrishna/eyecon-ai architecture

> Architecture diagram of the GitHub repository mukandkrishna/eyecon-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mukandkrishna/eyecon-ai
- Repository: https://github.com/mukandkrishna/eyecon-ai

## Overview

##### Project Type and Purpose
- This is a full-stack, microservice-augmented anomaly-detection platform, branded “Eyecon AI.”
- It consists of:
- A Next.js/TypeScript frontend for admin, super-admin, public demo, and auth flows.
- An Express-based Node.js backend exposing REST endpoints for anomalies, cameras, organizations, users, analytics, etc.
- A Kafka cluster + Python producer for ingesting streaming data (e.g., video or telemetry) into the system.
- A relational database (via `config/database.js`) and Firebase services (`config/firebase.js`) for auth/storage.

A. Frontend (Next.js App)
- Runs in Vercel or Docker.
- Uses NextAuth, React contexts, TailwindCSS, custom UI library, and calls backend API routes under `/api`.
B. Backend API (Node.js + Express)
- Dockerized, composed via `docker-compose.yml`.
- Layers:
- Routes (e.g. `routes/adminRoutes.js`, `publicRoutes.js`)
- Controllers (e.g. `anomalyController.js`)
- Services (e.g. `GroqService.js`)
- Models/ORM (e.g. Sequelize models under `models/`)
- Middlewares (auth, org-access)
- Connects to: relational DB, Firebase, and optionally a Kafka consumer.
C. Database
- A SQL database defined by `config/database.js` (Postgres/MySQL).
- Seeded via scripts under `scripts/`.
D. Firebase
- Used for auth, storage, real-time features via `config/firebase.js`.
E. Kafka Messaging
- Kafka-Server (broker + zookeeper) launched via its own `docker-compose.yml`.
- Kafka-Producer (Python) pushes messages into the Kafka topic(s).
- (Optional) A backend consumer microservice reads from Kafka and writes to DB or triggers anomaly analyses.
F. External/3rd-party Services
- Groq (or other AI/analytics engines) via `GroqService.js`.
- Firebase Auth/Storage.

##### Relationships and Data Flows
- Backend → Firebase: SDK/API calls.
- Producer → Kafka: Python producer publishes messages to Kafka topic(s).
- Backend → Groq/External AI: HTTP/gRPC calls for analytics.
- Frontend ←→ Firebase: (if real-time or storage is used directly by frontend).

##### Architectural Patterns & Design Principles
- Layered MVC in Backend: clear separation of routes, controllers, services, models, utils.
- “Monorepo” structure with distinct subfolders for backend, frontend, and Kafka services.
- Microservices/Message-driven ingestion (Kafka).
- Containerization: each major piece runs in its own Docker container, orchestrated via Docker Compose.
- Next.js App Router with API routes and server/client components.

##### Essential Elements Checklist
[ ] Clearly labeled components (e.g., “Next.js Frontend,” “Express API Server,” “Postgres DB,” “Kafka Broker”)
[ ] Callouts for key tech: Node.js, Express, Sequelize, Next.js, Kafka, Docker, Python, Firebase

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Next.js App)"
        direction TB
        NextApp["Next.js Frontend App"]:::frontend
        NextAuth["NextAuth Integration"]:::frontend
        FirebaseClient["Firebase Client Config"]:::frontend
        FirebaseService["Firebase Service"]:::frontend
        UIComponents["UI Components"]:::frontend
        Contexts["React Contexts"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API Server)"
        direction TB
        BackendServer["Express Backend API Server"]:::backend
        Routes["Routes Layer"]:::backend
        Controllers["Controllers Layer"]:::backend
        ServicesLayer["Services Layer"]:::backend
        ModelsLayer["Models/ORM Layer"]:::backend
        MiddlewaresLayer["Middlewares"]:::backend
        DBConfig["Database Config"]:::datastore
        BackendFirebase["Firebase Admin Config"]:::backend
        Scripts["DB Seed & Scripts"]:::datastore
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        PostgresDB["Postgres DB"]:::datastore
        FirebaseExternal["Firebase Auth/Storage"]:::external
    end

    %% Messaging Layer
    subgraph "Messaging (Kafka)"
        direction TB
        Producer["Kafka Producer"]:::messaging
        KafkaBroker["Kafka Broker"]:::messaging
        ConsumerOptional["Optional Kafka Consumer"]:::messaging
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GroqServiceExt["Groq AI Service"]:::external
    end

    %% Connections
    NextApp -->|HTTP/JSON| BackendServer
    NextApp -->|Realtime/Storage| FirebaseExternal
    BackendServer -->|JDBC/ORM| PostgresDB
    BackendServer -->|SDK/API| BackendFirebase
    BackendServer -->|HTTP/gRPC| GroqServiceExt
    Producer -.->|Kafka TCP| KafkaBroker
    KafkaBroker -.->|Kafka TCP| ConsumerOptional
    ConsumerOptional -->|JDBC/ORM| PostgresDB

    %% Click Events
    click NextApp "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Frontend/src/app"
    click NextAuth "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Frontend/src/app/api/auth/[...nextauth]/route.ts"
    click FirebaseClient "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Frontend/src/config/firebaseConfig.ts"
    click FirebaseService "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Frontend/src/services/firebaseService.ts"
    click UIComponents "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Frontend/src/components"
    click Contexts "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Frontend/src/context"
    click BackendServer "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Backend/server.js"
    click Routes "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Backend/routes"
    click Controllers "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Backend/controllers"
    click ServicesLayer "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Backend/services/GroqService.js"
    click ModelsLayer "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Backend/models"
    click MiddlewaresLayer "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Backend/middlewares"
    click DBConfig "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Backend/config/database.js"
    click BackendFirebase "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Backend/config/firebase.js"
    click Scripts "https://github.com/mukandkrishna/eyecon-ai/tree/main/Code/Backend/scripts"
    click Producer "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Kafka-Producer/producer.py"
    click KafkaBroker "https://github.com/mukandkrishna/eyecon-ai/blob/main/Code/Kafka-Server/docker-compose.yml"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#000,stroke-width:1px
    classDef backend fill:#D6FFD6,stroke:#000,stroke-width:1px
    classDef datastore fill:#FFE0B2,stroke:#000,stroke-width:1px
    classDef messaging fill:#E1BEE7,stroke:#000,stroke-width:1px
    classDef external fill:#CFD8DC,stroke:#000,stroke-width:1px
```
