# misprit7/real-time-chess architecture

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

- Interactive diagram: https://gitdiagram.com/misprit7/real-time-chess
- Repository: https://github.com/misprit7/real-time-chess

## Overview

##### Main Components
- Hardware Platform:
- PCB/Board Design: Organize the “ecad” folder’s various subdirectories (e.g., “board”, “edge1”, “edge2”, etc.) to show that multiple board components exist. These represent the physical layout and custom PCB components (including the electromagnets and possibly LED indicators) that enforce piece cooldown.
- Electromagnets & Mechanical Assembly: Mention off-the-shelf components (insulating washers, plastic screws, spacers, etc.) that are externally referenced in the README.
- Power Distribution: Note the known issue with undersized traces and voltage drops, so include a block to represent power management.

- Firmware System:
- Microcontroller (Teensy): Represent the central MCU that runs the firmware.
- Firmware Application: Include main firmware source files (main.cpp, goertzel.cpp, etc.) which implement the chess board control logic.
- Real-Time Operating System: Highlight the integration of FreeRTOS (as seen in the “firmware/lib/freertos-teensy” folder) that manages task scheduling (e.g., piece cooldown timers, sensor readings, and control of actuators).
- Build & Configuration: Include components such as “platformio.ini” and build scripts (build.py) that are used to compile and deploy the firmware.

##### Relationships and Interactions
- How signals flow from physical sensors or user inputs through the embedded firmware’s control logic (including any digital signal processing like the goertzel algorithm) and then out to actuators (electromagnets that hold chess pieces).

##### Architectural Patterns and Design Principles
- Separation between the physical (hardware/ECAD) components and the embedded software. Create two high-level layers (Hardware Layer and Firmware Layer) with well-defined interfaces.
- Modular structure in the ECAD designs where different board segments (main board, edge boards, etc.) are designed separately but work cohesively.
- For the firmware, note that leveraging FreeRTOS (and by extension built-in C++ libraries) modularizes timing-critical tasks such as enforcing cooldowns per piece and managing sensor/actuator updates.

##### Relevant Technologies and Tools
- KiCad for PCB design (illustrated by file extensions like *.kicad_pcb, *.kicad_pro, and *.kicad_sch).
- Teensy Platform, likely chosen for its embedded capabilities.
- FreeRTOS for scheduling and task management.
- Use of PlatformIO (platformio.ini) for building and deploying firmware.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Hardware Layer"
        subgraph "ECAD Board Designs"
            MainPCB["Main PCB Design"]:::hardware
            Edge1["Edge Board 1"]:::hardware
            Edge2["Edge Board 2"]:::hardware
            Edge3["Edge Board 3"]:::hardware
            Edge4["Edge Board 4"]:::hardware
        end
        Electro["Electromagnets & Mechanical Assembly"]:::mechanical
        Power["Power Distribution (trace issues)"]:::hardware
    end

    subgraph "Firmware Layer"
        MCU["Teensy Microcontroller"]:::firmware
        FirmwareApp["Firmware Application Code"]:::firmware
        FreeRTOS["FreeRTOS Scheduler"]:::firmware
        Build["Build & Configuration"]:::firmware
    end

    %% Firmware Layer Interactions
    MCU -->|"executes"| FirmwareApp
    MCU -->|"interfaces"| FreeRTOS
    FreeRTOS -->|"schedules"| FirmwareApp
    Build -->|"builds"| FirmwareApp

    %% Firmware to Hardware Interactions
    FirmwareApp -->|"readsSensors"| MainPCB
    FirmwareApp -->|"controlsActuators"| Electro
    MCU -->|"drives"| Power

    %% Hardware Interconnections
    MainPCB ---|"powerBus"| Edge1
    MainPCB ---|"powerBus"| Edge2
    MainPCB ---|"powerBus"| Edge3
    MainPCB ---|"powerBus"| Edge4
    Power -->|"supplies"| MainPCB
    Power -->|"supplies"| Edge1
    Power -->|"supplies"| Edge2
    Power -->|"supplies"| Edge3
    Power -->|"supplies"| Edge4

    %% Click Events for Component Mappings
    click MainPCB "https://github.com/misprit7/real-time-chess/blob/main/ecad/board/kfchess.kicad_pcb"
    click Edge1 "https://github.com/misprit7/real-time-chess/blob/main/ecad/edge1/edge1.kicad_pcb"
    click Edge2 "https://github.com/misprit7/real-time-chess/blob/main/ecad/edge2/edge1.kicad_pcb"
    click Edge3 "https://github.com/misprit7/real-time-chess/blob/main/ecad/edge3/edge1.kicad_pcb"
    click Edge4 "https://github.com/misprit7/real-time-chess/blob/main/ecad/edge4/edge1.kicad_mod"
    click FirmwareApp "https://github.com/misprit7/real-time-chess/blob/main/firmware/src/main.cpp"
    click FreeRTOS "https://github.com/misprit7/real-time-chess/tree/main/firmware/lib/freertos-teensy"
    click Build "https://github.com/misprit7/real-time-chess/blob/main/firmware/platformio.ini"

    %% Styles
    classDef hardware fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef firmware fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef mechanical fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef note fill:#FFFFE0,stroke:#000,stroke-dasharray: 5 5;
```
