# anycubic-3d/kobra2_neo architecture

> Architecture diagram of the GitHub repository anycubic-3d/kobra2_neo, 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/anycubic-3d/kobra2_neo
- Repository: https://github.com/anycubic-3d/kobra2_neo

## Overview

##### Major Architectural Layers and Components
- Core Modules and Firmware Framework: The “Marlin/src” folder contains “MarlinCore.cpp/h”, core board definitions, and various “core” files (such as drivers, utility functions, and configurations). This layer orchestrates overall firmware logic.
- G-code Interpreter: The “Marlin/src/gcode” directory handles all the command definitions and parsing, subdividing into further directories like “bedlevel,” “calibrate,” “control,” “lcd,” “motion,” etc. Represent this as a block that receives commands from external sources (e.g., USB/serial from a host computer or SD card).
- Feature Modules: The “Marlin/src/feature” directory shows dedicated modules for advanced functionalities like bed leveling algorithms (ABL, BDL, MBL, UBL), ammeter, direct stepping, bltouch, etc.
- User Interface & LCD/Touch Modules: The “Marlin/src/lcd” directory (including subfolders for various display types such as DOGM, TFTGLCD, and e3v2) plus “Marlin/src/menu” constitute the UI layer. Represent these as one or multiple blocks that interact with user inputs and provide status feedback.

##### Out the Data Flow and Interactions
- Input from External Host (via USB/Serial) or SD Card is received by the Communication Interface module.
- The G-code Interpreter block processes these commands and then routes them to appropriate feature or motion modules.
- The Motion, Temperature, and Extrusion modules (found in “Marlin/src/module”) use the HAL to interact with PWM drivers, stepper motors, sensors, etc.
- The User Interface (LCD/menus) receives updates from core modules and may also provide user input or override commands.

##### Relevant Build and Configuration Elements
- Presence of “Configuration.h” and “Configuration_adv.h” at the project root (and inside the Marlin folder). These files customize behavior and can be represented as configuration “inputs” that affect nearly every layer.

##### Architectural Patterns and Design Principles
- Layered / Modular Architecture: Distinct separation between HAL, core processing, interpreter, feature modules, and UI.
- Hardware Abstraction: The use of multiple HAL directories to hide platform-specific details.
- Extensibility and configurability: Separately maintained configuration and pin mapping files.
- Command Flow Pattern: Commands (G-code) being parsed and distributed among discrete modules (motion, temperature, UI, etc.), with clear input–processing–output flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interfaces
    subgraph "External Interfaces"
        External("External Interfaces (USB/Serial,SDCard,UserInput)"):::external
    end

    %% G-code Interpreter
    subgraph "Command Processing"
        Gcode("G-code Interpreter"):::gcode
    end

    %% Firmware Core Components
    subgraph "Firmware Core"
        Core1("MarlinCore.cpp"):::core
        Core2("Core Modules (/core)"):::core
    end

    %% Feature Modules
    Feat("Feature Modules"):::feature

    %% Hardware Abstraction Layers and Board Configuration
    HAL("HAL (Hardware Abstraction Layer)"):::hal
    PinConfig("Board/Pin Configuration"):::pin

    %% User Interface Elements
    subgraph "User Interface"
        LCD("LCD Modules"):::ui
        Menu("Menu Modules"):::ui
    end

    %% Build and Configuration Elements
    subgraph "Build & Configuration"
        ConfigH("Configuration.h"):::build
        ConfigAdv("Configuration_adv.h"):::build
        Makefile("Makefile"):::build
        PlatformIO("platformio.ini"):::build
    end

    %% Data Flow Connections
    External -->|"input"| Gcode
    Gcode -->|"parses"| Core1
    Core1 -->|"initializes"| Core2
    Core2 -->|"commands"| Feat
    Core2 -->|"updates"| LCD
    Core2 -->|"updates"| Menu
    Feat -->|"controls"| HAL
    HAL -->|"drives"| PinConfig
    HAL -- "feedback" --> Core2

    %% Build & Config influences
    ConfigH ---|"configures"| Core1
    ConfigAdv ---|"configures"| Core1
    Makefile ---|"builds"| Core2
    PlatformIO ---|"builds"| Core2

    %% Styles
    classDef external fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef gcode fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef feature fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef hal fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef pin fill:#d9d2e9,stroke:#333,stroke-width:2px;
    classDef ui fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef build fill:#f2d7d5,stroke:#333,stroke-width:2px;

    %% Click Events
    click HAL "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/HAL"
    click Core1 "https://github.com/anycubic-3d/kobra2_neo/blob/master/Marlin/src/MarlinCore.cpp"
    click Core2 "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/core"
    click Gcode "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/gcode"
    click Feat "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/feature"
    click LCD "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/lcd"
    click Menu "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/menu"
    click PinConfig "https://github.com/anycubic-3d/kobra2_neo/tree/master/Marlin/src/pins"
    click ConfigH "https://github.com/anycubic-3d/kobra2_neo/blob/master/Marlin/Configuration.h"
    click ConfigAdv "https://github.com/anycubic-3d/kobra2_neo/blob/master/Marlin/Configuration_adv.h"
    click Makefile "https://github.com/anycubic-3d/kobra2_neo/tree/master/Makefile"
    click PlatformIO "https://github.com/anycubic-3d/kobra2_neo/blob/master/platformio.ini"
```
