# next-flip/momentum-firmware architecture

> Architecture diagram of the GitHub repository next-flip/momentum-firmware, 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/next-flip/momentum-firmware
- Repository: https://github.com/next-flip/momentum-firmware

## Overview

##### Major architectural layers
- • ROM Bootloader & Startup – Although not very separate in the repo, the bootstrapping code (startup files, SConstruct, and toolchain scripts in “targets”) is critical.
- • RTOS Kernel & Core – This layer comprises the FreeRTOS components (found in “lib/FreeRTOS-Kernel” and “furi/core”) and the Furi core libraries. It is the basis on which tasks and threads run.
- • Hardware Abstraction Layer (HAL) & Device Drivers – Under “targets/furi_hal”, “lib/drivers,” “lib/fatfs”, and various protocol modules (NFC, Infrared, SubGHz, iButton, etc.), you have drivers that talk directly to the hardware.
- • Middleware & Libraries – A wealth of modules sit here (for example, “lib/mjs” provides the JavaScript engine, “lib/ibutton”, “lib/nfc”, “lib/subghz”, “lib/u8g2”, “lib/mlib”, etc.). These libraries abstract complex protocols and functionalities.
- • Applications and Services – In the “applications” folder you see many subfolders: a wide range of apps (debug apps, main apps, settings apps, system apps) and in “applications/services” you have services (CLI, desktop, GUI, input, loader, etc.). This application layer also includes the highly customizable Momentum Settings and Bad Keyboard functions described in the README.

##### Inter-layer dependencies and interactions
- Data flows upward from the hardware through the HAL and driver layers into the OS kernel, where tasks are scheduled.
- Middleware libraries (protocol stacks for NFC, SubGHz, Infrared, etc.) abstract hardware complexities and provide APIs to the higher-level applications.
- The applications and services call upon these libraries to implement features like file management, Bluetooth spoofing (Bad Keyboard), and the momentum settings interface.
- The assets and animation system interacts with the GUI part of the services and apps to provide a fully customizable user experience.
- Additionally, the build system (SConstruct, SConscripts, and associated “scripts” folders) is critical for assembling and flashing the firmware to the device.

##### Final Elements
- Clear, legible labels for each major component.
- Optionally, add notes indicating which folders from the file tree correspond to each module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    BuildSystem["Build System (SConstruct, SCons)"]:::build

    subgraph "Momentum Firmware"
        subgraph "Hardware & Bootloader"
            Bootloader["ROM Bootloader & Startup"]:::boot
        end
        subgraph "RTOS Kernel & Core"
            FreeRTOS["FreeRTOS Kernel (lib/FreeRTOS-Kernel)"]:::os
            FuriCore["Furi Core (furi/core)"]:::os
        end
        subgraph "HAL & Drivers"
            HALDrivers["HAL & Drivers (targets/furi_hal, lib/drivers, lib/fatfs)"]:::hal
        end
        subgraph "Middleware & Libraries"
            MiddlewareLibs["Middleware & Libraries (lib/mjs, lib/ibutton, lib/nfc, lib/subghz, lib/u8g2, lib/mlib, lib/momentum)"]:::middleware
        end
        subgraph "Applications & Services"
            AppsServices["Applications & Services (applications)"]:::apps
            AssetsManager["Asset & Animation Management (assets, applications/examples)"]:::apps
        end
    end

    %% Build System feeds into every layer
    BuildSystem -->|"builds"| Bootloader
    BuildSystem -->|"builds"| FreeRTOS
    BuildSystem -->|"builds"| FuriCore
    BuildSystem -->|"builds"| HALDrivers
    BuildSystem -->|"builds"| MiddlewareLibs
    BuildSystem -->|"builds"| AppsServices

    %% Data flow / Dependencies
    Bootloader -->|"bootstrap"| FuriCore
    HALDrivers -->|"provides_data"| FuriCore
    HALDrivers -->|"exposes_APIs"| MiddlewareLibs
    MiddlewareLibs -->|"offers_services"| AppsServices
    AssetsManager -->|"supplies_UI_assets"| AppsServices

    %% Class Definitions for Colors
    classDef boot fill:#D3D3D3,stroke:#000000,stroke-width:2px;
    classDef os fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef hal fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef middleware fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef apps fill:#DDA0DD,stroke:#800080,stroke-width:2px;
    classDef build fill:#FFFFE0,stroke:#DAA520,stroke-width:2px;

    class Bootloader boot;
    class FreeRTOS,FuriCore os;
    class HALDrivers hal;
    class MiddlewareLibs middleware;
    class AppsServices,AssetsManager apps;
    class BuildSystem build;

    %% Click Events for Component Mapping
    click Bootloader "https://github.com/next-flip/momentum-firmware/tree/dev/SConstruct"
    click Bootloader "https://github.com/next-flip/momentum-firmware/tree/dev/targets"
    click FreeRTOS "https://github.com/next-flip/momentum-firmware/tree/dev/lib/FreeRTOS-Kernel"
    click FuriCore "https://github.com/next-flip/momentum-firmware/tree/dev/furi/core"
    click HALDrivers "https://github.com/next-flip/momentum-firmware/tree/dev/targets/furi_hal"
    click HALDrivers "https://github.com/next-flip/momentum-firmware/tree/dev/lib/drivers"
    click HALDrivers "https://github.com/next-flip/momentum-firmware/tree/dev/lib/fatfs"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/mjs"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/ibutton"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/nfc"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/subghz"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/u8g2"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/mlib"
    click MiddlewareLibs "https://github.com/next-flip/momentum-firmware/tree/dev/lib/momentum"
    click AppsServices "https://github.com/next-flip/momentum-firmware/tree/dev/applications"
    click AssetsManager "https://github.com/next-flip/momentum-firmware/tree/dev/assets"
    click AssetsManager "https://github.com/next-flip/momentum-firmware/tree/dev/applications/examples"
```
