# trcio/mpanel architecture

> Architecture diagram of the GitHub repository trcio/mpanel, 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/trcio/mpanel
- Repository: https://github.com/trcio/mpanel

## Overview

##### Project Type and Purpose
- mPanel is a desktop application, built in C# on the .NET framework, that provides an interface for controlling a 15x15 LED matrix. It interacts with an Arduino-based hardware (with firmware in Arduino/matrix) via serial communication.
- The software is modular, offering various “Actions” (such as Animator, Basic, Snake, Pong, Tetris, Visualizer, Weather, etc.) that send display “frames” to the LED matrix when activated.
- The README and file tree emphasize both the UI-heavy application (various Windows Forms) and the embedded Arduino firmware.

##### Analyzing the File Structure
- Top-Level Separation: Notice the two major folders – “Arduino” (firmware/code for the Arduino nano clone) and “mPanel” (the main desktop control application).
- Within mPanel:
- The “Actions” directory groups different modules each offering a distinct interactive feature (Animator, Snake, Pong, etc.).
- The “Controls” directory indicates reusable UI components.
- The “Matrix” directory has files like Frame.cs, GuiPanel.cs, and SerialPanel.cs which suggest they manage the LED matrix display and hardware communication.
- The main entry point (Program.cs) and configuration files (App.config, .csproj, etc.) round out the application.
- In the Arduino folder, the firmware shows files (matrix.ino, serial.cpp/h, standby.cpp/h) intended for controlling the LED matrix hardware.

a. Main Components:
- mPanel Desktop Application:
- UI Layer: Comprising the ContainerForm and dedicated Action forms (Animator, Basic, Dots, Pong, Scripter, Snake, Tetris, Visualizer, Weather, Preview, etc.).
- Business Logic: Each action’s logic module that interprets user inputs and translates them into LED matrix frames (for example, the animation workflow in Animator, game logic in Snake/Pong/Tetris).
- Communication/Abstraction Layer: Dedicated classes and modules in the Matrix directory which manage the creation and transmission of frames via serial (e.g., SerialPanel.cs, Frame.cs).
- Arduino Firmware:
- Firmware Application: The code in Arduino/matrix (matrix.ino plus supporting .cpp/.h files) that is responsible for receiving frame data from the desktop application and handling LED control.
- Serial Communication Handlers: Abstracted in files like serial.cpp/h and standby mode support.

b. Relationships and Interactions:
- The Desktop UI (Forms from mPanel/Actions and ContainerForm) interacts with the Business Logic which processes user interactions.
- The Business Logic invokes the Communication Layer to send updated frame data.
- The Communication Layer establishes a serial connection (or a simulated GUI-only connection) with the Arduino device.
- Data Flow: User interacts with a selected Action (e.g., Animator) → UI captures commands → Business logic composes display frames → Communication layer serializes and transmits these frames → Arduino firmware receives and renders frames on the LED matrix.
- Additionally, some actions (like the Visualizer) pull data from external libraries (such as CSCore for sound input) and process that data through the same pipeline.

c. Architectural Patterns & Design Principles:
- The design follows a hybrid layered architecture with a strong separation between UI and hardware interaction.
- Modular design in the “Actions” directory ensures that each feature is isolated (adhering to separation of concerns).
- Use of helper libraries (e.g., for serial communication, noise generation, and the external CSCore library) indicate a plug-and-play extensibility approach.

d. Technologies, Frameworks, and Libraries:
- Platform: C#/.NET (likely Windows Forms) – illustrate this in your UI component.
- Hardware Communication: Serial interaction between the PC (running mPanel) and the Arduino nano clone.
- Arduino: Arduino IDE firmware (using .ino, .cpp/.h).

## Diagram (Mermaid)

```mermaid
graph TD
    %% mPanel Desktop Application
    subgraph "mPanel Desktop Application"
        A["Program Entry"]
        B["App Config"]
        C["Project File"]
        A --> B
        A --> C

        subgraph "UI Layer"
            D["ContainerForm"]
            E["Animator Form"]
            F["Basic Form"]
            G["Pong Form"]
            H["Snake Form"]
            I["Tetris Form"]
            J["Visualizer Form"]
            K["Weather Form"]
            L["Preview Form"]
            M["Scripter Form"]
            N["Dots Form"]
        end

        subgraph "Business Logic"
            O["Action Logic"]
        end

        subgraph "Communication Layer"
            P["Frame Module"]
            Q["Serial Panel"]
            R["Matrix Panel"]
        end

        subgraph "Utilities & Helpers"
            S["Extra Services"]
            T["Control Components"]
        end
    end

    %% Arduino Firmware
    subgraph "Arduino Firmware"
        U["matrix.ino"]
        V["Serial.cpp"]
        W["Serial.h"]
        X["Settings.h"]
        Y["Standby.cpp"]
        Z["Standby.h"]
    end

    %% Connections within mPanel Desktop Application
    A -->|"starts"| D
    D -->|"loads"| O
    E --> O
    F --> O
    G --> O
    H --> O
    I --> O
    J --> O
    K --> O
    L --> O
    M --> O
    N --> O

    O -->|"createsFrame"| P
    O -->|"invokes"| Q
    O -->|"updatesDisplay"| R

    %% Communication to Arduino Firmware
    Q -->|"frameDataTx"| U

    %% Utilities supporting UI and Business Logic
    S ---|"supports"| D
    S --- O
    T ---|"enhances"| D
    T --- O

    %% Click Events for mPanel Desktop Application
    click A "https://github.com/trcio/mpanel/blob/master/mPanel/Program.cs"
    click B "https://github.com/trcio/mpanel/blob/master/mPanel/App.config"
    click C "https://github.com/trcio/mpanel/blob/master/mPanel/mPanel.csproj"
    click D "https://github.com/trcio/mpanel/blob/master/mPanel/ContainerForm.cs"
    click E "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Animator/AnimatorForm.cs"
    click F "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/BasicForm.cs"
    click G "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Pong/PongForm.cs"
    click H "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Snake/SnakeForm.cs"
    click I "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Tetris/TetrisForm.cs"
    click J "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Visualizer/VisualizerForm.cs"
    click K "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Weather/WeatherForm.cs"
    click L "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/PreviewForm.cs"
    click M "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Scripter/ScripterForm.cs"
    click N "https://github.com/trcio/mpanel/blob/master/mPanel/Actions/Dots/DotsForm.cs"
    click P "https://github.com/trcio/mpanel/blob/master/mPanel/Matrix/Frame.cs"
    click Q "https://github.com/trcio/mpanel/blob/master/mPanel/Matrix/SerialPanel.cs"
    click R "https://github.com/trcio/mpanel/blob/master/mPanel/Matrix/MatrixPanel.cs"
    click S "https://github.com/trcio/mpanel/tree/master/mPanel/Extra"
    click T "https://github.com/trcio/mpanel/tree/master/mPanel/Controls"

    %% Click Events for Arduino Firmware
    click U "https://github.com/trcio/mpanel/blob/master/Arduino/matrix/matrix.ino"
    click V "https://github.com/trcio/mpanel/blob/master/Arduino/matrix/serial.cpp"
    click W "https://github.com/trcio/mpanel/blob/master/Arduino/matrix/serial.h"
    click X "https://github.com/trcio/mpanel/blob/master/Arduino/matrix/settings.h"
    click Y "https://github.com/trcio/mpanel/blob/master/Arduino/matrix/standby.cpp"
    click Z "https://github.com/trcio/mpanel/blob/master/Arduino/matrix/standby.h"

    %% Style Classes
    class A,B,C,D,E,F,G,H,I,J,K,L,M,N,S,T default
    class D,E,F,G,H,I,J,K,L,M,N,A,B,C clickEvent
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef biz fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef comm fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef firmware fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#000,stroke-width:2px;

    %% Assign Classes
    class D,E,F,G,H,I,J,K,L,M,N ui
    class O biz
    class P,Q,R comm
    class U,V,W,X,Y,Z firmware
    class S,T utility
    class A,B,C ui
```
