# fuxiaoy/arnics-os architecture

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

- Interactive diagram: https://gitdiagram.com/fuxiaoy/arnics-os
- Repository: https://github.com/fuxiaoy/arnics-os

## Overview

##### Project type and purpose
- Project Type: Embedded RTOS-based “operating system” framework with modular “departments” (business logic), a data‐platform layer, and third-party libraries.
- Purpose: Provide a social-biomimetic business framework (“Powerful Social Biomimetic Business System Architecture”) atop hardware, with common utilities, a core scheduler, data services, and pluggable business modules.

##### High-level layering (the main components)
1. Hardware Layer
– The MCU and peripherals (STM32 series in templates).
2. Board Support Package & Drivers
– drivers/bsp, drivers/common, drivers/component
– document/templete dirs show how BSP is structured.
3. HAL / Port Layer
– port/ (delay, reprintf, portInclude)
– rtosInterface/ (FreeRTOS wrapper, entry_rtos_api, rtosPort)
4. Common Utilities
– common/ (memory allocation, timing utilities)
– Inc/ (global typedefs, includes)
– thirdParty/ (Assert, RingBuffer, ufLog, syslog, fatfs, etc.)
5. Core Scheduler & State Machine
– core/
- processTask (task dispatch)
- ptThread (protothreads)
- separateSM (state-machine separation)
- arnicaCore (initialization, main loop)
6. Routine / Task Manager
– routine/arnicsTaskManager (interfaces to schedule tasks on top of core)
7. Data Platform
– dataPlat/
- dataApi (public API)
- dataCore (engine)
- dataManager (JSON store, lists, key/value)
- dataObj (parameter, systemCfg, systemStatus)
8. Business Modules (“Departments”)
– dePartment/centerAdministrative, centerBusiness, centerConsole, centerEvent, centerGuard, centerMedia
– Each has an entry_*_api and a _process implementation.
9. Documentation & Pictures
10. Templates
– document/templete/… STM32F103 & STM32L431 examples

##### Relationships & interactions
- Hardware ↔ BSP/Drivers: low-level register access
- Drivers & Port ↔ RTOSInterface: hardware abstraction + OS primitives
- RTOSInterface ↔ Core: scheduling, task creation, inter-task communication
- Core ↔ Routine: routine triggers tasks via the core scheduler
- Core & Routine ↔ Departments: “entry_*_api” functions register or invoke department logic
- Departments ↔ Data Platform: read/write parameters, config, system status
- All layers ↔ Third-Party: link in libraries (e.g. nnom for neural nets, modContact for modem comm, rollDB for TS DB)
- Documentation: out-of-band, not in execution but helpful for design.

##### Architectural patterns & principles
- Layered Architecture: clear separation HW → drivers → OS → core → middleware → business logic
- Plugin/Module Pattern: each “department” is a pluggable service adhering to a common entry_*_api interface
- Data Abstraction: dataPlat provides a unified API over JSON stores, structured objects, and persistent cfg/status
- Protothreads & State Machines: core/ptThread and separateSM encapsulate lightweight threading/state logic

##### Essential elements
– Each layer clearly labeled (Hardware, BSP/Drivers, HAL/RTOS Interface, Core, Data Platform, Departments, Third-Party)
– An entry point: “arnicsCore.init()” or “main()” at the top of the core layer
– Data flows: parameter read/write → dataPlat → storage
– Task flows: department entry_*_api → core scheduler → ptThread run

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Hardware Layer"
        HW["MCU & Peripherals"]:::hardware
    end

    subgraph "BSP & Drivers"
        BSP["drivers/bsp"]:::drivers
        COMMONDRV["drivers/common"]:::drivers
        COMPDVR["drivers/component"]:::drivers
    end

    subgraph "HAL / Port Layer"
        PORT["port/"]:::hal
    end

    subgraph "RTOS Interface"
        RTOINTERF["rtosInterface/"]:::hal
    end

    subgraph "Core Scheduler & State Machine"
        ARNICORE["core/arnicsCore.c/.h\n(main, init)"]:::core
        PROC_TASK["core/processTask/*"]:::core
        PTTHREAD["core/ptThread/*"]:::core
        SEPSM["core/separateSM/*"]:::core
    end

    subgraph "Routine / Task Manager"
        TASKMGR["routine/arnicsTaskManager.*"]:::core
    end

    subgraph "Data Platform"
        DATAAPI["dataPlat/dataApi/*"]:::dataplat
        DATACORE["dataPlat/dataCore/*"]:::dataplat
        DATAMGR["dataPlat/dataManager/*"]:::dataplat
        DATAOBJ["dataPlat/dataObj/*"]:::dataplat
    end

    subgraph "Business Modules"
        ADMIN["centerAdministrative"]:::module
        BUSINESS["centerBusiness"]:::module
        CONSOLE["centerConsole"]:::module
        EVENT["centerEvent"]:::module
        GUARD["centerGuard"]:::module
        MEDIA["centerMedia"]:::module
    end

    subgraph "Third-Party Libraries"
        ASSERT["thirdParty/Assert"]:::thirdparty
        RING["thirdParty/ring"]:::thirdparty
        UFLOG["thirdParty/ufLog"]:::thirdparty
        SYSLOG["thirdParty/syslog"]:::thirdparty
        FATFS["thirdParty/packages/fatfs"]:::thirdparty
    end

    HW --> BSP
    HW --> COMMONDRV
    HW --> COMPDVR

    BSP --> PORT
    COMMONDRV --> PORT
    COMPDVR --> PORT

    PORT --> RTOINTERF

    RTOINTERF --> ARNICORE
    RTOINTERF --> PROC_TASK

    ARNICORE --> PROC_TASK
    PROC_TASK --> PTTHREAD
    PTTHREAD --> SEPSM

    ARNICORE --> TASKMGR

    TASKMGR --> ADMIN
    TASKMGR --> BUSINESS
    TASKMGR --> CONSOLE
    TASKMGR --> EVENT
    TASKMGR --> GUARD
    TASKMGR --> MEDIA

    ADMIN --> DATAAPI
    BUSINESS --> DATAAPI
    CONSOLE --> DATAAPI
    EVENT --> DATAAPI
    GUARD --> DATAAPI
    MEDIA --> DATAAPI

    DATAAPI --> DATACORE
    DATACORE --> DATAMGR
    DATAMGR --> DATAOBJ

    BSP -.-> ASSERT
    PORT -.-> RING
    RTOINTERF -.-> UFLOG
    ARNICORE -.-> SYSLOG
    DATAOBJ -.-> FATFS

    click BSP "https://github.com/fuxiaoy/arnics-os/tree/main/drivers/bsp/"
    click COMMONDRV "https://github.com/fuxiaoy/arnics-os/tree/main/drivers/common/"
    click COMPDVR "https://github.com/fuxiaoy/arnics-os/tree/main/drivers/component/"
    click PORT "https://github.com/fuxiaoy/arnics-os/tree/main/port/"
    click RTOINTERF "https://github.com/fuxiaoy/arnics-os/tree/main/rtosInterface/"
    click ARNICORE "https://github.com/fuxiaoy/arnics-os/blob/main/core/arnicsCore.c"
    click PROC_TASK "https://github.com/fuxiaoy/arnics-os/blob/main/core/processTask/processTask.c"
    click PTTHREAD "https://github.com/fuxiaoy/arnics-os/tree/main/core/ptThread/"
    click SEPSM "https://github.com/fuxiaoy/arnics-os/blob/main/core/separateSM/separate_core.c"
    click TASKMGR "https://github.com/fuxiaoy/arnics-os/blob/main/routine/arnicsTaskManager.cpp"
    click DATAAPI "https://github.com/fuxiaoy/arnics-os/blob/main/dataPlat/dataApi/dataApi.h"
    click DATACORE "https://github.com/fuxiaoy/arnics-os/blob/main/dataPlat/dataCore/dataCore.c"
    click DATAMGR "https://github.com/fuxiaoy/arnics-os/blob/main/dataPlat/dataManager/dataJson.c"
    click DATAOBJ "https://github.com/fuxiaoy/arnics-os/blob/main/dataPlat/dataObj/dataObj.c"
    click ADMIN "https://github.com/fuxiaoy/arnics-os/tree/main/dePartment/centerAdministrative/"
    click BUSINESS "https://github.com/fuxiaoy/arnics-os/tree/main/dePartment/centerBusiness/"
    click CONSOLE "https://github.com/fuxiaoy/arnics-os/tree/main/dePartment/centerConsole/"
    click EVENT "https://github.com/fuxiaoy/arnics-os/tree/main/dePartment/centerEvent/"
    click GUARD "https://github.com/fuxiaoy/arnics-os/tree/main/dePartment/centerGuard/"
    click MEDIA "https://github.com/fuxiaoy/arnics-os/tree/main/dePartment/centerMedia/"
    click ASSERT "https://github.com/fuxiaoy/arnics-os/tree/main/thirdParty/Assert/"
    click RING "https://github.com/fuxiaoy/arnics-os/tree/main/thirdParty/ring/"
    click UFLOG "https://github.com/fuxiaoy/arnics-os/tree/main/thirdParty/ufLog/"
    click SYSLOG "https://github.com/fuxiaoy/arnics-os/tree/main/thirdParty/syslog/"
    click FATFS "https://github.com/fuxiaoy/arnics-os/tree/main/thirdParty/packages/fatfs/"

    classDef hardware fill:#e0e0e0,stroke:#333;
    classDef drivers fill:#1f497d,stroke:#333,color:#fff;
    classDef hal fill:#2f5597,stroke:#333,color:#fff;
    classDef core fill:#76923c,stroke:#333,color:#fff;
    classDef dataplat fill:#f79646,stroke:#333;
    classDef module fill:#8064a2,stroke:#333,color:#fff;
    classDef thirdparty fill:#ffeb84,stroke:#333;
```
