# airtonmega/sistema-transmissao-imagens architecture

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

- Interactive diagram: https://gitdiagram.com/airtonmega/sistema-transmissao-imagens
- Repository: https://github.com/airtonmega/sistema-transmissao-imagens

## Overview

##### Project Type and Purpose
- This is a microservices-based inference system designed to detect people in video frames using YOLOv4/V8 models.
- The README indicates that the main role is to receive video frames from two clients (S2 and S3) and process them using FastAPI in S1 – which handles the detection logic using OpenCV – ensuring each person is counted only once.
- The project uses Docker to containerize its services and includes CI/CD workflows (visible in .github/workflows/ci-cd.yml).

##### File Structure
- Top-level, you have directories for different services: S1, S2, and S3.
- S1 contains the core inference service (FastAPI application) along with configuration (app/config.py), the main script (app/main.py), a detection service (app/services/detection_service.py) likely encapsulating the YOLO usage, and utility functions (app/utils/image_utils.py).
- S2 and S3 each have their own Dockerfile and a simpler structure with a main script under their respective /app directories. They are the clients sending video frames to S1.
- Additional files include docker-compose.yml for multi-container orchestration and CI/CD configuration within the .github directory.
- Configuration files (.env in S1) and requirements.txt files in each service further reveal dependency management and environmental setups.

##### README for Additional Insights
- The README clearly describes that S1 runs a FastAPI-based inference service using YOLO models, and outlines its key functionalities like processing via CPU, unique person counting, and API-based frame processing.
- It also explains that S2 and S3 are clients sending frames — each with a dedicated tracker ensuring unique person counts.
- Essential technologies include Python (>=3.8), FastAPI, OpenCV, Numpy, Pydantic, and Uvicorn.

a. Main Components:
- Inference Service (S1):
- Core application implementing FastAPI.
- Contains detection service, configuration modules, and image processing utilities.
- Responsible for receiving frames, running YOLO detection, and returning counted results.
- Client Services (S2 and S3):
- Each operates as an independent microservice/component that captures/sends video frame data to S1.
- Contains its own tracker logic to ensure that each detected person is processed only once.
- Orchestration / Containerization:
- Docker is employed for all services (S1, S2, S3) as indicated by the Dockerfiles.
- docker-compose.yml is used to orchestrate the containers, networking them together.
- CI/CD Pipeline:
- Indicated by the .github/workflows folder; ensures continuous integration/deployment for updates and testing.

b. Relationships and Interactions:
- S2 and S3 send video frame data via HTTP requests to S1’s FastAPI endpoints.
- S1 processes each incoming frame using its detection service (leveraging OpenCV and YOLOv4/V8), then sends back the response (person count).
- Docker containers are networked together via docker-compose, ensuring proper inter-service communication.

c. Architectural Patterns and Design Principles:
- Microservices architecture: Different services encapsulate their responsibilities (API service vs. client-side frame sending).
- Containerization: Use of Docker for isolating each service.
- Separation of concerns: S1 is solely responsible for inference and detection logic, while S2 and S3 handle frame acquisition and tracking.
- Use of external libraries and frameworks (FastAPI for service handling, OpenCV for image processing, and YOLO models for detection).

d. Relevant Technologies, Frameworks, and Libraries:
- FastAPI: For the inference service API (S1).
- OpenCV: For image loading and processing.
- YOLOv4/V8: The detection models integrated within S1.
- Docker & Docker Compose: For containerizing and orchestrating the services.
- Python libraries such as Pydantic and Numpy for data validation and processing.
- CI/CD tools integrated via GitHub Actions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker Orchestration
    subgraph "Docker Orchestration"
        DCompose["Docker Compose (Orchestration)"]:::docker
        S1Container["S1 Docker Container"]:::docker
        S2Container["S2 Docker Container"]:::docker
        S3Container["S3 Docker Container"]:::docker
    end

    %% Inference Service (S1)
    subgraph "Inference Service (S1)"
        FastAPI["FastAPI Application"]:::service
        subgraph "Configuration"
            AppConfig["App Config"]:::service
            EnvFile["Env File"]:::service
            GlobalConfig["Global Config"]:::service
        end
        YOLO["YOLO Detection Module"]:::service
        ImageUtil["Image Processing Utilities"]:::service
    end

    %% Client Services
    subgraph "Client Services"
        S2["Client Service – S2 (Frame Sender/Tracker)"]:::client
        S3["Client Service – S3 (Frame Sender/Tracker)"]:::client
    end

    %% CI/CD Pipeline
    CI_CD["CI/CD Pipeline (GitHub Actions)"]:::cicd

    %% Connections between Docker and Services
    DCompose --> S1Container
    DCompose --> S2Container
    DCompose --> S3Container
    S1Container --> FastAPI
    S2Container --> S2
    S3Container --> S3
    CI_CD --> DCompose

    %% Connections between Clients and Inference Service
    S2 ---|"SendsFrame"| FastAPI
    S3 ---|"SendsFrame"| FastAPI
    FastAPI ---|"ReturnsCount"| S2
    FastAPI ---|"ReturnsCount"| S3

    %% Internal Inference Service Dependencies
    FastAPI -->|"Uses"| YOLO
    FastAPI -->|"Uses"| ImageUtil

    %% Styling Classes
    classDef docker fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef service fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef client fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef cicd fill:#F9E79F,stroke:#B7950B,stroke-width:2px;

    %% Click Events
    click FastAPI "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S1/app/main.py"
    click AppConfig "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S1/app/config.py"
    click EnvFile "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S1/.env"
    click GlobalConfig "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S1/config.py"
    click YOLO "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S1/app/services/detection_service.py"
    click ImageUtil "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S1/app/utils/image_utils.py"
    click S2 "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S2/app/main.py"
    click S3 "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/S3/app/main.py"
    click S1Container "https://github.com/airtonmega/sistema-transmissao-imagens/tree/main/S1/Dockerfile"
    click S2Container "https://github.com/airtonmega/sistema-transmissao-imagens/tree/main/S2/Dockerfile"
    click S3Container "https://github.com/airtonmega/sistema-transmissao-imagens/tree/main/S3/Dockerfile"
    click DCompose "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/docker-compose.yml"
    click CI_CD "https://github.com/airtonmega/sistema-transmissao-imagens/blob/main/.github/workflows/ci-cd.yml"
```
