# foxbms/foxbms-2 architecture

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

- Interactive diagram: https://gitdiagram.com/foxbms/foxbms-2
- Repository: https://github.com/foxbms/foxbms-2

## Overview

- Hardware: Indicate the hardware schematic and layout, including the battery system and sensor interfaces. The “hardware” directory holds circuit drawings and other files.
- Configuration/Settings: The “conf” folder contains high level configuration files—for instance, linking to CAN signal configurations, board definitions, etc.
- Embedded Software (Firmware): Use the “src” directory as the core of the embedded system. Within it, show key layered modules:
– Bootloader: (src/bootloader) responsible for startup, basic hardware initialization, and firmware upgrade.
– Hardware Abstraction Layer (HAL) and Drivers: Indicate drivers for ADC, CAN, I2C, SPI, and other peripherals (found in src/app/driver and similar subfolders).
– Application Layer: This contains modules for the battery management algorithms, such as state-estimation (SOC, SOE, SOH), balancing, BMS state logic, and plausibility checks (located in src/app/application) including algorithm and configuration modules.
- Command-Line Interface (CLI): The “cli” directory provides a toolchain for interacting with the repository (running tests, builds, deployments) and is central for development.
- Tools and Build Scripts: The “tools” directory includes scripts for code generation, versioning, build utilities, and specialized vendor tool integrations (e.g., for debugger, IDE integrations). This can be illustrated as supporting components which feed into build and verification of the firmware.
- Testing Framework: The “tests” folder includes unit tests and integration tests for both embedded sources and tool chain scripts. This can be indicated as a separate module that interacts with both the software and the CLI/toolchain.

##### Relationships and Data Flow
- That the bootloader is the first software piece that interacts with the hardware and then hands off control to the main OS.
- Optionally, illustrate how configuration files (in “conf”) and documentation (in “docs”) support development, maintenance, and certification processes.

##### Architectural Patterns and Design Principles
- Layered Architecture: Emphasize the strict separation between the hardware interfacing (drivers, HAL), core system functionality (RTOS, kernel, bootloader) and application logic (BMS algorithms, balancing, state estimation).
- Modularity: foxBMS is built as a modular platform, allowing individual modules (algorithm, driver, CLI commands) to be independently developed and tested.

##### Use of Technologies and Frameworks
- Mentions of RTOS components (typically FreeRTOS from the “src/os” directory or a variant indicated by “safertos”).
- Integration with industry-standard tools for static analysis, version control (git, pre-commit hooks), and IDE support (vscode configuration in “tools/ide”).
- That build configuration and testing are automated via scripts and meta-build systems (e.g., “wscript” files and pyproject.toml).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Components
    hw["Hardware"]:::hardware
    config["Configuration/Settings"]:::config

    %% Embedded Software Subgraph
    subgraph "Embedded Software (Firmware)"
        boot["Bootloader"]:::bootloader
        os["RTOS/Operating System Layer"]:::os
        driver["Drivers/HAL"]:::driver
        app["Application Layer"]:::app
    end

    %% Developer Tools Subgraph
    subgraph "Development & Tools"
        cli["CLI"]:::cli
        tools["Tools and Build Scripts"]:::tools
        tests["Testing Framework"]:::tests
    end

    %% Relationships and Data Flow
    hw -->|"initializes"| boot
    boot -->|"hand-off"| os
    os -->|"manages"| driver
    driver -->|"services"| app
    hw -->|"provides-signals"| driver

    config -->|"configures"| boot
    config -->|"configures"| app

    cli -->|"triggers-build"| tools
    cli -->|"triggers-tests"| tests
    tools -->|"deploys"| app
    tests -->|"verifies"| app

    %% Click Events
    click hw "https://github.com/foxbms/foxbms-2/tree/master/hardware"
    click config "https://github.com/foxbms/foxbms-2/tree/master/conf"
    click boot "https://github.com/foxbms/foxbms-2/tree/master/src/bootloader"
    click os "https://github.com/foxbms/foxbms-2/tree/master/src/os"
    click driver "https://github.com/foxbms/foxbms-2/tree/master/src/app/driver"
    click app "https://github.com/foxbms/foxbms-2/tree/master/src/app/application"
    click cli "https://github.com/foxbms/foxbms-2/tree/master/cli"
    click tools "https://github.com/foxbms/foxbms-2/tree/master/tools"
    click tests "https://github.com/foxbms/foxbms-2/tree/master/tests"

    %% Styles
    classDef hardware fill:#ffcccc,stroke:#b30000,stroke-width:2px;
    classDef config fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
    classDef bootloader fill:#ccffcc,stroke:#339933,stroke-width:2px;
    classDef os fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef driver fill:#e6ccff,stroke:#6600cc,stroke-width:2px;
    classDef app fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef cli fill:#ccffff,stroke:#009999,stroke-width:2px;
    classDef tools fill:#ffebcc,stroke:#cc3300,stroke-width:2px;
    classDef tests fill:#ffcccc,stroke:#cc0066,stroke-width:2px;
```
