# starlightconsole/comet architecture

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

- Interactive diagram: https://gitdiagram.com/starlightconsole/comet
- Repository: https://github.com/starlightconsole/comet

## Overview

##### Main Components

a) Core Components:
- CLI Interface (from cli.rs)
- Serial Communication Handler (from serial.rs and serial/device.rs)
- QEMU Integration (from serial/qemu.rs)
- Port Management (from port.rs)
- Styling System (from style.rs)

b) External Interfaces:
- Physical Serial Port Connection
- QEMU Virtual Serial Connection
- Starship Integration
- File System (for binary uploads)

**┌─ User Interface Layer ─────────────────────┐**
- CLI Interface               │
- ┬───────────────────────┘
- ↓
**┌─ Core Logic Layer ──────────────────────────────────────┐**
- ┌─────────────┐    ┌──────────────┐    ┌──────────┐   │
- Port     │←→│    Serial     │←→│  Style   │   │
- Manager    │    │   Handler    │    │ System  │   │
- ┘    └──────────────┘    └──────────┘   │
- ┬────────────────────────────┘
- ↓
**┌─ Device Layer ─────────────────────────────────────────┐**
- ┌────────────┐              ┌─────────────┐         │
- Physical   │              │    QEMU     │         │
- Serial    │              │ Integration │         │
- ┘              └─────────────┘         │
- ┘

##### Key Interactions to Highlight

a) Command Flow:
- Debug Mode: CLI → Serial Handler → Device
- Upload Mode: CLI → Serial Handler → Device + File System
- Test Mode: CLI → QEMU Integration → Virtual Serial

b) Data Flow:
- Serial Input: Device → Serial Handler → STDOUT
- Binary Upload: File System → Serial Handler → Device
- QEMU Communication: QEMU Process ↔ Serial Handler

##### Additional Elements

- Command types (Debug, Upload, Test)
- Data flow directions
- Component responsibilities
- Integration points with Starship
- STDERR vs STDOUT handling

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#2E86C1,stroke:#1B4F72,color:white
    classDef core fill:#2ECC71,stroke:#196F3D,color:white
    classDef device fill:#E67E22,stroke:#9C4D19,color:white
    classDef external fill:#8E44AD,stroke:#5B2C6F,color:white
    classDef dataflow fill:none,stroke:#FF7F50,color:black
    classDef optional stroke-dasharray: 5 5

    %% User Interface Layer
    subgraph UI
        CLI["CLI Interface"]
        EntryPoint["Application Entry Point"]
    end

    %% Core Logic Layer
    subgraph Core
        PortMgr["Port Manager"]
        SerialHandler["Serial Communication Handler"]
        StyleSystem["Styling System"]
        DeviceHandler["Device Handler"]
    end

    %% Device Layer
    subgraph Devices
        PhysicalSerial["Physical Serial Port"]
        QEMUInt["QEMU Integration"]
    end

    %% External Systems
    subgraph External
        FileSystem["File System"]
        Starship["Starship Integration"]
        STDOUT["STDOUT"]
        STDERR["STDERR"]
    end

    %% Relationships
    EntryPoint --> CLI
    CLI --> PortMgr
    CLI --> StyleSystem
    PortMgr --> SerialHandler
    SerialHandler --> DeviceHandler
    DeviceHandler --> PhysicalSerial
    DeviceHandler --> QEMUInt
    SerialHandler --> STDOUT
    SerialHandler --> STDERR
    SerialHandler --> FileSystem
    FileSystem --> Starship

    %% Styling
    class CLI,EntryPoint ui
    class PortMgr,SerialHandler,StyleSystem,DeviceHandler core
    class PhysicalSerial,QEMUInt device
    class FileSystem,Starship,STDOUT,STDERR external

    %% Click Events
    click CLI "https://github.com/starlightconsole/comet/blob/main/src/cli.rs"
    click EntryPoint "https://github.com/starlightconsole/comet/blob/main/src/main.rs"
    click PortMgr "https://github.com/starlightconsole/comet/blob/main/src/port.rs"
    click SerialHandler "https://github.com/starlightconsole/comet/blob/main/src/serial.rs"
    click StyleSystem "https://github.com/starlightconsole/comet/blob/main/src/style.rs"
    click DeviceHandler "https://github.com/starlightconsole/comet/blob/main/src/serial/device.rs"
    click QEMUInt "https://github.com/starlightconsole/comet/blob/main/src/serial/qemu.rs"

    %% Legend
    subgraph Legend
        UI_L["User Interface"]:::ui
        Core_L["Core Components"]:::core
        Device_L["Device Layer"]:::device
        External_L["External Systems"]:::external
    end
```
