# snwfke/markline architecture

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

- Interactive diagram: https://gitdiagram.com/snwfke/markline
- Repository: https://github.com/snwfke/markline

## Overview

#### Purpose and runtime

markline is a Lua library embedded into DCS missions to turn F10 map-marker text into command-line-style AI/mission commands. It is loaded through a Mission Editor `DO SCRIPT FILE` action, then consumed by mission Lua scripts. The repository’s implementation is concentrated in `snwfke_markline.lua`.

#### Entry points and public API

The script exposes a global/module API centered on `mark.cli()`, which creates a CLI instance. Mission authors register command callbacks such as `cli:on("ping", handler)`. The same runtime automatically attaches to DCS marker events when the DCS `world.addEventHandler` API is available.

Paths:
- `snwfke_markline.lua`
- `README.md`
- `USAGE.md`

#### Command registration and schema boundary

Commands are declared through the CLI API rather than hard-coded mission behavior. Each registered command associates a command name with callback logic and, per the documentation, supports schemas/flags. This separates reusable parsing and validation machinery in the library from mission-specific AI actions in the consuming mission script.

Paths:
- `snwfke_markline.lua`
- `USAGE.md`

#### Marker-event ingestion

DCS is the external event source. The library registers an event handler with `world.addEventHandler`, receiving marker lifecycle events rather than requiring callers to build their own handler. The event layer must consistently handle marker creation, updates, and deletion, which is the main control boundary between DCS simulation state and markline command processing.

Paths:
- `snwfke_markline.lua`
- `README.md`

#### Parse, validate, and dispatch pipeline

The primary flow is:

1. A player creates or edits an F10 marker in DCS.
2. DCS delivers the marker event to markline’s registered handler.
3. Marker text is treated as CLI input and parsed into command/arguments/flags.
4. The command is matched against registered definitions and schema rules.
5. The associated callback receives command context and invokes DCS mission APIs, such as `trigger.action.outText` or AI-control APIs.

This pipeline keeps command interpretation inside markline while side effects remain in mission callbacks.

Paths:
- `snwfke_markline.lua`
- `README.md`
- `USAGE.md`

#### Mission integration boundary

markline is not a standalone executable or web service. Its deployment unit is the Lua script copied into a `.miz` mission and loaded at mission start. Mission code instantiates the CLI and defines command behavior; DCS provides the Lua runtime, marker UI, event system, and mission-action APIs.

Paths:
- `snwfke_markline.lua`
- `README.md`

#### Extensibility model

The intended extension point is command definition: add commands, schemas, and callbacks without modifying core parsing/event machinery. Changes to parser semantics or event behavior belong in the single library implementation; mission-level behavior belongs in the mission script that calls `mark.cli()`.

Paths:
- `snwfke_markline.lua`
- `USAGE.md`

Main entry points: [`snwfke_markline.lua`](https://github.com/snwfke/markline/blob/main/snwfke_markline.lua) (Marker event handler), [`USAGE.md`](https://github.com/snwfke/markline/blob/main/USAGE.md) (Usage documentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dcs["DCS Mission Runtime"]
  node_f10["F10 map markers<br/>DCS UI"]
  node_world["DCS event system<br/>world API"]
  node_mission_apis["Mission and AI APIs<br/>DCS APIs"]
end

subgraph group_markline["markline Library"]
  node_library["markline runtime<br/>Lua library"]
  node_event_handler["Marker event handler<br/>event adapter"]
  node_parser["CLI parser"]
  node_registry["Command registry<br/>schema dispatcher"]
  node_cli_api["mark.cli() API<br/>public API"]
end

subgraph group_mission["Mission Extension"]
  node_mission_script["Mission Lua script<br/>consumer script"]
  node_commands["Command callbacks<br/>extension point"]
  node_miz["Mission .miz package<br/>deployment unit"]
end

node_docs["Usage documentation<br/>[USAGE.md]"]

node_miz -->|"loads"| node_library
node_mission_script -->|"creates CLI"| node_cli_api
node_cli_api -->|"owns definitions"| node_registry
node_mission_script -->|"registers"| node_commands
node_commands -->|"adds commands and schemas"| node_registry
node_library -->|"initializes"| node_event_handler
node_event_handler -->|"registers with"| node_world
node_f10 -->|"creates marker events"| node_world
node_world -->|"delivers create, update, delete"| node_event_handler
node_event_handler -->|"passes marker text"| node_parser
node_parser -->|"command and arguments"| node_registry
node_registry -->|"dispatches validated context"| node_commands
node_commands -->|"invokes AI or mission actions"| node_mission_apis
node_docs -.->|"guides integration"| node_mission_script

click node_library "https://github.com/snwfke/markline/blob/main/snwfke_markline.lua"
click node_event_handler "https://github.com/snwfke/markline/blob/main/snwfke_markline.lua"
click node_parser "https://github.com/snwfke/markline/blob/main/snwfke_markline.lua"
click node_registry "https://github.com/snwfke/markline/blob/main/snwfke_markline.lua"
click node_cli_api "https://github.com/snwfke/markline/blob/main/snwfke_markline.lua"
click node_docs "https://github.com/snwfke/markline/blob/main/USAGE.md"

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_f10,node_world,node_mission_apis toneBlue
class node_library,node_event_handler,node_parser,node_registry,node_cli_api toneAmber
class node_mission_script,node_commands,node_miz toneMint
class node_docs toneNeutral
```

## Components

### DCS Mission Runtime

- **F10 map markers**: DCS UI · Players create or edit command text.
- **DCS event system**: world API · Delivers marker lifecycle events.
- **Mission and AI APIs**: DCS APIs · Receives mission callback side effects.

### markline Library

- [markline runtime](https://github.com/snwfke/markline/blob/main/snwfke_markline.lua): Lua library · Embedded library and public global API. · `snwfke_markline.lua`
- [Marker event handler](https://github.com/snwfke/markline/blob/main/snwfke_markline.lua): event adapter · Registers through world.addEventHandler when available. · `snwfke_markline.lua`
- [CLI parser](https://github.com/snwfke/markline/blob/main/snwfke_markline.lua): parser · Converts marker text into commands, arguments, and flags. · `snwfke_markline.lua`
- [Command registry](https://github.com/snwfke/markline/blob/main/snwfke_markline.lua): schema dispatcher · Matches commands and applies definition schemas. · `snwfke_markline.lua`
- [mark.cli() API](https://github.com/snwfke/markline/blob/main/snwfke_markline.lua): public API · Creates CLI instances for command registration. · `snwfke_markline.lua`

### Mission Extension

- **Mission Lua script**: consumer script · Defines mission-specific command behavior.
- **Command callbacks**: extension point · Registered with cli:on(name, handler).
- **Mission .miz package**: deployment unit · Loads the library at mission start via DO SCRIPT FILE.

### Other components

- [Usage documentation](https://github.com/snwfke/markline/blob/main/USAGE.md): documentation · Describes loading, command schemas, flags, and callbacks. · `USAGE.md`

## Connections

- Mission .miz package → markline runtime: loads · Mission Editor DO SCRIPT FILE action.
- Mission Lua script → mark.cli() API: creates CLI
- mark.cli() API → Command registry: owns definitions
- Mission Lua script → Command callbacks: registers
- Command callbacks → Command registry: adds commands and schemas
- markline runtime → Marker event handler: initializes
- Marker event handler → DCS event system: registers with · Uses world.addEventHandler.
- F10 map markers → DCS event system: creates marker events
- DCS event system → Marker event handler: delivers create, update, delete
- Marker event handler → CLI parser: passes marker text
- CLI parser → Command registry: command and arguments
- Command registry → Command callbacks: dispatches validated context
- Command callbacks → Mission and AI APIs: invokes AI or mission actions
- Usage documentation → Mission Lua script: guides integration
