# gt-space/luna architecture

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

- Interactive diagram: https://gitdiagram.com/gt-space/luna
- Repository: https://github.com/gt-space/luna

## Overview

##### Main System Components

a) Flight Control System
- Switchboard system (commander, worker, defibrillator, lifetime)
- State management and handlers

b) Hardware Interface Layer
- 'ahrs' (Attitude and Heading Reference System)
- 'sam' (Sensor and Actuator Management)
- 'tel' (Telemetry system with SX1280 radio interface)

c) Ground Control System
- 'gui' component with its major subsystems:
- Sensor monitoring
- Valve control
- Sequence management
- Plotting/visualization
- AVI launcher

d) Data Management
- 'servo' component (database and API server)
- Database migrations and routes

##### Component Relationships

a) Data Flow
- Telemetry data flow from hardware sensors → flight control → ground control
- Command flow from ground control → flight control → hardware actuators
- Database interactions between servo and other components

b) Communication Protocols
- Common communication interfaces defined in the 'common' crate
- Different message types (flight, gui, sam)

##### Specific Implementation Details

Technical details:

a) Frontend (GUI):
- Tauri-based desktop application
- React/TypeScript implementation
- Multiple specialized views (sensors, sequences, valves, etc.)

b) Backend Services:
- Rust-based implementation
- RESTful API endpoints
- Database migrations and management

c) Hardware Communication:
- GPIO interfaces
- SX1280 radio communication
- ADC and sensor interfaces

##### Critical Flows to Highlight

Key interactions:

- Command and control flow from GUI to flight systems
- Telemetry data flow from sensors to display
- State management and synchronization
- Emergency/failure handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#ff9966,stroke:#333,stroke-width:2px
    classDef backend fill:#6699ff,stroke:#333,stroke-width:2px
    classDef hardware fill:#99cc66,stroke:#333,stroke-width:2px
    classDef database fill:#cc99ff,stroke:#333,stroke-width:2px
    classDef communication fill:#ffff99,stroke:#333,stroke-width:2px

    %% Ground Control Interface Layer
    subgraph GUI
        GC["GUI Core"]:::frontend
        SI["Sensor Interface"]:::frontend
        SQI["Sequence Interface"]:::frontend
        VC["Valve Control"]:::frontend
        SM["System Monitor"]:::frontend
        PI["Plotting Interface"]:::frontend
        TM["Task Management"]:::frontend
    end

    %% Flight Control System Layer
    subgraph FCS
        FC["Flight Core"]:::backend
        SB["Switchboard"]:::backend
        ST["State Management"]:::backend
        FH["Flight Handler"]:::backend
    end

    %% Hardware Interface Layer
    subgraph Hardware
        AHRS["AHRS System"]:::hardware
        SAM["SAM System"]:::hardware
        TEL["Telemetry System"]:::hardware
        SX["SX1280 Radio"]:::hardware
    end

    %% Data Management Layer
    subgraph Data
        SV["Servo Core"]:::database
        DB[(Database)]:::database
        API["API Routes"]:::backend
        MIG["Migrations"]:::database
    end

    %% Communication Layer
    subgraph Comm
        CP["Common Protocols"]:::communication
        FC_COMM["Flight Comm"]:::communication
        GUI_COMM["GUI Comm"]:::communication
        SAM_COMM["SAM Comm"]:::communication
        SEQ["Sequence Management"]:::communication
    end

    %% Hardware GPIO Layer
    subgraph GPIO
        AHRS_GPIO["AHRS GPIO"]:::hardware
        SAM_GPIO["SAM GPIO"]:::hardware
        TEL_GPIO["TEL GPIO"]:::hardware
    end

    %% Relationships
    GC --> GUI_COMM
    SI --> GUI_COMM
    SQI --> SEQ
    GUI_COMM --> FC_COMM
    FC_COMM --> FC
    FC --> SB
    SB --> ST
    ST --> FH
    FH --> AHRS
    FH --> SAM
    FH --> TEL
    AHRS --> AHRS_GPIO
    SAM --> SAM_GPIO
    TEL --> TEL_GPIO
    TEL --> SX
    API --> DB
    SV --> DB
    MIG --> DB

    %% Click Events
    click GC "https://github.com/gt-space/luna/tree/main/gui/src/"
    click SI "https://github.com/gt-space/luna/tree/main/gui/src/sensors/"
    click SQI "https://github.com/gt-space/luna/tree/main/gui/src/sequences/"
    click VC "https://github.com/gt-space/luna/tree/main/gui/src/valves/"
    click SM "https://github.com/gt-space/luna/tree/main/gui/src/system/"
    click PI "https://github.com/gt-space/luna/tree/main/gui/src/plotter/"
    click TM "https://github.com/gt-space/luna/tree/main/gui/src/task-bar/"
    click FC "https://github.com/gt-space/luna/blob/main/flight/src/main.rs"
    click SB "https://github.com/gt-space/luna/tree/main/flight/src/switchboard/"
    click ST "https://github.com/gt-space/luna/blob/main/flight/src/state.rs"
    click FH "https://github.com/gt-space/luna/blob/main/flight/src/handler.rs"
    click AHRS "https://github.com/gt-space/luna/tree/main/ahrs/src/"
    click SAM "https://github.com/gt-space/luna/tree/main/sam/src/"
    click TEL "https://github.com/gt-space/luna/tree/main/tel/src/"
    click SX "https://github.com/gt-space/luna/tree/main/tel/src/sx1280/"
    click SV "https://github.com/gt-space/luna/tree/main/servo/src/"
    click DB "https://github.com/gt-space/luna/blob/main/servo/src/server/database.rs"
    click API "https://github.com/gt-space/luna/tree/main/servo/src/server/routes/"
    click MIG "https://github.com/gt-space/luna/tree/main/servo/src/migrations/"
    click CP "https://github.com/gt-space/luna/tree/main/common/src/comm/"
    click FC_COMM "https://github.com/gt-space/luna/blob/main/common/src/comm/flight.rs"
    click GUI_COMM "https://github.com/gt-space/luna/blob/main/common/src/comm/gui.rs"
    click SAM_COMM "https://github.com/gt-space/luna/blob/main/common/src/comm/sam.rs"
    click SEQ "https://github.com/gt-space/luna/tree/main/common/src/sequence/"
    click AHRS_GPIO "https://github.com/gt-space/luna/tree/main/ahrs/src/gpio/"
    click SAM_GPIO "https://github.com/gt-space/luna/blob/main/sam/src/gpio.rs"
    click TEL_GPIO "https://github.com/gt-space/luna/tree/main/tel/src/gpio/"
```
