# nuclei-software/nuclei-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/nuclei-software/nuclei-sdk
- Repository: https://github.com/nuclei-software/nuclei-sdk

## Overview

##### Main Components
- Build System and Infrastructure:
- The “Build” folder contains multiple Makefiles (e.g., Makefile.core, Makefile.components, Makefile.rtos, etc.) which orchestrate the build of SDK components.
- The root Makefile and SConscript serve as entry points to build and debug applications across multiple platforms.
- Application Layers:
- The “application” directory is divided into subdirectories for various deployment models: baremetal, FreeRTOS, UCOSII, RTThread, and ThreadX.
- Each type represents a specific flavor of application built on top of the same SDK infrastructure.
- SoC and Board Abstraction:
- The “SoC” directory holds support packages for different processors and boards. It includes folders like evalsoc, gd32vf103, and gd32vw55x.
- Each SoC design contains a “Common” and “Board” layer: the Common subfolder contains device drivers and system-level code (including the mandatory “nuclei_sdk_soc.h”), while each board directory provides hardware abstraction (with “nuclei_sdk_hal.h”).
- NMSIS and DSP/NN Library:
- The “NMSIS” directory (including Core, DSP, NN, and Library subdirectories) provides the peripheral and core definitions. The SDK is built on this foundation so it is critical to show its central role.
- OS Packages:
- The “OS” directory includes RTOS implementations that are integrated in the SDK. Each OS (FreeRTOS, UCOSII, ThreadX, RTThread) can be shown as separate building blocks that supply kernel services to corresponding application projects.
- Supporting Tools and Documentation:
- Tools for benchmarking, configuration, testing, and the IDE support (Nuclei Studio, PlatformIO integration via package.json, etc.) appear within directories like “tools”, “ideprojects”, and “doc”. These are essential for both development and evaluation.

##### Relationships and Interactions
- A layered model:
– At the bottom, show the Hardware and SoC/Board Abstraction layer, including both custom SoC hardware support and board initialization (the HAL provided via “nuclei_sdk_soc.h” and “nuclei_sdk_hal.h”).
– Above that, show the NMSIS layer that abstracts the CPU/DSP instructions and peripheral functionality.
– Next, add the OS Layer (if used) and then the Application layer (baremetal or RTOS-based).
- Connections that show the integration of external toolchains (Nuclei RISC-V gcc/clang, IAR, Terapines) and debugging tools (OpenOCD, gdb).
- In an auxiliary section, include the “tools” and “ideprojects” components to show their role in project configuration, benchmarking, and IDE integration.

##### Architectural Patterns and Design Principles
- Modularity – by dividing the system into independent and clearly defined modules (NMSIS, OS, SoC/Board, Applications, Build Infrastructure).
- Abstraction layers between hardware-specific code and the application logic.
- That the build scripts act as “glue code” that integrates these independent modules.
- How external configurations (such as toolchain-specific Makefiles in “Build/toolchain” and CPU configuration files within “tools/scripts/nsdk_cli/configs”) replace hard-coded parameters via variable substitution (e.g., CORE, DOWNLOAD options).

##### Technologies and Frameworks
- Integration of various compilers (nuclei_gnu, nuclei_llvm, IAR, Terapines ZCC) and debugging/flash download flows.
- Mention that PlatformIO support is provided through package.json.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build System Subgraph
    subgraph "Build System"
        BS1["Build Folder"] 
        BS2["Root Makefile"]
        BS3["SConscript"]
    end

    %% External Tools Node
    ToolchainDebug["Toolchain & Debug Tools"]

    %% SoC & Board Abstraction Subgraph
    subgraph "SoC & Board Abstraction"
        SoCOverall["SoC & Board Support"]
        SoCCommon["Common (nuclei_sdk_soc.h)"]
        SoCBoard["Board (nuclei_sdk_hal.h)"]
    end

    %% NMSIS Framework Subgraph
    subgraph "NMSIS Framework"
        NMSISFrame["NMSIS Framework"]
    end

    %% OS Packages Subgraph
    subgraph "OS Packages"
        OSFreeRTOS["FreeRTOS OS"]
        OSUCOSII["UCOSII OS"]
        OSRTThread["RTThread OS"]
        OSThreadX["ThreadX OS"]
    end

    %% Application Layers Subgraph
    subgraph "Application Layers"
        AppBaremetal["Baremetal Application"]
        AppFreeRTOS["FreeRTOS Application"]
        AppUCOSII["UCOSII Application"]
        AppRTThread["RTThread Application"]
        AppThreadX["ThreadX Application"]
    end

    %% Supporting Tools Subgraph
    subgraph "Supporting Tools"
        Tools["tools"]
        IDE["ideprojects"]
        Doc["doc"]
        PackageJson["package.json"]
        SetupSh["setup.sh"]
        SetupBat["setup.bat"]
        SetupPs1["setup.ps1"]
    end

    %% Connections from Build System to Other Layers
    BS2 -->|"builds"| SoCOverall
    BS2 -->|"builds"| NMSISFrame
    BS2 -->|"builds"| OSFreeRTOS
    BS2 -->|"builds"| AppBaremetal
    BS2 -->|"builds"| Tools
    BS2 -->|"configures"| ToolchainDebug

    %% SoC & Board supports NMSIS
    SoCOverall -->|"provides hardware support to"| NMSISFrame

    %% NMSIS Layer underlying OS Packages and Applications
    NMSISFrame -->|"supports"| OSFreeRTOS
    NMSISFrame -->|"supports"| OSUCOSII
    NMSISFrame -->|"supports"| OSRTThread
    NMSISFrame -->|"supports"| OSThreadX
    NMSISFrame -->|"direct API use in"| AppBaremetal

    %% OS Packages provide kernel services to Application Layers
    OSFreeRTOS -->|"kernel services"| AppFreeRTOS
    OSUCOSII -->|"kernel services"| AppUCOSII
    OSRTThread -->|"kernel services"| AppRTThread
    OSThreadX -->|"kernel services"| AppThreadX

    %% Click Events for Build System
    click BS1 "https://github.com/nuclei-software/nuclei-sdk/tree/master/Build"
    click BS2 "https://github.com/nuclei-software/nuclei-sdk/tree/master/Makefile"
    click BS3 "https://github.com/nuclei-software/nuclei-sdk/tree/master/SConscript"

    %% Click Events for SoC & Board Abstraction
    click SoCOverall "https://github.com/nuclei-software/nuclei-sdk/tree/master/SoC"
    click SoCCommon "https://github.com/nuclei-software/nuclei-sdk/blob/master/SoC/evalsoc/Common/nuclei_sdk_soc.h"
    click SoCBoard "https://github.com/nuclei-software/nuclei-sdk/blob/master/SoC/evalsoc/Board/nuclei_sdk_hal.h"

    %% Click Event for NMSIS Framework
    click NMSISFrame "https://github.com/nuclei-software/nuclei-sdk/tree/master/NMSIS"

    %% Click Events for OS Packages
    click OSFreeRTOS "https://github.com/nuclei-software/nuclei-sdk/tree/master/OS/FreeRTOS"
    click OSUCOSII "https://github.com/nuclei-software/nuclei-sdk/tree/master/OS/UCOSII"
    click OSRTThread "https://github.com/nuclei-software/nuclei-sdk/tree/master/OS/RTThread"
    click OSThreadX "https://github.com/nuclei-software/nuclei-sdk/tree/master/OS/ThreadX"

    %% Click Events for Application Layers
    click AppBaremetal "https://github.com/nuclei-software/nuclei-sdk/tree/master/application/baremetal"
    click AppFreeRTOS "https://github.com/nuclei-software/nuclei-sdk/tree/master/application/freertos"
    click AppUCOSII "https://github.com/nuclei-software/nuclei-sdk/tree/master/application/ucosii"
    click AppRTThread "https://github.com/nuclei-software/nuclei-sdk/tree/master/application/rtthread"
    click AppThreadX "https://github.com/nuclei-software/nuclei-sdk/tree/master/application/threadx"

    %% Click Events for Supporting Tools
    click Tools "https://github.com/nuclei-software/nuclei-sdk/tree/master/tools"
    click IDE "https://github.com/nuclei-software/nuclei-sdk/tree/master/ideprojects"
    click Doc "https://github.com/nuclei-software/nuclei-sdk/tree/master/doc"
    click PackageJson "https://github.com/nuclei-software/nuclei-sdk/blob/master/package.json"
    click SetupSh "https://github.com/nuclei-software/nuclei-sdk/blob/master/setup.sh"
    click SetupBat "https://github.com/nuclei-software/nuclei-sdk/blob/master/setup.bat"
    click SetupPs1 "https://github.com/nuclei-software/nuclei-sdk/blob/master/setup.ps1"

    %% Styling
    class BS1,BS2,BS3 build
    class SoCOverall,SoCCommon,SoCBoard soc
    class NMSISFrame nmsis
    class OSFreeRTOS,OSUCOSII,OSRTThread,OSThreadX os
    class AppBaremetal,AppFreeRTOS,AppUCOSII,AppRTThread,AppThreadX app
    class Tools,IDE,Doc,PackageJson,SetupSh,SetupBat,SetupPs1 tools
    class ToolchainDebug ext

classDef build fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
classDef soc fill:#e6f0ff,stroke:#003399,stroke-width:2px;
classDef nmsis fill:#e6ffe6,stroke:#009933,stroke-width:2px;
classDef os fill:#fff4cc,stroke:#cc9900,stroke-width:2px;
classDef app fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
classDef tools fill:#e6ffff,stroke:#006666,stroke-width:2px;
classDef ext fill:#f2e6ff,stroke:#660099,stroke-width:2px;
```
