eclipse-wakaama / wakaama

Eclipse Wakaama is a C implementation of the Open Mobile Alliance's LightWeight M2M protocol (LWM2M).
BSD 3-Clause "New" or "Revised" License
502 stars 374 forks source link

Layered Architecture #798

Open LukasWoodtli opened 3 months ago

LukasWoodtli commented 3 months ago

This is a proposal of a cleaner architecture for Wakaama. This ensures that the library is modular and easier to maintain and extend.

Layered Architecture

wakaama_layers

Each layer is allowed to access code from itself and all layers below it (the layers are open). But it is not allowed to access code from higher layers.

Support Layer

This forms the basis for the library and supports an abstraction to the environment. They are necessary for the functionality of the library, but cannot be implemented in a generic way.

Abstractions in this layer include:

Customization in this layer is mainly achieved by link-time polymorphism: For example, a POSIX platform module implements the set of functions declared in platform.h and is linked to the library. Another module for and embedded system would implement the same functions. But only one of these modules are linked to the final library.

Base Layer

This layer contains the core LwM2M functionality.

Customization in this layer is done with conditional compilation (#ifdefs).

Add On's Layer

This layer includes additional functionality, that might be useful for some application, but that can be omitted for others. This might include modules for:

Modules from this layer can be added with the build system (CMake).

Folder Structure

The folder structure should reflect the architecture layers.

wakaama_folders

With a nice folder structure and a correct build system, some architectual rules can be enfored (i.e. no circular dependencies, accessing only lower layers).

LukasWoodtli commented 3 months ago

The images are created with PlantUML:

@startditaa (--no-shadows)
+------------------------------------------------+
| Add Ons (optional)                             |
|  +=----+ +=---------+                          |
|  | CLI | | Registry | ...                      |
|  +-----+ +----------+                          |
+------------------------------------------------+
| Base                                           |
|  +------+ +------+ +------+ +------+           |
|  | Core | | Data | | CoAP | | Util |           |
|  +------+ +------+ +------+ +------+           |
+------------------------------------------------+
| Support                                        |
|  +----------+ +-----------+ +------------+     |
|  | Platform | | Transport | | Event Loop | ... |
|  +----------+ +-----------+ +------------+     |
+------------------------------------------------+
@endditaa
@startsalt
{
{T
 + eclipse-wakaama
 ++ base
 +++ core
 +++ data
 +++ coap
 +++ util
 ++ support
 +++ platform
 +++ transport
 +++ event_loop
 +++ ...
 ++ addon
 +++ cli
 +++ registry
 +++ ...
}
}
@endsalt