# tuanchris/dune-weaver architecture

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

- Interactive diagram: https://gitdiagram.com/tuanchris/dune-weaver
- Repository: https://github.com/tuanchris/dune-weaver

## Overview

##### Main Components

A. Frontend Layer:
- Web Interface (Browser-based UI)
- Static Assets (CSS, JS files in /static)
- HTML Templates (in /templates)

B. Backend Layer:
- Flask Web Server (app.py)
- Pattern Processing System
- Serial Communication Handler

C. Hardware Layer:
- Arduino Controller
- Motors & Drivers
- Physical Components (sand table, magnet, steel ball)

**[Web Interface Layer]**
- ↕
**[Backend Server Layer]**
- ↕
**[Hardware Layer]**

##### Component Details and Relationships

A. Web Interface Layer (Top):
- Static file serving (main.js, style.css)
- Template rendering (index.html)

B. Backend Server Layer (Middle):
- Key modules:
- Pattern Processor (handling .thr files)
- Serial Communication Manager
- File Management System
- Patterns directory with its contents

C. Hardware Layer (Bottom):
- Arduino Controller (show both variants: standard and TMC2209)
- Motor Control System
- Physical Table Components

##### Data Flow Indicators

- HTTP/WebSocket communications between frontend and backend
- Serial communication between backend and Arduino
- Physical control signals from Arduino to motors
- Pattern file processing flow

##### Additional Elements

- Notes about the theta-rho coordinate system
- Configuration flows for pre-execution actions
- Batch processing optimization

##### Technical Details

- Python/Flask backend
- Serial communication protocols
- Arduino firmware components
- Motor driver specifications (DRV8825/TMC2209)
- Pattern file format structure

Remember to indicate the asynchronous nature of the communication between components and the real-time aspects of the system, as this is crucial for the smooth operation of the sand table.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Web
        Browser["Web Browser"]
        UI["Web Interface"]:::frontend
        Static["Static Assets"]:::frontend
        Templates["HTML Templates"]:::frontend
    end

    subgraph Server
        Flask["Flask Server"]:::backend
        PatternProc["Pattern Processor"]:::backend
        SerialComm["Serial Communication"]:::backend
        FileSystem["File Management"]:::backend
        Patterns["Pattern Storage"]:::storage
        CustomPat["Custom Patterns"]:::storage
    end

    subgraph Hardware
        Arduino["Arduino Controller"]:::hardware
        TMC["TMC2209 Variant"]:::hardware
        ESP["ESP32 Variant"]:::hardware
        Motors["Motors & Drivers"]:::hardware
        Table["Physical Table"]:::hardware
        Calibration["Hardware Calibration"]:::hardware
    end

    Browser --> UI
    UI --> Static
    UI --> Templates
    UI <--> Flask

    Flask --> PatternProc
    Flask --> SerialComm
    Flask --> FileSystem
    
    FileSystem --> Patterns
    FileSystem --> CustomPat
    
    PatternProc --> SerialComm
    SerialComm --> Arduino
    SerialComm --> TMC
    SerialComm --> ESP
    
    Arduino --> Motors
    TMC --> Motors
    ESP --> Motors
    Motors --> Table
    Calibration --> Motors

    %% Click Events
    click UI "https://github.com/tuanchris/dune-weaver/blob/main/templates/index.html"
    click Static "https://github.com/tuanchris/dune-weaver/blob/main/static/main.js"
    click Static "https://github.com/tuanchris/dune-weaver/blob/main/static/style.css"
    click Flask "https://github.com/tuanchris/dune-weaver/blob/main/app.py"
    click PatternProc "https://github.com/tuanchris/dune-weaver/blob/main/mirror_pattern.py"
    click Arduino "https://github.com/tuanchris/dune-weaver/blob/main/arduino_code/arduino_code.ino"
    click TMC "https://github.com/tuanchris/dune-weaver/blob/main/arduino_code_TMC2209/arduino_code_TMC2209.ino"
    click ESP "https://github.com/tuanchris/dune-weaver/blob/main/esp32/esp32.ino"
    click Calibration "https://github.com/tuanchris/dune-weaver/blob/main/steps_calibration/steps_calibration.ino"
    click Patterns "https://github.com/tuanchris/dune-weaver/tree/main/patterns/"
    click CustomPat "https://github.com/tuanchris/dune-weaver/tree/main/patterns/custom_patterns/"

    %% Styling
    classDef frontend fill:#3498db
    classDef backend fill:#2ecc71
    classDef storage fill:#f1c40f
    classDef hardware fill:#e74c3c
    classDef communication fill:#9b59b6

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Storage["Storage Component"]:::storage
        HW["Hardware Component"]:::hardware
        Comm["Communication"]:::communication
    end
```
