# ankraft/coapthon3-acme-cse architecture

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

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

## Overview

##### Project’s nature and purpose
– It’s a protocol library (not a monolithic app).
– Core purpose: send/receive CoAP messages, support proxies (forward/reverse/HTTP), caching, blockwise transfers, and extensibility for oneM2M CSE.

##### File structure to find main components
– “coapthon” package is the heart, with subpackages:
- layers (blocklayer, cachelayer, forwardLayer, messagelayer, observelayer, requestlayer, resourcelayer)
- client (CoAP client logic)
- server (CoAP server logic)
- forward_proxy, reverse_proxy, http_proxy
- caching (cache implementations)
- messages (message/option/request/response models)
- resources (Resource abstraction)
- serializer, transaction, utils
– Top-level scripts wire everything up: coapclient.py, coapserver.py, coapforwardproxy.py, coapreverseproxy.py, collect*.py, plugtest.py, etc.

##### Pull architecture hints from the README
– It’s a Python3 port with oneM2M CSE forks: custom options, blockwise fixes, plug-in request layers, type hints.

a. Main components:
- Application scripts (CLI tools): coapclient, coapserver, proxies, example servers/clients.
- Library core: layers stack, message serializer, transaction manager, resource manager.
- Caching subsystem.
- Network I/O (UDP socket layer) and optional Twisted reactor.
- External entities: CoAP devices/endpoints, HTTP clients (for HTTP→CoAP proxy), oneM2M CSE backend.
b. Relationships & interactions:
– Client script → invokes client layer → builds CoAP Request → passes through message layer → block/cache/observe layers as needed → UDP socket → remote CoAP server.
– Server script → listens on UDP → passes incoming bytes → serializer → message layer → resource layer → custom RequestLayer (oneM2M logic) → response flows back.
– Proxies sit between client & server paths, reusing the same layers but altering flows (forward vs. reverse).
– Caching layer intercepts GET requests/responses.
c. Architectural patterns/design principles:
– Layered pipeline (chain of responsibility) for message processing.
– Plug-in extensibility: new RequestLayer implementations, custom options.
– Separation of concerns: messaging, transport, caching, resource dispatch.
– Transaction management for reliability.
d. Key technologies/frameworks:
– Python3 (type hints).
– Optional Twisted support.
– Standard UDP sockets.
– XML mapping file for reverse proxy (reverse_proxy_mapping.xml).

##### Detail
– Show how scripts instantiate and wire these modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Scripts
    subgraph "Application Scripts"
        coapclient["CoAP Client Script"]:::app
        coapserver["CoAP Server Script"]:::app
        coapforwardproxy["CoAP Forward Proxy Script"]:::app
        coapreverseproxy["CoAP Reverse Proxy Script"]:::app
        collectclient["Collect Client Script"]:::app
        collectserver["Collect Server Script"]:::app
        plugtest["Plugtest Script"]:::app
        httpcoapproxy["HTTP↔CoAP Proxy Script"]:::app
    end

    %% Core Engine Layers
    subgraph "Layered Engine"
        serializer["Serializer"]:::transport
        messagelayer["MessageLayer"]:::processing
        cachelayer["CacheLayer"]:::processing
        blocklayer["BlockLayer"]:::processing
        observelayer["ObserveLayer"]:::processing
        forwardlayer["ForwardLayer"]:::processing
        requestlayer["RequestLayer"]:::processing
        resourcelayer["ResourceLayer"]:::processing
        transactionmgr["TransactionManager"]:::processing
        udpsocket["UDP Socket I/O"]:::transport
    end

    %% Caching Subsystem
    CachingDB["Caching Subsystem"]:::cache

    %% External Systems
    CoAPDevice["CoAP Device/Endpoint"]:::external
    OneM2M_CSE["oneM2M CSE Backend"]:::external

    %% Data Flow
    coapclient -->|"CoAP message"| serializer
    httpcoapproxy -->|"HTTP request"| serializer
    collectclient --> serializer
    plugtest --> serializer

    serializer --> messagelayer
    messagelayer --> cachelayer
    cachelayer --> blocklayer
    blocklayer --> observelayer
    observelayer --> forwardlayer
    forwardlayer --> requestlayer
    requestlayer --> resourcelayer
    resourcelayer --> transactionmgr
    transactionmgr --> udpsocket
    udpsocket -->|"UDP datagram"| CoAPDevice
    CoAPDevice -->|"UDP datagram"| udpsocket
    udpsocket --> resourcelayer
    resourcelayer --> CoAPDevice

    cachelayer --- CachingDB
    coapserver --> udpsocket
    coapreverseproxy --> udpsocket
    collectserver --> udpsocket

    CoAPDevice --> OneM2M_CSE
    OneM2M_CSE --- requestlayer

    %% Click Events
    click coapclient "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapclient.py"
    click coapserver "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapserver.py"
    click coapforwardproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapforwardproxy.py"
    click coapreverseproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapreverseproxy.py"
    click collectclient "https://github.com/ankraft/coapthon3-acme-cse/blob/master/collectclient.py"
    click collectserver "https://github.com/ankraft/coapthon3-acme-cse/blob/master/collectserver.py"
    click plugtest "https://github.com/ankraft/coapthon3-acme-cse/blob/master/plugtest.py"
    click httpcoapproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/http_proxy/http_coap_proxy.py"

    click serializer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/serializer.py"
    click messagelayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/messagelayer.py"
    click cachelayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/cachelayer.py"
    click blocklayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/blocklayer.py"
    click observelayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/observelayer.py"
    click forwardlayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/forwardLayer.py"
    click requestlayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/requestlayer.py"
    click resourcelayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/layers/resourcelayer.py"

    click CachingDB "https://github.com/ankraft/coapthon3-acme-cse/tree/master/coapthon/caching"
    click CachingDB "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/caching/cache.py"
    click CachingDB "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/caching/coapcache.py"
    click CachingDB "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/caching/coaplrucache.py"

    click CoAPDevice "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/messages/message.py"
    click CoAPDevice "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/messages/option.py"
    click CoAPDevice "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/messages/request.py"
    click CoAPDevice "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/messages/response.py"

    click OneM2M_CSE "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/resources/resource.py"
    click OneM2M_CSE "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/resources/remoteResource.py"

    click transactionmgr "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/transaction.py"
    click serializer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/utils.py"
    click serializer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/defines.py"

    click forwardlayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/forward_proxy/coap.py"
    click coapforwardproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapforwardproxy.py"

    click requestlayer "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/reverse_proxy/coap.py"
    click coapreverseproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapreverseproxy.py"
    click OneM2M_CSE "https://github.com/ankraft/coapthon3-acme-cse/blob/master/reverse_proxy_mapping.xml"
    click coapforwardproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/forward_proxy/coap.py"
    click coapreverseproxy "https://github.com/ankraft/coapthon3-acme-cse/blob/master/coapthon/reverse_proxy/coap.py"

    %% Styles
    classDef app fill:#FFA500,stroke:#333,stroke-width:1px
    classDef transport fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef processing fill:#90EE90,stroke:#333,stroke-width:1px
    classDef cache fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px
```
