# bluerobotics/cockpit architecture

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

- Interactive diagram: https://gitdiagram.com/bluerobotics/cockpit
- Repository: https://github.com/bluerobotics/cockpit

## Overview

##### Project Type & Purpose
- This is a cross-platform, Electron-based ground control station for remote vehicles.
- It is a frontend-only application that connects to external backends (e.g., BlueOS, MAVLink routers, mavlink2rest, mavlink-camera-manager) to control and monitor various types of vehicles.
- The README and file structure indicate that it supports simulation (via docker-compose profiles) for different vehicle types – ArduSub, ArduCopter, ArduRover, and ArduPlane.

##### Main Components
A. Frontend / Application Layer:
- UI Components: Represent the Vue components from “src/components” and “src/views”. There’s clear separation into generic UI elements, specialized widgets (including mini-widgets, mission planning, and custom widget elements) that form the cockpit interface.
- Plugins and Composables: Show modules like “src/plugins” (using Vuetify, Webfontloader) and composables (e.g., drag, interactionDialog, settingsSyncer) that help manage application logic.
- State Management & Routing: Include “src/stores” (for various domains like vehicle, mission, etc.) and the routing configuration (“src/router”) that binds everything together.
- Styles: Note that “src/styles” is used for user interface styling.
- Public Assets: Illustrated in “public” (with images, manifests, etc.) for UI assets.

B. Electron / Native Application Layer:
- Electron Main & Preload: Highlight “src/electron/main.ts” and “src/electron/preload.ts” as the entry points when running as an Electron application.
- Electron Services: Include services for auto-updating, configuration (config-store), networking, and local storage found under “src/electron/services”.

C. Domain & Communication Libraries:
- Libraries in “src/libs” represent core functionalities including:
- Communication (e.g., MAVLink integration under “src/libs/communication/mavlink”).
- Connection management: “src/libs/connection” for managing websockets and external connections.
- Vehicle protocols and support for different vehicle types under “src/libs/vehicle”.
- External API & Telemetry: “src/libs/external-api” and “src/libs/external-telemetry”.
- Widgets, joystick handling, and signal processing are also supported by dedicated libs (e.g., “src/libs/joystick”, “src/libs/signal”).

D. External Systems & Backend Providers:
- BlueOS: acting as the complete backend when available.
- MAVLink routers (e.g., mavp2p or MAVLink Router).
- mavlink2rest: providing API access over websockets (noted as running on port 6040).
- Optionally, mavlink-camera-manager for video streaming (via WebRTC).
- Simulation Environment: Represent a simulation module (using docker-compose with profiles defined in sim.yml) that emulates different vehicle behaviors.

##### Relationships & Data Flow
- That the Electron layer (when used) encapsulates the UI and communicates with local services (auto-update, configuration, etc.).
- Communication between the Frontend’s network/connection libraries and the external backend services via WebSockets and HTTP calls.

##### Architectural Patterns / Design Principles
- Separation of Concerns: Divide UI rendering (Vue components), state management (stores across domains), and backend communication (libs for connection and protocol handling).
- Modularization: Components (widgets, dialogs, joysticks) and libraries are organized in domain-specific directories, signifying a modular design.
- Extensibility: The project supports custom widgets and config panels, showcasing points for enhancing or injecting new features.
- Integration via WebSockets & REST: Highlight that real-time data flows between the app and external systems using specific protocols (WebSockets for mavlink2rest and WebRTC for camera streaming).

##### Final Assembly

– The Frontend/UI layer (Vue components, composables, plugins, stores, router)
– The Electron integration layer (when applicable)
– The Domain & Communication libraries (providing abstraction for interactions with vehicles)
- Overlay the external systems: BlueOS, MAVLink routers, mavlink2rest and camera manager.
- For development and simulation: Represent the simulation environment (docker-compose defined in sim.yml) as a parallel external component that feeds data to the application.

- Clear labels for components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend / Application Layer
    subgraph "Frontend / Application Layer"
        User["User"]:::frontend
        ComponentsUI["Components (UI)"]:::frontend
        ViewsUI["Views (UI)"]:::frontend
        Plugins["Plugins"]:::frontend
        Composables["Composables"]:::frontend
        StateStores["State Stores"]:::frontend
        Routing["Routing"]:::frontend
        Styles["Styles"]:::frontend
        PublicAssets["Public Assets"]:::frontend
    end

    %% Electron / Native Application Layer
    subgraph "Electron / Native Application Layer"
        ElectronMain["Electron Main"]:::electron
        ElectronPreload["Electron Preload"]:::electron
        ElectronServices["Electron Services"]:::electron
    end

    %% Domain & Communication Libraries
    subgraph "Domain & Communication Libraries"
        MAVLinkComm["MAVLink Communication"]:::domain
        ConnMgmt["Connection Management"]:::domain
        VehicleProt["Vehicle Protocols"]:::domain
        ExternalAPI["External API"]:::domain
        ExternalTelem["External Telemetry"]:::domain
        Joystick["Joystick Handling"]:::domain
        SignalProc["Signal Processing"]:::domain
        BlueOSLib["BlueOS Integration"]:::domain
        Mavlink2REST["mavlink2rest Support"]:::domain
    end

    %% External Systems
    subgraph "External Systems"
        BlueOSBackend["BlueOS (Backend)"]:::external
        MAVLinkRouter["MAVLink Router"]:::external
        Mavlink2REST_Service["mavlink2rest Service"]:::external
        MavlinkCameraManager["mavlink-camera-manager"]:::external
    end

    %% Simulation Environment
    subgraph "Simulation Environment"
        SimEnv["Simulation Environment"]:::simulation
    end

    %% User Interactions in Frontend
    User -->|"interacts"| ComponentsUI
    ComponentsUI -->|"updates"| StateStores
    ViewsUI -->|"updates"| StateStores
    Plugins -->|"supports"| StateStores
    Composables -->|"supports"| StateStores
    StateStores -->|"routes"| Routing
    StateStores -->|"triggers"| ConnMgmt

    %% Electron Layer Communication
    ElectronMain -->|"calls"| ElectronServices
    ElectronPreload -->|"calls"| ElectronServices
    ElectronServices -->|"updates"| StateStores

    %% Domain Libraries Connections
    ConnMgmt -->|"communicates"| MAVLinkComm
    ConnMgmt -->|"manages"| VehicleProt
    ConnMgmt -->|"fetches"| ExternalAPI
    ConnMgmt -->|"fetches"| ExternalTelem
    ConnMgmt -->|"supports"| Mavlink2REST
    ConnMgmt -->|"integrates"| BlueOSLib
    VehicleProt -->|"integrates"| Joystick
    VehicleProt -->|"processes"| SignalProc

    %% Simulation feeds
    SimEnv -->|"sim feeds"| ConnMgmt

    %% Domain Libraries to External Systems
    ConnMgmt -->|"ws"| MAVLinkRouter
    Mavlink2REST -->|"ws"| Mavlink2REST_Service
    ConnMgmt -->|"WebRTC"| MavlinkCameraManager
    BlueOSLib -->|"REST"| BlueOSBackend

    %% Click Events for Frontend Components
    click ComponentsUI "https://github.com/bluerobotics/cockpit/tree/master/src/components"
    click ViewsUI "https://github.com/bluerobotics/cockpit/tree/master/src/views"
    click Plugins "https://github.com/bluerobotics/cockpit/tree/master/src/plugins"
    click Composables "https://github.com/bluerobotics/cockpit/tree/master/src/composables"
    click StateStores "https://github.com/bluerobotics/cockpit/tree/master/src/stores"
    click Routing "https://github.com/bluerobotics/cockpit/tree/master/src/router"
    click Styles "https://github.com/bluerobotics/cockpit/tree/master/src/styles"
    click PublicAssets "https://github.com/bluerobotics/cockpit/tree/master/public"

    %% Click Events for Electron Components
    click ElectronMain "https://github.com/bluerobotics/cockpit/blob/master/src/electron/main.ts"
    click ElectronPreload "https://github.com/bluerobotics/cockpit/blob/master/src/electron/preload.ts"
    click ElectronServices "https://github.com/bluerobotics/cockpit/tree/master/src/electron/services"

    %% Click Events for Domain & Communication Libraries
    click MAVLinkComm "https://github.com/bluerobotics/cockpit/blob/master/src/libs/communication/mavlink.ts"
    click ConnMgmt "https://github.com/bluerobotics/cockpit/tree/master/src/libs/connection"
    click VehicleProt "https://github.com/bluerobotics/cockpit/tree/master/src/libs/vehicle"
    click ExternalAPI "https://github.com/bluerobotics/cockpit/tree/master/src/libs/external-api"
    click ExternalTelem "https://github.com/bluerobotics/cockpit/tree/master/src/libs/external-telemetry"
    click Joystick "https://github.com/bluerobotics/cockpit/tree/master/src/libs/joystick"
    click SignalProc "https://github.com/bluerobotics/cockpit/blob/master/src/libs/signal.ts"
    click BlueOSLib "https://github.com/bluerobotics/cockpit/blob/master/src/libs/blueos.ts"
    click Mavlink2REST "https://github.com/bluerobotics/cockpit/tree/master/src/libs/vehicle/protocol/mavlink2rest"

    %% Click Event for Simulation Environment
    click SimEnv "https://github.com/bluerobotics/cockpit/blob/master/sim.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef electron fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef domain fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef simulation fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
