# jafaral/openpilot architecture

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

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

## Overview

##### Main System Components

a) Hardware Layer:
- Device Hardware (comma two/three, EON Gold DevKit)
- Car Interface (via CAN bus)
- Sensors (cameras, IMU, GPS)

b) Core Services Layer:
- boardd (vehicle communication)
- sensord (sensor data handling)
- camerad (camera management)
- modeld (neural network processing)
- locationd (localization)
- controlsd (main control logic)

c) Application Layer:
- UI components
- Monitoring systems
- Logging and telemetry
- Update services

##### Component Relationships

a) Data Flow:
- CAN messages between car and boardd
- Sensor data flows to respective services
- Camera feeds to vision processing
- Control commands to vehicle

b) Process Communication:
- Real-time control messages
- Logging/telemetry data
- Configuration updates
- Status information

##### Specific Implementation Details

Specialized components:

a) Vehicle Integration:
- Car-specific interfaces (opendbc)
- Safety systems
- Hardware abstraction layer

b) Machine Learning:
- Model pipeline
- Training data flow
- Inference systems

**┌─ User Interface Layer ─────┐**
- UI  │  Monitoring  │ Maps │
- Application Layer ────────┤
- Controls │ Planning │ State│
- Services Layer ───────────┤
- Sensors │ Vision │ Comms  │
- Hardware Layer ───────────┤
- Device │ Car │ Peripherals│
- ┘

##### Critical Subsystems

Components:

a) Safety Systems:
- Panda safety model
- Driver monitoring
- Failsafe mechanisms

b) Control Systems:
- Lateral control
- Longitudinal control
- Planning and decision making

##### External Interfaces

Connections to:
- comma servers (telemetry/updates)
- Mobile apps
- Development tools
- Simulation environments

##### Deployment View

Include:
- Process distribution
- Hardware requirements
- Network topology
- Storage systems

Remember to maintain appropriate abstraction levels - show enough detail to understand the system architecture without getting lost in implementation specifics.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef hardware fill:#FFE6E6,stroke:#FF0000
    classDef core fill:#E6F3FF,stroke:#0066CC
    classDef app fill:#E6FFE6,stroke:#006600
    classDef ui fill:#FFFDE6,stroke:#CC9900
    classDef safety fill:#FFE6E6,stroke:#FF0000,stroke-width:3px
    classDef ml fill:#F0E6FF,stroke:#6600CC
    
    %% Hardware Layer
    subgraph Hardware
        DeviceHW[Device Hardware]
        CarInterface[Car Interface]
        Sensors[Sensors]
    end
    
    %% Core Services Layer
    subgraph CoreServices
        Boardd[boardd]:::core
        Sensord[sensord]:::core
        Camerad[camerad]:::core
        Modeld[modeld]:::core
        Locationd[locationd]:::core
        Controlsd[controlsd]:::core
    end
    
    %% Safety Systems
    subgraph SafetySystems
        PandaSafety[Panda Safety]:::safety
        DriverMon[Driver Monitoring]:::safety
        Failsafe[Failsafe Systems]:::safety
    end
    
    %% Control Systems
    subgraph ControlSystems
        LateralCtrl[Lateral Control]:::core
        LongitudinalCtrl[Longitudinal Control]:::core
        Planning[Planning]:::core
    end
    
    %% ML Systems
    subgraph MLSystems
        NNProcessing[Neural Networks]:::ml
        ModelPipeline[Model Pipeline]:::ml
    end
    
    %% Application Layer
    subgraph AppLayer
        UI[User Interface]:::ui
        Monitoring[Monitoring]:::app
        Logging[Logging]:::app
        Updates[Update Service]:::app
    end
    
    %% Relationships
    DeviceHW --> Boardd
    Sensors --> Sensord
    CarInterface --> Boardd
    
    Camerad --> Modeld
    Sensord --> Locationd
    Boardd --> Controlsd
    
    Modeld --> ControlSystems
    Locationd --> ControlSystems
    
    ControlSystems --> PandaSafety
    PandaSafety --> Boardd
    
    Monitoring --> DriverMon
    DriverMon --> Failsafe
    
    Controlsd --> LateralCtrl
    Controlsd --> LongitudinalCtrl
    
    NNProcessing --> ModelPipeline
    ModelPipeline --> Modeld
    
    %% Click events for component mapping
    click Boardd "https://github.com/jafaral/openpilot/tree/devel/selfdrive/boardd/"
    click Sensord "https://github.com/jafaral/openpilot/tree/devel/selfdrive/sensord/"
    click Camerad "https://github.com/jafaral/openpilot/tree/devel/selfdrive/camerad/"
    click Modeld "https://github.com/jafaral/openpilot/tree/devel/selfdrive/modeld/"
    click Locationd "https://github.com/jafaral/openpilot/tree/devel/selfdrive/locationd/"
    click Controlsd "https://github.com/jafaral/openpilot/blob/devel/selfdrive/controls/controlsd.py"
    click CarInterface "https://github.com/jafaral/openpilot/tree/devel/selfdrive/car/"
    click PandaSafety "https://github.com/jafaral/openpilot/tree/devel/panda/board/safety/"
    click NNProcessing "https://github.com/jafaral/openpilot/tree/devel/selfdrive/modeld/models/"
    click LateralCtrl "https://github.com/jafaral/openpilot/tree/devel/selfdrive/controls/lib/lateral_mpc/"
    click LongitudinalCtrl "https://github.com/jafaral/openpilot/tree/devel/selfdrive/controls/lib/longitudinal_mpc_lib/"
    click Planning "https://github.com/jafaral/openpilot/tree/devel/selfdrive/controls/lib/"
    click UI "https://github.com/jafaral/openpilot/tree/devel/selfdrive/ui/"
    click DriverMon "https://github.com/jafaral/openpilot/tree/devel/selfdrive/monitoring/"
    click Logging "https://github.com/jafaral/openpilot/tree/devel/selfdrive/loggerd/"
    click Sensors "https://github.com/jafaral/openpilot/tree/devel/selfdrive/sensord/sensors/"
    
    %% Style applications
    class DeviceHW,CarInterface,Sensors hardware
    class UI,Updates ui
    class Monitoring,Logging app
    class NNProcessing,ModelPipeline ml
```
