# ankraft/acme-onem2m-cse architecture

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

- Interactive diagram: https://gitdiagram.com/ankraft/acme-onem2m-cse
- Repository: https://github.com/ankraft/acme-onem2m-cse

## Overview

##### Project Type and Purpose
- The project is an open-source oneM2M Common Service Entity (CSE) middleware, implemented in Python, aimed at education and easy extensibility.
- It provides multiple network interfaces (CoAP, HTTP, MQTT, WebSocket), a resource-oriented service layer, pluggable storage backends, and both CLI (textui) and browser-based (webui) user interfaces.

##### File Structure
- Top-Level Packages
– acme/protocols: network servers/clients for CoAP, HTTP, MQTT, WebSocket
– acme/runtime: bootstrapping, configuration, script manager, logging, storage initialization
– acme/services: business-logic managers (RequestManager, RegistrationManager, NotificationManager, etc.)
– acme/resources: oneM2M resource classes and their “Annc” variants
– acme/databases: binding modules for PostgreSQL and TinyDB
– acme/textui & acme/webui: CLI and web front-ends
- Supporting Directories
– acme/etc & acme/helpers: shared utilities, enums, locks, caches, geo, date, ID generators
– acme/init: startup scripts, AS-style configuration, demo content
– docs, tests, tools, and Docker for documentation, CI, testing, and deployment

##### README for Additional Insights
- Confirms oneM2M compliance subset, target audience (educational), tech stack (Python 3.10), and maintenance status.
- Points to external documentation, change history, and community channels.

##### Main Components
a. External Entities
– oneM2M AEs or devices (“Clients”)
– MQTT Broker (for MQTTClient module)
– Web browser (for webui)
– Terminal (for textui CLI)
b. ACME CSE Application Container
– Protocol Layer
- CoAPServer, HttpServer, WebSocketServer, MQTTClient
– Runtime Layer
- Configuration loader, Storage initializer (DBBinding), ScriptManager, Logging
– Service Layer
- RequestManager → Dispatcher → various Manager classes (Registration, Notification, etc.)
– Resource Model
- Resource classes (CNT, CIN, AE, etc.) → CRUD operations, Announceable vs. Announced
– Persistence Layer
- Interfaces → PostgreSQLBinding, TinyDBBinding
– Presentation Layer
- TextUI (ACMETuiApp), WebUI (webUI.py + static assets)
– Init & Scripts
- Startup scripts, demo code, attribute-policy files
c. Configuration
– acme/init and acme/runtime/configurations modules supplying JSON/INI defaults

##### Relationships and Data Flows
- Clients → Protocol Layer (incoming REST/CoAP/MQTT/WS requests)
- Protocol Layer → Runtime → Service Layer (RequestManager)
- Service Layer → Resource Model → Persistence Layer (storage bindings)
- Service Layer → NotificationManager → Protocol Layer (outbound notifications)
- Runtime → ScriptManager → custom AS scripts (init, tests)
- Presentation Layer queries Service Layer / Runtime for status and invokes operations

##### Architectural Patterns and Principles
- Layered Architecture: Protocol → Runtime → Services → Resources → Storage
- Plugin-style Storage Binding: two DBBinding implementations loaded via Configuration
- Modular Protocol Adapters: each protocol lives in its own module and registers with the Dispatcher
- Separation of Concerns: distinct packages for helpers/utilities vs. business logic vs. I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    subgraph "External Clients" 
        direction TB
        AE["oneM2M AE/Device"]:::external
    end
    MQTTBroker["MQTT Broker"]:::external
    WebBrowser["Web Browser"]:::external
    Terminal["Terminal (CLI)"]:::external

    %% ACME CSE Middleware Container
    subgraph "ACME CSE Middleware"
        direction TB

        %% Protocol Layer
        subgraph "Protocol Layer"
            direction TB
            CoAPServer["acme.protocols.CoAPServer"]:::protocol
            HttpServer["acme.protocols.HttpServer"]:::protocol
            WebSocketServer["acme.protocols.WebSocketServer"]:::protocol
            MQTTClient["acme.protocols.MQTTClient"]:::protocol
        end

        %% Runtime Layer
        subgraph "Runtime Layer"
            direction TB
            CSE["acme.runtime.CSE"]:::core
            Configuration["acme.runtime.Configuration"]:::core
            Configs["acme/runtime/configurations/"]:::core
            StorageInit["acme.runtime.Storage"]:::core
            ScriptManager["acme.runtime.ScriptManager"]:::core
            Logging["acme.runtime.Logging"]:::core
            Onboarding["acme.runtime.Onboarding"]:::core
            Console["acme.runtime.Console"]:::core
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            RequestManager["acme.services.RequestManager"]:::core
            Dispatcher["acme.services.Dispatcher"]:::core
            RegistrationManager["acme.services.RegistrationManager"]:::core
            NotificationManager["acme.services.NotificationManager"]:::core
            AnnouncementManager["acme.services.AnnouncementManager"]:::core
            GroupManager["acme.services.GroupManager"]:::core
            SecurityManager["acme.services.SecurityManager"]:::core
            OtherManagers["acme.services/*"]:::core
        end

        %% Resource Model
        subgraph "Resource Model"
            direction TB
            ResourceBase["acme.resources.Resource"]:::data
            Announceable["acme.resources.AnnounceableResource"]:::data
            Announced["acme.resources.AnnouncedResource"]:::data
            ConcreteResources["acme/resources/*.py"]:::data
            MgmtObjs["acme.resources.mgmtobjs/"]:::data
        end

        %% Persistence Layer
        subgraph "Persistence Layer"
            direction TB
            DBBinding["acme.databases.DBBinding"]:::data
            PostgreSQL["acme.databases.PostgreSQLBinding"]:::data
            TinyDB["acme.databases.TinyDBBinding"]:::data
        end

        %% Presentation Layer
        subgraph "Presentation Layer"
            direction TB
            TextUI["acme.textui.ACMETuiApp"]:::ui
            CLICommands["acme.textui/*"]:::ui
            WebUIServer["acme.webui.webUI"]:::ui
            WebAssets["acme.webui/web/{css,js,img}/"]:::ui
        end

        %% Init & Scripts
        subgraph "Init & Scripts"
            direction TB
            InitDir["acme/init/"]:::init
            DefaultConfig["acme/init/acme.ini.default"]:::init
            DocConfig["acme/init/configurations.docmd"]:::init
        end
    end

    %% Data Flows
    AE -->|"CoAP/REST/WS/MQTT requests"| CoAPServer
    AE --> HttpServer
    AE --> WebSocketServer
    AE --> MQTTClient
    MQTTBroker --> MQTTClient
    WebBrowser --> WebUIServer
    Terminal --> TextUI

    CoAPServer -->|invokes| CSE
    HttpServer --> CSE
    WebSocketServer --> CSE
    MQTTClient --> CSE

    CSE --> Configuration
    CSE --> StorageInit
    CSE --> ScriptManager
    CSE --> Logging
    CSE --> Onboarding
    Console --> CSE

    CSE --> RequestManager
    RequestManager --> Dispatcher
    Dispatcher --> RegistrationManager
    Dispatcher --> NotificationManager
    Dispatcher --> AnnouncementManager
    Dispatcher --> GroupManager
    Dispatcher --> SecurityManager
    Dispatcher --> OtherManagers

    NotificationManager -->|notifications| CoAPServer
    NotificationManager --> HttpServer
    NotificationManager --> WebSocketServer
    NotificationManager --> MQTTClient

    Dispatcher --> ResourceBase
    ResourceBase --> Announceable
    ResourceBase --> Announced
    ResourceBase --> ConcreteResources
    ResourceBase --> MgmtObjs

    Dispatcher --> DBBinding
    DBBinding --> PostgreSQL
    DBBinding --> TinyDB

    TextUI --> RequestManager
    WebUIServer --> RequestManager
    WebUIServer --> CSE

    ScriptManager --> InitDir

    %% Click Events
    click CoAPServer "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/protocols/CoAPServer.py"
    click HttpServer "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/protocols/HttpServer.py"
    click WebSocketServer "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/protocols/WebSocketServer.py"
    click MQTTClient "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/protocols/MQTTClient.py"
    click CSE "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/CSE.py"
    click Configuration "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/Configuration.py"
    click Configs "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/runtime/configurations/"
    click StorageInit "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/Storage.py"
    click ScriptManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/ScriptManager.py"
    click Logging "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/Logging.py"
    click Onboarding "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/Onboarding.py"
    click Console "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/runtime/Console.py"
    click RequestManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/RequestManager.py"
    click Dispatcher "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/Dispatcher.py"
    click RegistrationManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/RegistrationManager.py"
    click NotificationManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/NotificationManager.py"
    click AnnouncementManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/AnnouncementManager.py"
    click GroupManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/GroupManager.py"
    click SecurityManager "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/services/SecurityManager.py"
    click OtherManagers "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/services/"
    click ResourceBase "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/resources/Resource.py"
    click Announceable "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/resources/AnnounceableResource.py"
    click Announced "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/resources/AnnouncedResource.py"
    click ConcreteResources "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/resources/"
    click MgmtObjs "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/resources/mgmtobjs/"
    click DBBinding "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/databases/DBBinding.py"
    click PostgreSQL "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/databases/PostgreSQLBinding.py"
    click TinyDB "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/databases/TinyDBBinding.py"
    click TextUI "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/textui/ACMETuiApp.py"
    click CLICommands "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/textui/"
    click WebUIServer "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/webui/webUI.py"
    click WebAssets "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/webui/web/"
    click InitDir "https://github.com/ankraft/acme-onem2m-cse/tree/master/acme/init/"
    click DefaultConfig "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/init/acme.ini.default"
    click DocConfig "https://github.com/ankraft/acme-onem2m-cse/blob/master/acme/init/configurations.docmd"

    %% Styles
    classDef external fill:#f0f0f0,stroke:#333
    classDef protocol fill:#cce5ff,stroke:#333
    classDef core fill:#d4edda,stroke:#333
    classDef data fill:#fff3cd,stroke:#333
    classDef ui fill:#e2d5f0,stroke:#333
    classDef init fill:#f8d7da,stroke:#333
```
