# danikf/tik4net architecture

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

- Interactive diagram: https://gitdiagram.com/danikf/tik4net
- Repository: https://github.com/danikf/tik4net

## Overview

1. This repository is a multi-project .NET library centered on talking to MikroTik RouterOS devices. The architecture splits into a low-level protocol layer, a higher-level object mapper layer, test doubles, and several sample/tooling applications.

2. The core transport/protocol subsystem lives in `tik4net`. It defines the connection and command abstractions (`ITikConnection`, `ITikCommand`, sentence interfaces) plus concrete API protocol handling under `tik4net/Api`. This layer is responsible for opening the RouterOS API session, sending commands, parsing replies, handling async command execution/cancellation, and surfacing connection/command exceptions.

3. `tik4net/Api` is the wire-protocol boundary. The files here model MikroTik API sentence types such as done/re/trap/fatal, command parameters, tag sequencing, and sentence lists. This is the point where raw protocol messages are encoded/decoded before higher layers see them.

4. Discovery support is separate from the main API session path. The `tik4net/Mndp` folder contains MNDP helpers and binary parsing utilities for MikroTik network discovery, enabling a device-discovery flow distinct from authenticated API control.

5. `tik4net.objects` is the high-level O/R mapper layer built on top of `tik4net`. It introduces entity annotations and metadata (`TikEntityAttribute`, `TikPropertyAttribute`, `TikEntityMetadataCache`) and extension methods that translate between typed C# objects and RouterOS command/list operations.

6. The object model is organized by RouterOS domain area: `Interface`, `Ip`, `Ppp`, `Queue`, `Routing/BGP`, `System`, `Tool`, `User`, `Wireguard`, and `CapsMan`. Each entity file represents a concrete RouterOS resource and is intended to support CRUD-like operations through the mapper.

7. The mapper layer also contains reusable infrastructure for entity access and batching: property accessors, list merge behavior, command/connection extensions, and asynchronous loading context. These pieces form the bridge from typed entities to low-level API calls, so they are the main boundary between business-level model code and protocol code.

8. `tik4net.testing` provides fake implementations of commands, connections, parameters, and sentences. This is a test seam that lets unit tests exercise the object mapper and command code without requiring a live RouterOS device.

9. `tik4net.tests` is the integration/unit test suite for both the low-level API and the typed entity layer. The test names show coverage across connection behavior, CRUD, BGP, interfaces, firewall, hotspot, DNS, PPP, tool commands, MNDP discovery, and async/torch scenarios. This suite is the main consumer validating the end-to-end contract against RouterOS.

10. The `tik4net.examples` project is a usage sample library, not an application service. It demonstrates how consumers are expected to open a connection, issue commands, read lists, and save typed entities using the two-tier API.

11. There are two console front ends: `tik4net.console` and `tik4net.coreconsole`. These are thin executable wrappers around the library, likely used for manual experimentation and cross-runtime validation. The presence of both suggests support for older .NET Framework style and newer .NET Core style runtimes.

12. The `tik4net.torch` project is a focused executable around the RouterOS torch/traffic-monitoring capability. It likely exercises the tool-command subsystem and serves as a specialized sample or diagnostic utility.

13. The `Tools` directory contains semi-automatic code-generation utilities. `tik4net.entitygenerator` is a Windows Forms generator that parses/assembles typed entity classes, while `tik4net.entityWikiImporter` appears to import entity definitions from wiki content. These tools feed the `tik4net.objects` model layer by generating or updating entity code.

14. At the repo level, the main dependency flow is: tools and samples consume the library; tests consume both real and fake implementations; `tik4net.objects` depends on `tik4net`; and `tik4net` is the foundational protocol/runtime boundary. The architectural diagram should show `tik4net` as the base, `tik4net.objects` as the higher-level abstraction, and the executables/tools/tests as consumers around them.

Main entry points: [`tik4net.objects`](https://github.com/danikf/tik4net/blob/master/tik4net.objects) (tik4net.objects), [`tik4net`](https://github.com/danikf/tik4net/tree/master/tik4net) (tik4net), [`tik4net/Api`](https://github.com/danikf/tik4net/tree/master/tik4net/Api) (API layer), [`tik4net.tests`](https://github.com/danikf/tik4net/blob/master/tik4net.tests) (tik4net.tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core protocol"]
  node_tik4net["tik4net<br/>protocol runtime"]
  node_api["API layer<br/>wire protocol"]
  node_api_command["Commands<br/>api command<br/>[ApiCommand.cs]"]
  node_api_sentences["Sentences<br/>[ApiSentence.cs]"]
  node_mndp["MNDP<br/>discovery"]
end

subgraph group_objects["Object mapper"]
  node_objects["tik4net.objects<br/>object mapper<br/>[tik4net.objects]"]
  node_metadata["Metadata"]
  node_entity_ext["Entity ops<br/>mapper extensions"]
  node_async_ctx["Async load<br/>load context"]
  node_entity_domain["Entity models<br/>routeros entities<br/>[Interface.cs]"]
end

subgraph group_support["Test support"]
  node_tests["tik4net.tests<br/>test suite<br/>[tik4net.tests]"]
  node_testing["tik4net.testing<br/>test doubles<br/>[tik4net.testing]"]
end

subgraph group_apps["Samples and tools"]
  node_examples["Examples<br/>sample library<br/>[tik4net.examples]"]
  node_console["Console app<br/>sample cli<br/>[tik4net.console]"]
  node_coreconsole["Core console<br/>sample cli"]
  node_torch["Torch tool<br/>diagnostic cli<br/>[tik4net.torch]"]
  node_entitygen["Entity generator<br/>codegen tool"]
  node_wikiimporter["Wiki importer<br/>import tool"]
end

node_tik4net -->|"contains"| node_api
node_api -->|"defines"| node_api_command
node_api -->|"defines"| node_api_sentences
node_tik4net -->|"contains"| node_mndp
node_objects -->|"uses"| node_metadata
node_objects -->|"uses"| node_entity_ext
node_objects -->|"coordinates"| node_async_ctx
node_objects -->|"contains"| node_entity_domain
node_objects -->|"depends on"| node_tik4net
node_entity_domain -->|"annotated by"| node_metadata
node_entity_ext -->|"invokes"| node_api
node_testing -->|"fakes"| node_tik4net
node_tests -->|"validates"| node_tik4net
node_tests -->|"validates"| node_objects
node_tests -->|"uses"| node_testing
node_examples -->|"consumes"| node_tik4net
node_examples -->|"consumes"| node_objects
node_console -->|"wraps"| node_tik4net
node_coreconsole -->|"wraps"| node_tik4net
node_torch -->|"uses"| node_objects
node_entitygen -->|"generates"| node_objects
node_wikiimporter -->|"updates"| node_objects

click node_tik4net "https://github.com/danikf/tik4net/tree/master/tik4net"
click node_api "https://github.com/danikf/tik4net/tree/master/tik4net/Api"
click node_api_command "https://github.com/danikf/tik4net/blob/master/tik4net/Api/ApiCommand.cs"
click node_api_sentences "https://github.com/danikf/tik4net/blob/master/tik4net/Api/ApiSentence.cs"
click node_mndp "https://github.com/danikf/tik4net/tree/master/tik4net/Mndp"
click node_objects "https://github.com/danikf/tik4net/blob/master/tik4net.objects"
click node_metadata "https://github.com/danikf/tik4net/blob/master/tik4net.objects/TikEntityMetadata.cs"
click node_entity_ext "https://github.com/danikf/tik4net/blob/master/tik4net.objects/TikEntityObjectsExtensions.cs"
click node_async_ctx "https://github.com/danikf/tik4net/blob/master/tik4net.objects/AsyncLoadingContext.cs"
click node_entity_domain "https://github.com/danikf/tik4net/blob/master/tik4net.objects/Interface/Interface.cs"
click node_tests "https://github.com/danikf/tik4net/blob/master/tik4net.tests"
click node_testing "https://github.com/danikf/tik4net/blob/master/tik4net.testing"
click node_examples "https://github.com/danikf/tik4net/blob/master/tik4net.examples"
click node_console "https://github.com/danikf/tik4net/blob/master/tik4net.console"
click node_coreconsole "https://github.com/danikf/tik4net/blob/master/tik4net.coreconsole"
click node_torch "https://github.com/danikf/tik4net/blob/master/tik4net.torch"
click node_entitygen "https://github.com/danikf/tik4net/blob/master/Tools/tik4net.entitygenerator"
click node_wikiimporter "https://github.com/danikf/tik4net/blob/master/Tools/tik4net.entityWikiImporter"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tik4net,node_api,node_api_command,node_api_sentences,node_mndp toneBlue
class node_objects,node_metadata,node_entity_ext,node_async_ctx,node_entity_domain toneAmber
class node_tests,node_testing toneMint
class node_examples,node_console,node_coreconsole,node_torch,node_entitygen,node_wikiimporter toneRose
```

## Components

### Core protocol

Low-level RouterOS API and discovery runtime.

- [tik4net](https://github.com/danikf/tik4net/tree/master/tik4net): protocol runtime · Foundational connection, command, sentence, error, and MNDP discovery APIs. · `tik4net`
- [API layer](https://github.com/danikf/tik4net/tree/master/tik4net/Api): wire protocol · RouterOS API sentence encoding/decoding and connection session handling. · `tik4net/Api`
- [Commands](https://github.com/danikf/tik4net/blob/master/tik4net/Api/ApiCommand.cs): api command · Command and parameter representations plus command execution flow. · `tik4net/Api/ApiCommand.cs`
- [Sentences](https://github.com/danikf/tik4net/blob/master/tik4net/Api/ApiSentence.cs): api sentences · done/re/trap/fatal sentence models and sentence list/tag sequencing. · `tik4net/Api/ApiSentence.cs`
- [MNDP](https://github.com/danikf/tik4net/tree/master/tik4net/Mndp): discovery · Binary parsing helpers and MikroTik network discovery support. · `tik4net/Mndp`

### Object mapper

Typed entity layer built on top of the core protocol.

- [tik4net.objects](https://github.com/danikf/tik4net/blob/master/tik4net.objects): object mapper · Typed RouterOS object model and mapping extensions over the core API. · `tik4net.objects`
- [Metadata](https://github.com/danikf/tik4net/blob/master/tik4net.objects/TikEntityMetadata.cs): mapping metadata · Entity attributes, metadata cache, and property accessors for object mapping. · `tik4net.objects/TikEntityMetadata.cs`
- [Entity ops](https://github.com/danikf/tik4net/blob/master/tik4net.objects/TikEntityObjectsExtensions.cs): mapper extensions · Connection and command extensions for CRUD-style entity access and batching. · `tik4net.objects/TikEntityObjectsExtensions.cs`
- [Async load](https://github.com/danikf/tik4net/blob/master/tik4net.objects/AsyncLoadingContext.cs): load context · Asynchronous loading coordination for entity retrieval. · `tik4net.objects/AsyncLoadingContext.cs`
- [Entity models](https://github.com/danikf/tik4net/blob/master/tik4net.objects/Interface/Interface.cs): routeros entities · Typed RouterOS resources spanning interfaces, IP, PPP, routing, system, tools, users, wireguard, and capsman. · `tik4net.objects/Interface/Interface.cs`

### Test support

Fakes and test suite validating protocol and mapping behavior.

- [tik4net.tests](https://github.com/danikf/tik4net/blob/master/tik4net.tests): test suite · Integration and unit coverage for API, mapper, MNDP, and tool scenarios. · `tik4net.tests`
- [tik4net.testing](https://github.com/danikf/tik4net/blob/master/tik4net.testing): test doubles · Fake connections, commands, parameters, and sentences for isolated tests. · `tik4net.testing`

### Samples and tools

Console samples and code-generation utilities.

- [Examples](https://github.com/danikf/tik4net/blob/master/tik4net.examples): sample library · Usage examples for low-level commands and typed entity persistence. · `tik4net.examples`
- [Console app](https://github.com/danikf/tik4net/blob/master/tik4net.console): sample cli · Legacy console front end for manual experimentation. · `tik4net.console`
- [Core console](https://github.com/danikf/tik4net/blob/master/tik4net.coreconsole): sample cli · Modern console front end for cross-runtime validation. · `tik4net.coreconsole`
- [Torch tool](https://github.com/danikf/tik4net/blob/master/tik4net.torch): diagnostic cli · Focused executable around RouterOS torch and traffic monitoring. · `tik4net.torch`
- [Entity generator](https://github.com/danikf/tik4net/blob/master/Tools/tik4net.entitygenerator): codegen tool · WinForms tool for generating and updating typed entity classes. · `Tools/tik4net.entitygenerator`
- [Wiki importer](https://github.com/danikf/tik4net/blob/master/Tools/tik4net.entityWikiImporter): import tool · WinForms utility for importing entity definitions from wiki content. · `Tools/tik4net.entityWikiImporter`

## Connections

- tik4net → API layer: contains · Core library exposes the API protocol boundary.
- API layer → Commands: defines · Command and parameter abstractions live in the API layer.
- API layer → Sentences: defines · Protocol sentence models and sequencing are part of the wire layer.
- tik4net → MNDP: contains · Discovery support is shipped alongside the core runtime.
- tik4net.objects → Metadata: uses · Object mapping relies on entity metadata and property accessors.
- tik4net.objects → Entity ops: uses · Typed object operations are exposed through mapper extensions.
- tik4net.objects → Async load: coordinates · Entity loading uses async orchestration support.
- tik4net.objects → Entity models: contains · Domain-specific RouterOS entities are organized under the object layer.
- tik4net.objects → tik4net: depends on · Mapper builds on the low-level connection and command abstractions.
- Entity models → Metadata: annotated by · Entities are described using mapping attributes and cached metadata.
- Entity ops → API layer: invokes · High-level operations translate to protocol commands and sentence handling.
- tik4net.testing → tik4net: fakes · Test doubles stand in for the core protocol interfaces.
- tik4net.tests → tik4net: validates · Test suite exercises the low-level API and discovery flows.
- tik4net.tests → tik4net.objects: validates · Tests cover typed entity mapping and CRUD behavior.
- tik4net.tests → tik4net.testing: uses · Integration-style tests rely on fake implementations for isolation.
- Examples → tik4net: consumes · Samples demonstrate direct use of the protocol API.
- Examples → tik4net.objects: consumes · Samples also demonstrate typed entity access.
- Console app → tik4net: wraps · Legacy console is a thin executable over the library.
- Core console → tik4net: wraps · Core console is a thin executable over the library.
- Torch tool → tik4net.objects: uses · Torch executable likely exercises the tool-command and mapping layers.
- Entity generator → tik4net.objects: generates · Entity generator feeds the typed model layer.
- Wiki importer → tik4net.objects: updates · Wiki importer helps create or refresh entity definitions.
