# monishkumarvr/ai_clone architecture

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

- Interactive diagram: https://gitdiagram.com/monishkumarvr/ai_clone
- Repository: https://github.com/monishkumarvr/ai_clone

## Overview

##### Project type and purpose
- This is an end-to-end, computer-vision microservices pipeline. It ingests CCTV video, runs inference on molten-metal processes, post-processes results, exports metrics, syncs data, and exposes an API for alerts and dashboards—all orchestrated via Docker Compose with no external-cloud dependencies.

##### File structure
- Top-level microservice folders:
- api_gateway/
- camera_ingest/
- inference/
- post_processing/
- metrics_exporter/
- offline_sync/
- Persistence/config:
- database/init.sql & db/init_db.sql → relational database schema
- gfs/ → shared file storage for raw video frames and intermediate artifacts
- Orchestration:
- docker-compose.yaml → composes all services, volumes, networks
- Each service has its own Dockerfile, requirements.txt, and main.py entrypoint.

##### README insights
- “Foundry Process Recognition System – CCTV Project”
- Purpose: detect, track, analyze molten-metal processes from CCTV footage
- End-to-end, private pipeline, generates SOP-violation alerts & production intelligence

##### Main components & interactions
a. camera_ingest
- Connects to CCTV streams or video files
- Extracts frames, drops them into GFS (shared volume) or message queue
b. inference
- Picks up frames from GFS
- Runs OpenVINO models (best_openvino_model, best_yolov11x_v6_openvino_model)
- Emits raw detections to GFS or a Kafka/RabbitMQ topic
c. post_processing
- Consumes detections
- Aggregates tracks, applies business rules (SOP violations)
- Writes structured events/alerts to the relational database
d. metrics_exporter
- Periodically scrapes service health & performance metrics
- Exposes Prometheus-compatible /metrics endpoint
e. offline_sync
- Periodically syncs database dumps, frames, model artifacts for offline analysis
f. api_gateway
- Fronts the pipeline: authenticates, routes requests to DB or metrics exporter
- Exposes RESTful endpoints for dashboards, alert queries, model metadata
g. database
- Stores schema for raw events, processed alerts, SOP violations, telemetry

##### Architectural patterns & design principles
- Microservices: each step isolated in its own container
- Event-driven pipeline: GFS or pub/sub for decoupling ingest → inference → post_processing
- Single-responsibility: each service does one thing end-to-end
- Orchestration with Docker Compose: shared network, named volumes, service dependencies
- Observability: metrics_exporter + potentially logs shipped to stdout
- Data persistence: relational DB for structured data; GFS for video/frames

##### Essential details to capture
- The multi-stage pipeline and how data moves from raw CCTV to insights
- Each microservice’s role, boundaries, and persistence mechanisms
- The orchestration and networking via docker-compose.yaml
- External touchpoints: CCTV stream sources and potential archive/offline storage

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External sources
    CCTV["CCTV Cameras"]:::external

    %% Ingest layer
    subgraph "Ingest"
        camera_ingest["camera_ingest"]:::service
    end

    %% Inference layer
    subgraph "Inference"
        inference["inference"]:::service
    end

    %% Post-Processing layer
    subgraph "Post-Processing"
        post_processing["post_processing"]:::service
    end

    %% Persistence layer
    subgraph "Persistence"
        GFS["Shared File Storage (GFS)"]:::folder
        DB["Relational Database"]:::db
    end

    %% API and Export layer
    subgraph "API/Export"
        api_gateway["api_gateway"]:::service
        metrics_exporter["metrics_exporter"]:::service
    end

    %% Offline Sync
    subgraph "Offline Sync"
        offline_sync["offline_sync"]:::service
    end

    %% External storage
    Archive["Offline Archive"]:::external

    %% Data flows
    CCTV -->|"RTSP/Video"| camera_ingest
    camera_ingest -->|"Extracted Frames"| GFS
    GFS -->|"Frames (OpenVINO Input)"| inference
    inference -->|"Detections"| GFS
    GFS -->|"RawDetections"| post_processing
    post_processing -->|"StructuredEvents"| DB
    metrics_exporter -->|"Scrape /metrics"| metrics_exporter
    DB -->|"SQL Queries"| api_gateway
    metrics_exporter -->|"Expose /metrics"| api_gateway

    %% Offline sync flows
    DB -->|"Dump Sync"| offline_sync
    GFS -->|"Artifact Sync"| offline_sync
    offline_sync -->|"Upload"| Archive

    %% Orchestration note (Docker Compose)
    subgraph "Orchestration"
        Compose["docker-compose.yaml"]:::compose
    end
    Compose --> camera_ingest
    Compose --> inference
    Compose --> post_processing
    Compose --> metrics_exporter
    Compose --> api_gateway
    Compose --> offline_sync
    Compose --> DB
    Compose --> GFS

    %% Click events
    click camera_ingest "https://github.com/monishkumarvr/ai_clone/tree/main/camera_ingest/"
    click inference "https://github.com/monishkumarvr/ai_clone/tree/main/inference/"
    click post_processing "https://github.com/monishkumarvr/ai_clone/tree/main/post_processing/"
    click metrics_exporter "https://github.com/monishkumarvr/ai_clone/tree/main/metrics_exporter/"
    click api_gateway "https://github.com/monishkumarvr/ai_clone/tree/main/api_gateway/"
    click offline_sync "https://github.com/monishkumarvr/ai_clone/tree/main/offline_sync/"
    click DB "https://github.com/monishkumarvr/ai_clone/tree/main/database/"
    click DB "https://github.com/monishkumarvr/ai_clone/tree/main/db/"
    click GFS "https://github.com/monishkumarvr/ai_clone/tree/main/gfs/"
    click Compose "https://github.com/monishkumarvr/ai_clone/blob/main/docker-compose.yaml"

    %% Styles
    classDef service fill:#4DA6FF,stroke:#333,stroke-width:1px,color:#fff
    classDef db fill:#FFCC00,stroke:#333,stroke-width:1px,color:#000
    classDef folder fill:#FF9966,stroke:#333,stroke-width:1px,color:#000
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px,color:#000
    classDef compose fill:#66CC66,stroke:#333,stroke-width:1px,color:#000
```
