# mm-x/sunnypilot-pc architecture

> Architecture diagram of the GitHub repository mm-x/sunnypilot-pc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mm-x/sunnypilot-pc
- Repository: https://github.com/mm-x/sunnypilot-pc

## Overview

##### Project type and purpose
- sunnypilot is a real-time embedded driver assistance system (fork of comma.ai’s openpilot).
- It runs on dedicated devices (comma three, C3X), interfacing with vehicle sensors/ECUs, performing perception, localization, planning, control, UI, logging, and cloud connectivity.

##### File structure
- Top‐level directories:
- system/ & openpilot/ daemons (camerad, sensord, loggerd, locationd, modeld, controlsd, selfdrived, etc.)
- selfdrive/ modules mirroring openpilot core (controls, locationd, modeld, UI)
- cereal/ messaging library (capnp-based pub/sub)
- common/ shared helpers, parameters, data structures
- panda/ hardware interface to vehicle CAN bus
- ui/ Qt/Python UI clients
- sunnypilot/ extensions (mads, mapd, sunnylink integration)
- release/, scripts/, tools/ supporting CI, build, simulation, profiling, tooling

##### README for additional insights
- Confirms sunnypilot’s purpose: ADAS fork of openpilot.
- References safety rules, supported hardware, installation branches.
- Mentions cloud upload via “comma servers” and sunnylink backup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        CAM["Camera Daemon (camerad)"]:::hardware
        RAD["Radar Daemon (radard)"]:::hardware
        SEN["Sensor Daemon (sensord)"]:::hardware
        GNSS["GNSS Daemon (ubloxd)"]:::hardware
        PAN["Panda CAN Interface"]:::hardware
    end

    %% Middleware
    subgraph "Messaging Bus"
        direction TB
        BUS["cereal Pub/Sub Bus"]:::middleware
    end

    %% Perception & Localization
    subgraph "Perception & Localization"
        direction TB
        LOC["IMU/GPS Fusion (locationd)"]:::perception
        MOD["Perception Neural Net Runner (modeld)"]:::perception
    end

    %% Planning & Control
    subgraph "Planning & Control"
        direction TB
        PLAN["Planning Daemon (plannerd)"]:::control
        CTRL["Control Daemon (controlsd)"]:::control
        DMON["Driver Monitoring (dmonitoringd)"]:::control
        SD["State & Alert Manager (selfdrived)"]:::control
    end

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        OFF["Off-road UI (Qt)"]:::ui
        ONR["On-road HUD"]:::ui
    end

    %% Logging & Cloud
    subgraph "Logging & Cloud"
        direction TB
        LOG["Data Logger (loggerd)"]:::logging
        MAN["Daemon Orchestrator (manager)"]:::logging
        ATH["Athena Client (athenad)"]:::logging
        CC["Comma Connect Cloud"]:::logging
    end

    %% Extensions
    subgraph "Sunnypilot Extensions"
        direction TB
        MADS["MADS"]:::extensions
        MAPD["Map Daemon (mapd)"]:::extensions
        SUNNY["Sunnylink Backup"]:::extensions
    end

    %% Data Flows
    CAM -->|Camera frames| BUS
    RAD -->|Radar data| BUS
    SEN -->|IMU/CAN/GPS| BUS
    GNSS -->|GPS data| BUS
    BUS -->|fused pose| LOC
    BUS -->|frames| MOD
    LOC -->|pose| CTRL
    MOD -->|perception| CTRL
    CTRL -->|trajectory| PLAN
    PLAN -->|planned path| CTRL
    CTRL -->|steering/throttle cmds| PAN
    BUS -->|topics| OFF
    BUS -->|topics| ONR
    BUS -->|all topics| LOG
    MAN -->|control messages| BUS
    ATH -->|health/pub| BUS
    LOG -->|uploads| CC
    ATH -->|uploads| CC
    SUNNY -->|backup data| CC
    MAN -->|updates| CC

    %% Click Events
    click SEN "https://github.com/mm-x/sunnypilot-pc/blob/master/system/sensord/sensord.py"
    click CAM "https://github.com/mm-x/sunnypilot-pc/blob/master/system/camerad/main.cc"
    click RAD "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/controls/radard.py"
    click GNSS "https://github.com/mm-x/sunnypilot-pc/blob/master/system/ubloxd/ubloxd.py"
    click LOC "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/locationd/locationd.py"
    click MOD "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/modeld/modeld.py"
    click CTRL "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/controls/controlsd.py"
    click PLAN "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/controls/plannerd.py"
    click DMON "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/monitoring/dmonitoringd.py"
    click SD "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/selfdrived/selfdrived.py"
    click LOG "https://github.com/mm-x/sunnypilot-pc/blob/master/system/loggerd/loggerd.cc"
    click MAN "https://github.com/mm-x/sunnypilot-pc/blob/master/system/manager/manager.py"
    click ATH "https://github.com/mm-x/sunnypilot-pc/blob/master/system/athena/athenad.py"
    click BUS "https://github.com/mm-x/sunnypilot-pc/tree/master/cereal/messaging/"
    click PAN "https://github.com/mm-x/sunnypilot-pc/blob/master/selfdrive/pandad/pandad.py"
    click MADS "https://github.com/mm-x/sunnypilot-pc/blob/master/sunnypilot/mads/mads.py"
    click MAPD "https://github.com/mm-x/sunnypilot-pc/blob/master/sunnypilot/mapd/mapd_manager.py"
    click SUNNY "https://github.com/mm-x/sunnypilot-pc/blob/master/sunnypilot/sunnylink/api.py"

    %% Styles
    classDef hardware fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef middleware fill:#a0c4ff,stroke:#333,stroke-width:1px
    classDef perception fill:#b9fbc0,stroke:#333,stroke-width:1px
    classDef control fill:#ffba08,stroke:#333,stroke-width:1px
    classDef ui fill:#cdb4db,stroke:#333,stroke-width:1px
    classDef logging fill:#ffdd99,stroke:#333,stroke-width:1px
    classDef extensions fill:#ffadad,stroke:#333,stroke-width:1px
```
