# erofcon/rust-vision architecture

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

- Interactive diagram: https://gitdiagram.com/erofcon/rust-vision
- Repository: https://github.com/erofcon/rust-vision

## Overview

##### Project type and purpose
- This is a distributed, real-time video-processing pipeline built in Rust.
- It ingests video streams via GStreamer, runs object-detection and tracking (using ONNX Runtime), publishes tasks over RabbitMQ, processes them in worker pools, stores results in a database/S3, and exposes an HTTP API (and CLI) to query processed data.

##### File structure
- Top-level “crates/” folder holds reusable Rust libraries:
- common (shared data types, config, utilities)
- queue (RabbitMQ producer/consumer)
- gst-streaming & streaming (GStreamer-based ingest pipelines)
- detection, motion, inference (analytics libraries)
- storage (DB/S3 repository layer)
- api (HTTP server, handlers)
- “app/bin” and “cli/” are executables: the long-running worker service and command-line client.
- “config/” contains environment-specific TOML configs.
- “docker/” and docker-compose.yml orchestrate API, worker, RabbitMQ, DB, Nginx reverse-proxy.
- SQL migration scripts under root and migrations/ initialize PostgreSQL schemas.

##### README
- Describes real-time video capture, analytics, and tracking.
- Mentions GStreamer for capture, ORT for inference.
- Points to docs/api.md for API details.
- Warns project is under active development.

##### Detailing essentials
- Microservice or crate as its own component block.
- Environment configs feeding into services.
- External dependencies (e.g., camera feeds, S3).
- How Docker-Compose wires containers together on a virtual network.
- Protocols (AMQP, HTTP, SQL, gRPC if any).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Sources
    subgraph "Video Sources"
        Camera["Camera / File Inputs"]:::external
    end

    %% Ingestion Layer
    subgraph "Ingestion Services"
        Gst["gst-streaming crate"]:::front
        Strm["streaming crate"]:::front
    end

    %% Messaging
    RabbitMQ["RabbitMQ (AMQP)"]:::msg

    %% Processing
    subgraph "Worker Pool"
        Worker["Worker Service (app/bin)"]:::process
        Det["detection crate"]:::process
        Mot["motion crate"]:::process
        Inf["inference crate"]:::process
    end

    %% Storage
    subgraph "Storage Layer"
        DB["PostgreSQL"]:::storage
        S3["AWS S3"]:::storage
    end

    %% API & CLI
    subgraph "Interface Layer"
        Nginx["Nginx Reverse Proxy"]:::infra
        API["API Service (api crate)"]:::api
        CLI["CLI Client"]:::api
    end

    %% Config & Docs
    subgraph "Config & Docs"
        Config["Config (TOML)"]:::config
        Docs["API Docs (docs/api.md)"]:::config
    end

    %% Orchestration
    Infra["Docker & Docker-Compose"]:::infra

    %% Data flows
    Camera -->|video stream| Gst
    Camera -->|video stream| Strm
    Gst -->|AMQP publish| RabbitMQ
    Strm -->|AMQP publish| RabbitMQ

    RabbitMQ -->|AMQP consume| Worker
    Worker -->|uses| Det
    Worker -->|uses| Mot
    Worker -->|uses| Inf
    Worker -->|writes metadata| DB
    Worker -->|uploads frames| S3

    API -->|HTTP read/write| DB
    API -->|HTTP read/write| S3
    CLI -->|REST calls| API

    Nginx -->|routes/TLS| API
    Infra -->|network| Gst
    Infra -->|network| Strm
    Infra -->|network| RabbitMQ
    Infra -->|network| Worker
    Infra -->|network| DB
    Infra -->|network| API

    Config --> Gst
    Config --> Strm
    Config --> Worker
    Config --> API

    Docs -.-> API

    %% Click Events
    click Gst "https://github.com/erofcon/rust-vision/tree/develop/crates/gst-streaming"
    click Strm "https://github.com/erofcon/rust-vision/tree/develop/crates/streaming"
    click RabbitMQ "https://github.com/erofcon/rust-vision/tree/develop/crates/queue"
    click Worker "https://github.com/erofcon/rust-vision/tree/develop/app/bin"
    click Det "https://github.com/erofcon/rust-vision/tree/develop/crates/detection"
    click Mot "https://github.com/erofcon/rust-vision/tree/develop/crates/motion"
    click Inf "https://github.com/erofcon/rust-vision/tree/develop/inference"
    click DB "https://github.com/erofcon/rust-vision/tree/develop/crates/storage"
    click API "https://github.com/erofcon/rust-vision/tree/develop/crates/api"
    click CLI "https://github.com/erofcon/rust-vision/tree/develop/cli"
    click Config "https://github.com/erofcon/rust-vision/tree/develop/config"
    click Docs "https://github.com/erofcon/rust-vision/blob/develop/docs/api.md"
    click Infra "https://github.com/erofcon/rust-vision/blob/develop/docker/docker-compose.yml"

    %% Styles
    classDef external fill:#EFEFEF,stroke:#333,stroke-width:1px;
    classDef front fill:#D0E8FF,stroke:#0066CC,stroke-width:1px;
    classDef msg fill:#FFF4CC,stroke:#CC9900,stroke-width:1px;
    classDef process fill:#DFFFD0,stroke:#33CC33,stroke-width:1px;
    classDef storage fill:#FFE0B3,stroke:#E65C00,stroke-width:1px;
    classDef api fill:#F0D0FF,stroke:#9900CC,stroke-width:1px;
    classDef config fill:#E8E8E8,stroke:#666,stroke-width:1px;
    classDef infra fill:#FFD0D0,stroke:#CC0000,stroke-width:1px;
```
