# hamdiboukamcha/yolo-v11-cpp-tensorrt architecture

> Architecture diagram of the GitHub repository hamdiboukamcha/yolo-v11-cpp-tensorrt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hamdiboukamcha/yolo-v11-cpp-tensorrt
- Repository: https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt

## Overview

##### Main Components
- Build & Configuration: The CMakeLists.txt at the root sets up the project, with dependencies to TensorRT, OpenCV, and CUDA.
- Core Application Logic:
- main.cpp acts as the main entry point.
- src/YOLOv11.cpp implements the object detection logic.
- src/preprocess.cu handles CUDA-based preprocessing.
- Header Files: The include/ directory contains the API declarations (including YOLOv11, CUDA utility functions, logging, preprocessing, etc.).
- Assets: The asset directory (along with images/videos) provides benchmark visuals and sample outputs.
- External Dependencies: TensorRT, CUDA Toolkit, and OpenCV are key technologies that power the performance and efficiency of the system.

##### Relationships and Interactions
- The main application (main.cpp) coordinates the overall workflow. It likely initializes the environment, loads the TensorRT engine, processes input (image/video), and routes data to the YOLOv11 implementation.
- The YOLOv11 component (in YOLOv11.cpp) encapsulates the object detection logic using a TensorRT engine which was built from an ONNX model.
- CUDA preprocessing (in preprocess.cu) prepares and optimizes images/videos for inference.

##### Architectural Patterns
- The design uses a modular approach where the preprocessing, inference, and conversion are separated into different components.
- A clear separation of concerns is evident between the interface (headers in include/) and the implementation (code in src/), as well as between CPU-side logic (C++) and GPU-accelerated tasks (CUDA).
- The project leverages dependency injection via CMake, ensuring that external libraries (TensorRT, CUDA, OpenCV) are correctly linked.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Configuration
    subgraph "Build & Configuration"
        build["CMakeLists.txt"]:::build
    end

    %% Application Entry Point
    subgraph "Application Entry"
        main["main.cpp"]:::entry
    end

    %% Headers & Utilities
    subgraph "Headers & Utilities"
        common["common.h"]:::utility
        cuda_utils["cuda_utils.h"]:::utility
        logging["logging.h"]:::utility
        macros["macros.h"]:::utility
    end

    %% Inference Pipeline
    subgraph "Inference Pipeline"
        subgraph "ONNX Conversion & Inference"
            conversion["ONNX Conversion Utility"]:::conversion
        end
        subgraph "Inference Core"
            yolo_h["YOLOv11.h"]:::inference
            yolo_cpp["YOLOv11.cpp"]:::inference
        end
        subgraph "CUDA Preprocessing"
            preprocess_h["preprocess.h"]:::cuda
            preprocess_cu["preprocess.cu"]:::cuda
        end
    end

    %% External Dependencies
    subgraph "External Dependencies"
        tensor["TensorRT"]:::external
        cuda_dep["CUDA Toolkit"]:::external
        opencv["OpenCV"]:::external
    end

    %% Assets
    subgraph "Assets"
        assets["Assets"]:::asset
    end

    %% Connections
    build --> main
    assets --> main
    main -->|"calls"| yolo_cpp
    main -->|"calls"| preprocess_cu
    conversion -->|"producesEngineFor"| yolo_cpp

    %% External dependency connections
    opencv --> main
    tensor --> yolo_cpp
    cuda_dep --> preprocess_cu

    %% Header/API usage connections
    common --- yolo_cpp
    cuda_utils --- preprocess_cu
    logging --- main
    macros --- yolo_cpp

    %% Internal grouping connections
    yolo_h --- yolo_cpp
    preprocess_h --- preprocess_cu

    %% Click Events
    click build "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/CMakeLists.txt"
    click main "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/main.cpp"
    click yolo_cpp "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/src/YOLOv11.cpp"
    click yolo_h "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/include/YOLOv11.h"
    click preprocess_cu "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/src/preprocess.cu"
    click preprocess_h "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/include/preprocess.h"
    click common "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/include/common.h"
    click cuda_utils "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/include/cuda_utils.h"
    click logging "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/include/logging.h"
    click macros "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/blob/master/include/macros.h"
    click assets "https://github.com/hamdiboukamcha/yolo-v11-cpp-tensorrt/tree/master/asset"

    %% Styles
    classDef build fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef entry fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef inference fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef cuda fill:#e6ccff,stroke:#333,stroke-width:2px;
    classDef conversion fill:#ffebcc,stroke:#333,stroke-width:2px;
    classDef external fill:#d9ead3,stroke:#333,stroke-width:2px;
    classDef utility fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef asset fill:#d0e0e3,stroke:#333,stroke-width:2px;

    class build build;
    class main entry;
    class yolo_cpp inference;
    class yolo_h inference;
    class preprocess_cu cuda;
    class preprocess_h cuda;
    class conversion conversion;
    class tensor external;
    class cuda_dep external;
    class opencv external;
    class common utility;
    class cuda_utils utility;
    class logging utility;
    class macros utility;
    class assets asset;
```
