# dra1ex/ff5m architecture

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

- Interactive diagram: https://gitdiagram.com/dra1ex/ff5m
- Repository: https://github.com/dra1ex/ff5m

## Overview

##### Main Components
- Firmware/MCU Layer: This is represented by the C++ code in .bin/src/boot_mcu (and other executables like demo, logged, typer) as well as the common modules (fonts, text handling, etc.). These components handle the low-level printer control.
- Klipper Core & Patches: These are the customizations and patches integrated into Klipper (see references in the README such as fixes for E00017, nozzle collision failsafe, shaper calibration, etc.).
- Moonraker Server: Located in the “.root/moonraker” directory and its extensive “components” subdirectory, it forms the API and management backbone, coordinating printer communications, file management, update handling, and integration with external interfaces.
- Web Front Ends (Fluidd and Mainsail): The README references these web UI interfaces. They interact with Moonraker to provide the user interface for printer monitoring and control.
- Configuration & Tooling: This includes the various .cfg (configuration files), KAMP for adaptive bed meshing, Python scripts (in the .py directory) for OTA updates, backups, utilities (e.g., backlight, tone, speed test, etc.), and shell scripts (.shell) for boot and maintenance tasks.
- External Services Integration: Components like the Telegram bot for timelapse support, Entware for additional package management, and patchsets for external Klipper enhancements are also represented.

##### Relationships and Interactions
- Data Flow: Illustrate the flow from the end-user (using Fluidd/Mainsail web interface) to the Moonraker API, and then further down to the Klipper-engine and ultimately to the printer’s MCU firmware.
- Configuration and OTA: Show a separate panel for configuration files and update mechanisms that interact with both the firmware layer (via boot, OTA, and backup scripts) and the higher API/services layer.

##### Important Architectural Patterns and Design Principles
- Modularity and Extensibility: Note the structure where each directory (e.g., components in Moonraker, plugins in Klipper, dedicated configuration directories) encapsulates specific functionality. This ensures maintainability and easier debugging.
- Bootstrapping & Recovery: Highlight that boot scripts, dual-boot configurations, and recovery mechanisms are key in a device that runs a dedicated Linux environment (based on Buildroot), indicating robustness and safety.

##### Relevant Technologies, Frameworks, and Libraries
- Custom Buildroot-based Linux: Represent the dedicated Linux environment on the printer.
- Klipper and Moonraker: Reference these as the core engine for printer control and web API, respectively.
- Fluidd/Mainsail: As front ends, note that they form the user-facing control panels.
- Scripting Tools: Include Python, shell scripts, and the use of zsh with oh-my-zsh for administrative tasks.
- Font Libraries: For screen output (JetBrains Mono, Roboto, Typicons), showing that UI/UX on the hardware display is optimized.

- A section for auxiliary services (like Telegram integration and buildroot/Entware functionality) to capture all external dependencies.
- That boot and recovery components (e.g., boot scripts under .shell, dual-boot support) are not overlooked because they are essential for a robust embedded system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI1["Mainsail Web UI"]:::frontend
        UI2["Fluidd Web UI"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        MA["Moonraker API Server"]:::api
        KC["Klipper Core & Patches"]:::api
    end

    %% Firmware/MCU Layer
    subgraph "Firmware/MCU Layer"
        MCU["MCU Firmware"]:::firmware
    end

    %% Auxiliary Services
    subgraph "Auxiliary Services"
        CT["Configuration & Tooling"]:::config
        ES["External Services (Telegram)"]:::external
    end

    %% Data Flow Connections
    UI1 -->|"commands"| MA
    UI2 -->|"commands"| MA
    MA -->|"coordinates"| KC
    KC -->|"controls"| MCU

    %% Auxiliary Interactions
    CT -->|"updates"| MA
    CT -->|"updates"| KC
    CT -->|"OTA/boot"| MCU
    ES -->|"integrated"| MA

    %% Click Events for MCU Firmware
    click MCU "https://github.com/dra1ex/ff5m/tree/main/.bin/exec/boot_mcu"
    click MCU "https://github.com/dra1ex/ff5m/tree/main/.bin/src/boot_mcu"

    %% Click Events for Klipper Core & Patches
    click KC "https://github.com/dra1ex/ff5m/tree/main/.py/klipper/patches"
    click KC "https://github.com/dra1ex/ff5m/tree/main/.py/klipper/plugins"

    %% Click Events for Moonraker API Server
    click MA "https://github.com/dra1ex/ff5m/tree/main/.root/moonraker"

    %% Click Events for Mainsail Web UI
    click UI1 "https://github.com/dra1ex/ff5m/blob/main/.root/mainsail.json"
    click UI1 "https://github.com/dra1ex/ff5m/blob/main/.root/patches/mainsail.patch"

    %% Click Events for Configuration & Tooling
    click CT "https://github.com/dra1ex/ff5m/blob/main/.cfg"
    click CT "https://github.com/dra1ex/ff5m/blob/main/.py"
    click CT "https://github.com/dra1ex/ff5m/blob/main/.shell"

    %% Click Events for External Services (Telegram)
    click ES "https://github.com/dra1ex/ff5m/tree/main/telegram"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef api fill:#FFE082,stroke:#FF6F00,stroke-width:2px;
    classDef firmware fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef config fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
