# rakeshbb08/openpilot architecture

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

- Interactive diagram: https://gitdiagram.com/rakeshbb08/openpilot
- Repository: https://github.com/rakeshbb08/openpilot

## Overview

##### Main components
- Hardware Interface & Sensors:
– Components in the “system” folder such as system/camerad (camera data acquisition), system/hardware (hardware abstraction for both device and car platforms), and system/sensord (sensor reading and processing) stand out.
– The “panda” and “boardd” related directories handle CAN communication and safety. These modules interface directly with the car’s electrical and sensor systems.
- Perception and Processing Pipelines:
– The “common” library supports many functions (logging, conversions, parameters, and shared utilities) used across these modules.
- Car Interface & Safety:
– The “selfdrive/car” directory contains interface and controller code for various car makes and models. It implements the car-specific abstractions and safety rules.
– Additionally, “selfdrive/athena” and “selfdrive/boardd” include code for monitoring and safety-critical function.
- User Interface & Monitoring:
– “selfdrive/ui” contains both on‑road (real‑time driving display) and off‑road user interfaces built with QT/C++.
- Process Management and Infrastructure:
– “system/loggerd”, “system/logcatd”, “system/proclogd”, “system/qcomgpsd”, “system/ubloxd”, etc. show how lower level data logging, GPS handling, and inter‑process communications are organized.
– There is an orchestration of multiple processes (each presumably communicating via IPC or shared memory) that together provide a full pipeline from sensing to actuation.

##### Understand the relationships between components
– Sensors (cameras, CAN bus, IMU, etc.) are handled by low‑level system modules (camerad, sensord, hardware) and then their data is passed up to the processing pipelines.
– The “modeld” process ingests pre‑processed sensor data to perform deep learning inference for prediction and planning.
– The “controls” module takes inputs from modeld and/or sensor fusion modules (like locationd) to calculate actuator commands.
– The “car” components interface with specific vehicle hardware and safety layers to perform actuation.
– “loggerd” and “debug” modules collect execution and sensor data, sometimes providing data for monitoring, replay, or analysis (extensively supported by numerous tools in the “tools” directory).
– There are also external services (comma connect, data upload) that are part of the overall ecosystem even if not implemented as strictly “internal” modules.

##### Architectural patterns and design principles
– The system follows a modular, multi‑process design where each major functional block runs as an independent process communicating with others.
– Layers include a hardware abstraction/sensor layer, a perception/decision layer, and a control/actuation layer.
– Shared libraries ("common”) serve as the glue between components, while configuration, safety checks, and extensive testing (both unit and hardware‑in‑the‑loop tests) are integral parts of the design.
– The design accommodates multiple car makes/models via abstraction in “selfdrive/car” and the use of language bindings (e.g., Cython in some modules under “common” and “modeld”).

##### Elements
– Annotate interactions such as logging (to loggerd), safety data collection, and inter‑process communications among modules.
– Optionally, include “tools” and “third_party” libraries in a separate section to denote auxiliary functions (e.g., simulation, debugging, testing, and external libraries used to support various functionalities).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "User Interface & Monitoring"
        UI["UI (QT/C++)"]:::ui
    end

    subgraph "Perception, Planning & Control"
        Modeld["Modeld (DeepLearning_Inference - Python)"]:::processing
        Controls["Controls (Control_Algorithms - Python)"]:::processing
        Locationd["Locationd (Sensor_Fusion & Positioning - Python)"]:::processing
        Navd["Navd (Navigation & Mapping - Python)"]:::processing
        CarInterface["Car Interface (Car_Abstraction & Safety - Python)"]:::processing
        Athena["Athena (Safety-Critical_Monitoring - Python)"]:::processing
        Common["Common Libraries & Utilities"]:::common
    end

    subgraph "Hardware & Sensor Interfaces"
        Camerad["Camerad (Camera_Data_Acquisition - C/C++)"]:::hardware
        SensorProc["Sensor Processing (Sensor_Reading - C/C++)"]:::hardware
        HardwareAbs["Hardware Abstraction (Device & Car_Platforms - C/C++)"]:::hardware
        Boardd["Boardd (CAN_Interface & Safety - C/C++)"]:::hardware
        Panda["Panda (CAN & Safety)"]:::hardware
    end

    subgraph "Process Management & Infrastructure"
        Loggerd["Loggerd (Data_Logging)"]:::infra
        Logcatd["Logcatd (Log_Monitoring)"]:::infra
        Proclogd["Proclogd (Process_Logging)"]:::infra
        Manager["Manager (Process_Orchestration)"]:::infra
    end

    %% Data Flow from Hardware Layer to Perception
    Camerad -->|"sends_camera_data"| Modeld
    SensorProc -->|"sends_sensor_data"| Modeld
    HardwareAbs -->|"sends_hardware_info"| Modeld
    SensorProc -->|"provides_fusion_data"| Locationd

    %% Perception and Control Flow
    Modeld -->|"inference_results"| Controls
    Locationd -->|"fusion_results"| Controls
    Modeld -->|"planning_data"| Navd
    Navd -->|"navigation_info"| Controls
    Controls -->|"actuation_commands"| CarInterface
    Boardd -->|"CAN_signals"| CarInterface
    Panda -->|"safety_signals"| CarInterface
    Controls -->|"ui_updates"| UI
    Controls -->|"safety_monitor"| Athena

    %% Shared Library Connections (dashed lines)
    Modeld ---|"uses"| Common
    Controls ---|"uses"| Common
    Locationd ---|"uses"| Common
    Navd ---|"uses"| Common
    CarInterface ---|"uses"| Common

    %% Process Management Connections
    Modeld -->|"orchestrated_by"| Manager
    Controls -->|"orchestrated_by"| Manager
    UI -->|"orchestrated_by"| Manager

    Manager -->|"logs_to"| Loggerd
    Manager -->|"logs_to"| Logcatd
    Manager -->|"logs_to"| Proclogd

    %% Styling Classes
    classDef hardware fill:#aed9e0,stroke:#0077b6,stroke-width:2px;
    classDef processing fill:#bde0fe,stroke:#0077b6,stroke-width:2px;
    classDef ui fill:#ffddd2,stroke:#ff4500,stroke-width:2px;
    classDef infra fill:#d0f4de,stroke:#008000,stroke-width:2px;
    classDef common fill:#ffe066,stroke:#f48c06,stroke-width:2px;

    %% Click Events
    click Camerad "https://github.com/rakeshbb08/openpilot/tree/master/system/camerad"
    click SensorProc "https://github.com/rakeshbb08/openpilot/tree/master/system/sensord"
    click HardwareAbs "https://github.com/rakeshbb08/openpilot/tree/master/system/hardware"
    click Boardd "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/boardd"
    click Panda "https://github.com/rakeshbb08/openpilot/tree/master/panda"
    click Modeld "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/modeld"
    click Controls "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/controls"
    click Locationd "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/locationd"
    click Navd "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/navd"
    click Common "https://github.com/rakeshbb08/openpilot/tree/master/common"
    click CarInterface "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/car"
    click Athena "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/athena"
    click UI "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/ui"
    click Loggerd "https://github.com/rakeshbb08/openpilot/tree/master/system/loggerd"
    click Logcatd "https://github.com/rakeshbb08/openpilot/tree/master/system/logcatd"
    click Proclogd "https://github.com/rakeshbb08/openpilot/tree/master/system/proclogd"
    click Manager "https://github.com/rakeshbb08/openpilot/tree/master/selfdrive/manager"
```
