# sagarreddypatil/pspl_cms_gsesoftware architecture

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

- Interactive diagram: https://gitdiagram.com/sagarreddypatil/pspl_cms_gsesoftware
- Repository: https://github.com/sagarreddypatil/pspl_cms_gsesoftware

## Overview

##### Main Components
- CommandNet Components:
- cmdnet-v2-cli: A command-line interface utilizing the cmdnet library.
- cmdnet-v2-server: An HTTP API that uses the cmdnet library to expose command functionalities.
- SensorNet Components:
- sensornet-server-cpp: A C++ based server handling sensor data (with calibration, sensors, and UDP packet processing).
- sensornet-server: A TypeScript/Python-hybrid service providing data wiring, using WebSockets and interacting with InfluxDB.
- PSPieChart: A web-based mission control frontend application (built with React/TypeScript, Vite, Tailwind CSS) which integrates plugins for SensorNet and, eventually, CommandNet.
- PocketBase: A component for database/migration management, suggesting it may function as a backend for user or project data.
- Docker & CI/CD: Presence of Dockerfiles, docker-compose files, and GitHub workflows indicate containerization and continuous integration for deployment.

##### Out Relationships and Data Flow
- The Firmware subsystem runs on the embedded hardware, potentially sending commands and sensor readings.
- SensorNet servers (both C++ and Node/TypeScript based) handle UDP sensor data and route them via WebSockets, with InfluxDB (and possibly PocketBase) as the storage backend.
- The cmdnet components (CLI and HTTP API server) form the command/control side and expose operations over the network.
- PSPieChart interacts with the SensorNet services (and eventually with cmdnet-server) to display mission control information, charts, and provide user interaction.
- Docker orchestrates these services, each deployed in their containers, indicating clear “service boundaries”.

##### Architectural Patterns and Principles
- Microservices/Component-Based Architecture: Each major piece (cmdnet, sensornet, frontend, firmware) forms an independent service.
- Containerization: Use of Dockerfiles and docker-compose for managing dependencies and ensuring reproducibility.
- Separation of Concerns: Clear division between firmware, command control, sensor data routing, and web presentation.
- Integration through APIs and WebSockets: The backend services interact with frontends (PSPieChart) using standard web protocols.

##### Technologies and Frameworks
- Embedded/PlatformIO for firmware.
- Python (for cmdnet and its server, using Python 3.10+).
- Node.js and TypeScript in both the PSPieChart frontend and sensornet-server.
- Docker and docker-compose for containerization.
- InfluxDB (for time-series sensor data) and PocketBase (for additional data management).
- WebSockets for real-time data communication.

- Data flow from the firmware to the SensorNet servers.
- Command flows between cmdnet CLI and cmdnet server.
- Interaction between sensor servers and the frontend over WebSockets/HTTP.
- Docker orchestration controlling service startup across containers.
- Hardware/embedded components.
- Backend services (Python, C++ and Node services).
- Frontend/UI components.
- Infrastructure (Docker, InfluxDB, CI/CD pipelines).

##### Additional Clarifications
- To include any integration points with databases (InfluxDB, PocketBase) that are implied by migration files and related Docker settings.
- Recognize that while PSPieChart is the primary UI for the mission control software, it integrates plugins from SensorNet (and eventually cmdnet) – ensure this coupling is clearly depicted.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Embedded/Firmware Layer
    subgraph "Embedded/Firmware Layer"
        Firmware["Firmware (Bang Bang Boom Box/Power_System_Controller_firmware)"]:::firmware
    end

    %% Backend Services Layer
    subgraph "Backend Services Layer"
        CLI["CommandNet CLI"]:::backend
        CmdServer["CommandNet Server"]:::backend
        CmdServerDocker["Server Dockerfile"]:::backend
        SensorNetCpp["SensorNet (C++ Service)"]:::backend
        SensorNetNode["SensorNet (Node/TS Service)"]:::backend
        PocketBase["PocketBase"]:::backend
    end

    %% Frontend/UI Layer
    subgraph "Frontend/UI Layer"
        PSPieChart["PSPieChart - Frontend"]:::frontend
    end

    %% Integration/Orchestration
    subgraph "Integration/Orchestration"
        DockerCI["Docker & CI/CD"]:::infrastructure
        GitHubActions["GitHub Actions (.github/workflows/build.yml)"]:::infrastructure
        DockerCompose["Docker Compose (docker-compose.yml)"]:::infrastructure
        DockerComposeDev["Docker Compose Dev (docker-compose.dev.yml)"]:::infrastructure
    end

    %% Data and Command Flows
    Firmware -->|"UDP_Sensor_Data"| SensorNetCpp
    Firmware -->|"Sensor_Data"| SensorNetNode

    CLI -->|"CommandDispatch"| CmdServer
    CmdServerDocker ---|"Docker_Config"| CmdServer

    CmdServer -->|"HTTP_API_Call"| PSPieChart
    SensorNetNode -->|"WebSocket_Update"| PSPieChart
    SensorNetNode -->|"Data_Storage"| PocketBase

    %% Integration orchestration arrows
    DockerCI -->|"Orchestrates"| CLI
    DockerCI -->|"Orchestrates"| CmdServer
    DockerCI -->|"Orchestrates"| SensorNetCpp
    DockerCI -->|"Orchestrates"| SensorNetNode
    DockerCI -->|"Orchestrates"| PocketBase
    DockerCI -->|"Orchestrates"| PSPieChart

    GitHubActions -->|"Triggers"| DockerCI
    DockerCompose -->|"Configures"| DockerCI
    DockerComposeDev -->|"Configures"| DockerCI

    %% Click Events
    click Firmware "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/tree/main/Bang Bang Boom Box/Power_System_Controller_firmware"
    click CLI "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/blob/main/cmdnet-v2-cli/main.py"
    click CmdServer "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/blob/main/cmdnet-v2-server/app.py"
    click CmdServerDocker "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/tree/main/cmdnet-v2-server/Dockerfile"
    click SensorNetCpp "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/tree/main/sensornet-server-cpp/src"
    click SensorNetNode "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/blob/main/sensornet-server/src/index.ts"
    click PSPieChart "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/tree/main/pspiechart/src"
    click PocketBase "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/tree/main/pocketbase"
    click GitHubActions "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/blob/main/.github/workflows/build.yml"
    click DockerCompose "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/blob/main/docker-compose.yml"
    click DockerComposeDev "https://github.com/sagarreddypatil/pspl_cms_gsesoftware/blob/main/docker-compose.dev.yml"

    %% Styles
    classDef firmware fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef backend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef frontend fill:#fff0b3,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#d9d2e9,stroke:#333,stroke-width:2px;
```
