# karlcswanson/spectrum-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/karlcswanson/spectrum-frontend
- Repository: https://github.com/karlcswanson/spectrum-frontend

## Overview

##### Project Type & Purpose
- This is the frontend portion of a larger multi-component system called “micboard spectrum.” In our specific project ("spectrum-frontend") the main focus is on rendering and interacting with spectrum scan data in real time using Vue3.
- The README explains that this frontend interfaces with data coming from remote scan units (running “spectrum-capture” in a soapySDR container) via an MQTT broker. The overall system supports both distributed and standalone configurations.

##### File Structure Insights
- The file tree confirms it is a Vue3 SPA:
- Files like App.vue, main.ts, and the router and stores directories indicate use of state management, views routing, and component-based UI.
- Assets such as CSS files in the assets folder help define styling, while components (e.g., SpectrumPlot.vue) and views (e.g., HomeView.vue) represent UI segments.
- Configuration files (package.json, tsconfig.*, vite.config.ts) indicate standard modern JavaScript/TypeScript development practices.

##### Key Components
- Client UI (spectrum-frontend): Represented by the Vue3 SPA, including its subcomponents:
- Main entry (App.vue, main.ts)
- Router (managing user navigation)
- State management (stores directory)
- Key UI components (e.g., SpectrumPlot.vue)
- Data Ingestion Layer:
- MQTT Broker (using Eclipse Mosquitto as noted in the README)
- WebSocket interface: The frontend connects using secure WebSocket (wss) connections which are proxied to the MQTT broker.
- Remote Scan Units:
- spectrum-capture running in soapySDR-containers that collect and stream RF data via MQTT.
- Web Server (Caddy in production): Hosts the spectrum-frontend and proxies the WebSocket connections.

##### Architectural Relationships & Data Flow
- In the Distributed System:
- Multiple remote scan units (each with a soapySDR-container running spectrum-capture) capture RF spectrum data.
- These units stream power level data via MQTT to the central MQTT broker.
- The central server hosts a webserver (Caddy) that delivers the spectrum-frontend to users.
- The frontend establishes a WebSocket (wss) connection (proxied to the MQTT broker) to receive and display live data.
- In the Standalone Setup:
- All the above components run on a single machine, eliminating the central server role but keeping the same internals.

##### Architectural Patterns & Technologies
- Use a layered approach: presentation layer (Vue3 components), connection layer (WebSockets bridging to the MQTT broker), and data acquisition layer (spectrum-capture in containerized scan units).
- The separation of concerns is clear: the frontend is solely responsible for visualization and user interaction, while the backend components handle data gathering and messaging.
- Technologies involved: Vue3, TypeScript, MQTT (Eclipse Mosquitto), Caddy web server, and containerized scanning (soapySDR-container).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Services
    subgraph "Backend Services"
        RemoteScan["Remote Scan Units (spectrum-capture in soapySDR container)"]:::container
        MQBroker["MQTT Broker (Eclipse Mosquitto)"]:::broker
        WebServer["Web Server (Caddy)"]:::server
    end

    %% Frontend (Vue3 SPA)
    subgraph "Frontend (Vue3 SPA)"
        MainEntry["Main Entry (main.ts)"]:::frontend
        AppVue["App Container (App.vue)"]:::frontend
        Router["Router (Navigation)"]:::router
        Stores["State Management (Stores)"]:::stores
        HomeView["Home View (HomeView.vue)"]:::view
        SpectrumPlot["Spectrum Data Display (SpectrumPlot.vue)"]:::component
        WebSocket["WebSocket Interface"]:::websocket
    end

    %% Data Flow between Backend Components
    RemoteScan -->|"publishes"| MQBroker
    MQBroker -->|"forwards"| WebServer
    WebServer -->|"proxies-wss-to"| WebSocket

    %% Frontend Internal Interactions
    MainEntry -->|"loads"| AppVue
    AppVue -->|"uses"| Router
    AppVue -->|"manages"| Stores
    AppVue -->|"renders"| HomeView
    HomeView -->|"includes"| SpectrumPlot
    AppVue -->|"establishes"| WebSocket

    %% Annotation for Deployment Modes
    Note1["Note: System can be deployed in Distributed or Standalone mode."]:::note
    WebServer --- Note1

    %% Click Events
    click MainEntry "https://github.com/karlcswanson/spectrum-frontend/blob/main/src/main.ts"
    click AppVue "https://github.com/karlcswanson/spectrum-frontend/blob/main/src/App.vue"
    click Router "https://github.com/karlcswanson/spectrum-frontend/blob/main/src/router/index.ts"
    click Stores "https://github.com/karlcswanson/spectrum-frontend/tree/main/src/stores"
    click SpectrumPlot "https://github.com/karlcswanson/spectrum-frontend/blob/main/src/components/SpectrumPlot.vue"
    click HomeView "https://github.com/karlcswanson/spectrum-frontend/blob/main/src/views/HomeView.vue"
    click WebSocket "https://github.com/karlcswanson/spectrum-frontend/blob/main/src/socks.ts"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef router fill:#a8d5e2,stroke:#333,stroke-width:2px;
    classDef stores fill:#dcedc8,stroke:#333,stroke-width:2px;
    classDef component fill:#fff9c4,stroke:#333,stroke-width:2px;
    classDef view fill:#ffe0b2,stroke:#333,stroke-width:2px;
    classDef websocket fill:#e1bee7,stroke:#333,stroke-width:2px;
    classDef broker fill:#ffcdd2,stroke:#333,stroke-width:2px;
    classDef server fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef container fill:#fff9c4,stroke:#333,stroke-width:2px;
    classDef note fill:#e0e0e0,stroke:#333,stroke-width:2px,stroke-dasharray:5 5;
```
