# dragonpilot-community/dragonpilot architecture

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

- Interactive diagram: https://gitdiagram.com/dragonpilot-community/dragonpilot
- Repository: https://github.com/dragonpilot-community/dragonpilot

## Overview

- Hardware Interface & Embedded Controllers: This includes “panda” (the safety hardware board and CAN interface), “opendbc” (vehicle network definitions and DBC files), as well as parts in system/hardware and system/hardware/tici. They collectively manage the low-level interaction with vehicle sensors and actuators.
- Sensor Data and Messaging Pipeline: Use the “cereal” module as the data serialization and messaging library. Also include “msgq” (the messaging queue abstraction) which is used to pass messages between separate processes.
- Core Self-Driving Modules: Under “selfdrive”, you have modules that handle perception, planning, control, and car interfaces. Sections such as “selfdrive/car” (with various OEM-specific implementations), “selfdrive/controls” (for lateral/longitudinal control algorithms and MPC), and “modeld” (for model inference and processing) belong here.
- System Daemons and Management: The “system” directory includes several essential processes—“camerad” (camera streaming and sensor input processing), “loggerd” (data logging of the vehicle state, camera streams, etc.), “manager” (orchestrates processes), “sensord” (collects sensor information), “sentry” and others. Include these as separate components that run concurrently and communicate via the messaging pipeline.
- User Interface & Debugging: The “selfdrive/ui” and “tools/bodyteleop” provide on-road display and interactive tools. Also include “debug” modules that handle logging, testing utilities, and process monitoring.
- Testing & Simulation: There are extensive test folders (in “selfdrive/tests”, “panda/tests”, “dp_ext”, “dp_priv”, etc.) plus simulation and hardware-in-the-loop testing components. Mark these as supporting components that integrate with hardware and simulation environments.
- External & Third Party Components: The file tree contains large “third_party” directories (for acados, snpe, libyuv, etc.), which indicate the use of external libraries for control solvers (MPC), neural network inference, and multimedia processing. These should be represented as building blocks that the core modules (like “modeld” or “controls”) interface with.

##### Specify the interactions and data flows
- Data flows from the vehicle sensors (via hardware/panda) into system daemons (camerad, sensord) which preprocess the sensor images, CAN, GPS and IMU data.
- The messaging system (using cereal and msgq) passes processed data into the core “selfdrive” modules where planning, perception, control, and decision-making occur.
- Control commands and safety checks are routed back through the system manager to the hardware controllers (panda, opendbc) to actuate the vehicle.
- Logging and monitoring modules (loggerd, logcatd) collect data on performance and events for debugging, testing, and (optionally) data upload.
- The UI (selfdrive/ui) receives processed data to render driver alerts, camera views, and system status, while external teleop/debug tools further interact with the messaging system.

##### Architectural patterns/design principles
- Modular design with clear separation between hardware interfacing, high-level perception/control, system management, and the UI.
- Use of inter-process communication (IPC) via a common messaging format (cereal) that decouples the components.
- Safety-critical coding practices, evident in layered safety tests in panda and adherence to standards (ISO26262).
- Scalability and extensibility via the device-specific folders (e.g., dp_ext, dp_priv, car manufacturers’ subfolders) and third party libraries.

##### Relevant technologies, frameworks, and libraries
- C++ (for performance-critical modules such as sensor processing, and control algorithms found in “modeld”, “controls”, etc.)
- Python (for higher-level orchestration, UI, testing, and messaging glue code – seen in many __init__.py files and scripts)
- Custom messaging system (cereal), ZeroMQ-like infrastructure in “msgq”
- Embedded systems (panda firmware and hardware interfacing components), and integration with external tools like acados (MPC solver) and SNPE (neural network inference).

- Every major module (as outlined above) is present and their interdependencies are clearly illustrated.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Hardware Interface & Embedded Controllers
    subgraph "Hardware Interface & Embedded Controllers"
        HPanda["panda"]:::hardware
        HOp["opendbc"]:::hardware
        HTici["Embedded Hardware for Tici"]:::hardware
    end

    %% System Daemons and Management
    subgraph "System Daemons and Management"
        DCam["camerad"]:::daemon
        DLog["loggerd"]:::daemon
        DMan["manager"]:::daemon
        DSens["sensord"]:::daemon
        DSen["sentry"]:::daemon
    end

    %% Sensor Data and Messaging Pipeline
    subgraph "Sensor Data and Messaging Pipeline"
        MsgCereal["cereal"]:::messaging
        MsgQueue["msgq"]:::messaging
    end

    %% Core Self-Driving Modules
    subgraph "Core Self-Driving Modules"
        SDCar["selfdrive/car"]:::selfdrive
        SDControls["selfdrive/controls"]:::selfdrive
        SDModeld["selfdrive/modeld"]:::selfdrive
    end

    %% User Interface & Debugging
    subgraph "User Interface & Debugging"
        UI["selfdrive/ui"]:::ui
        Teleop["tools/bodyteleop"]:::ui
    end

    %% Testing & Simulation
    subgraph "Testing & Simulation"
        TTest1["selfdrive/car/tests"]:::testing
        TTest2["panda/tests"]:::testing
        TTest3["dp_ext"]:::testing
        TTest4["dp_priv"]:::testing
    end

    %% External & Third Party
    ThirdParty["third_party"]:::external

    %% Data flows from Hardware to System Daemons
    HPanda -->|"sensorData"| DCam
    HPanda -->|"sensorData"| DSens
    HOp -->|"vehicleDefs"| DMan
    HTici -->|"ticiSignals"| DCam
    HTici -->|"ticiSignals"| DSens

    %% System Daemons output data to Messaging Pipeline
    DCam -->|"dataFeed"| MsgCereal
    DSens -->|"dataFeed"| MsgCereal
    DLog -->|"logData"| MsgCereal
    DSen -->|"safetyAlerts"| MsgCereal
    DMan -->|"manageSignals"| MsgCereal

    %% Internal Messaging Serialization
    MsgCereal -->|"serialize"| MsgQueue

    %% Messaging Pipeline feeds Self-Driving Modules
    MsgQueue -->|"processData"| SDCar
    MsgQueue -->|"processData"| SDControls
    MsgQueue -->|"processData"| SDModeld

    %% Self-Driving Modules send control commands back to System Daemons
    SDControls -->|"controlCmds"| DMan
    SDCar -->|"controlCmds"| DMan
    SDModeld -->|"controlCmds"| DMan

    %% Self-Driving Modules deliver visual and status data to UI
    SDModeld -->|"renderUI"| UI
    SDCar -->|"status"| UI

    %% UI and Teleoperation interaction
    UI ---|"interaction"| Teleop

    %% External libraries interfacing with Self-Driving Modules
    ThirdParty -->|"externalLibs"| SDControls
    ThirdParty -->|"externalLibs"| SDModeld

    %% Self-Driving Modules feed data to Testing & Simulation
    SDCar -->|"testFeed"| TTest1
    SDControls -->|"testFeed"| TTest1
    SDModeld -->|"testFeed"| TTest1
    DLog -->|"testLogs"| TTest2

    %% Click Events
    click HPanda "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/panda/"
    click HOp "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/opendbc_repo/"
    click HTici "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/system/hardware/tici/"
    click DCam "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/system/camerad/"
    click DLog "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/system/loggerd/"
    click DMan "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/system/manager/"
    click DSens "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/system/sensord/"
    click DSen "https://github.com/dragonpilot-community/dragonpilot/blob/beta3/system/sentry.py"
    click MsgCereal "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/cereal/"
    click MsgQueue "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/msgq_repo/"
    click SDCar "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/selfdrive/car/"
    click SDControls "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/selfdrive/controls/"
    click SDModeld "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/selfdrive/modeld/"
    click UI "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/selfdrive/ui/"
    click Teleop "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/tools/bodyteleop/"
    click TTest1 "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/selfdrive/car/tests/"
    click TTest2 "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/panda/tests/"
    click TTest3 "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/dp_ext/"
    click TTest4 "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/dp_priv/"
    click ThirdParty "https://github.com/dragonpilot-community/dragonpilot/tree/beta3/third_party/"

    %% Styles
    classDef hardware fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef daemon fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef messaging fill:#F9E79F,stroke:#000,stroke-width:1px;
    classDef selfdrive fill:#FFC0CB,stroke:#000,stroke-width:1px;
    classDef ui fill:#E6E6FA,stroke:#000,stroke-width:1px;
    classDef testing fill:#FFE4B5,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
