# thepurpleone/magtrix architecture

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

## Overview

##### Main Components
- Front End (User Interface):
– Component: React web application in “src/web/tictactoe/frontend”.
– Role: Displays the game board, processes player interactions, and sends move commands.
- Back End (Game Server API):
– Component: Python server in “src/web/tictactoe/backend”.
– Role: Acts as a bridge between the UI and hardware; receives commands from the frontend and forwards them to the MCU.
- MCU Firmware:
– Component: Firmware (in “src/mcu/tictactoe” and “src/mcu/firmware” for other parts) that handles game move commands.
– Role: Receives move instructions from the backend and drives the electromagnetic coils on the PCB; may include microcontroller scheduling (e.g., via FreeRTOS) and real-time control mechanisms.
- Hardware / PCB:
– Component: Custom PCB designs (e.g., “pcb/magtrix”, “pcb/coil_driver” and others) created using KiCad.
– Role: Physically controls the board’s magnetic elements. The design files and KiCad libraries indicated in the tree help generate schematics and layout files.
- Supporting & Simulation Tools:
– Additional areas include simulation scripts (under “simulation”) and KiCad automation scripts (under “src/kicad_scripts”) that help test and generate PCB/design outputs.
– These tools provide insight into how the hardware may be simulated before fabrication.

##### Relationships and Data Flow
- The Front End sends player move commands to the Back End.
- The Back End processes the game logic and then communicates with the MCU.
- The MCU Firmware receives commands (e.g., via a serial or similar communication protocol) and activates specific coils on the PCB.
- The physical PCB (designed in KiCad, with coil drivers and associated electronics) receives the actuations, moving the magnetic game pieces.
- Optionally, simulation tools allow for virtual testing of the Coil responses before actual manufacturing.

##### Final Checklist
- Clear labels for each main block/component.
- Annotations where necessary (e.g., list of frameworks: “React” in frontend, “Python” in backend, “C/FreeRTOS” in MCU firmware, “KiCad” for PCB).
- Optionally, include smaller blocks for simulation/automation if detail is needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    subgraph "User Interaction"
        UI["Web UI – React Frontend"]:::frontend
    end

    %% Backend and Firmware Layer
    subgraph "Software Communication"
        BE["Python Backend – Game Server API"]:::backend
        MCU["MCU Firmware"]:::firmware
    end

    %% Hardware Design Layer
    subgraph "Hardware Design"
        PCB1["PCB Hardware (Magnetic Board)"]:::hardware
        PCB2["PCB Hardware (Coil Drivers)"]:::hardware
    end

    %% Supporting & Simulation Tools Layer
    subgraph "Supporting & Simulation Tools"
        SIM["Simulation Environment"]:::simulation
        KCAD["KiCad Automation Scripts"]:::kicad
    end

    %% Data Flow Connections
    UI -->|"REST_API"| BE
    BE -->|"Serial/UART"| MCU
    MCU -->|"Actuation_Signals"| PCB1
    MCU -->|"Actuation_Signals"| PCB2
    PCB1 -->|"Feedback"| MCU
    PCB2 -->|"Feedback"| MCU
    KCAD -->|"Automates"| PCB1
    KCAD -->|"Automates"| PCB2
    SIM -->|"Tests"| PCB1
    SIM -->|"Tests"| PCB2

    %% Click Events
    click UI "https://github.com/thepurpleone/magtrix/tree/master/src/web/tictactoe/frontend"
    click BE "https://github.com/thepurpleone/magtrix/tree/master/src/web/tictactoe/backend"
    click MCU "https://github.com/thepurpleone/magtrix/tree/master/src/mcu/firmware"
    click PCB1 "https://github.com/thepurpleone/magtrix/tree/master/pcb/magtrix"
    click PCB2 "https://github.com/thepurpleone/magtrix/tree/master/pcb/coil_driver"
    click SIM "https://github.com/thepurpleone/magtrix/tree/master/simulation/first_simu"
    click KCAD "https://github.com/thepurpleone/magtrix/tree/master/src/kicad_scripts"

    %% Styles for Color Coding
    classDef frontend fill:#f9e79f,stroke:#d35400,stroke-width:2px,color:#1c2833;
    classDef backend fill:#aed6f1,stroke:#2471a3,stroke-width:2px,color:#1c2833;
    classDef firmware fill:#abebc6,stroke:#1e8449,stroke-width:2px,color:#1c2833;
    classDef hardware fill:#f5cba7,stroke:#a04000,stroke-width:2px,color:#1c2833;
    classDef simulation fill:#f9e79f,stroke:#b9770e,stroke-width:2px,color:#1c2833;
    classDef kicad fill:#d2b4de,stroke:#8e44ad,stroke-width:2px,color:#1c2833;
```
