# srl-labs/containerlab architecture

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

- Interactive diagram: https://gitdiagram.com/srl-labs/containerlab
- Repository: https://github.com/srl-labs/containerlab

## Overview

#### Purpose and entry points
Containerlab is a Go CLI for declaratively deploying, wiring, operating, and inspecting container/VM-based network labs. `main.go` launches the Cobra-style command surface rooted in `cmd/root.go`; lifecycle commands such as deploy, destroy, apply, exec, graph, and generate are implemented under `cmd/` and delegate to `core/`.

#### Topology ingestion and orchestration model
Topology definitions are represented by shared types and loaded/reconciled into a lab model before runtime changes occur. `core/topology.go` and `core/config.go` handle topology/config processing; `core/topology_reconcile.go` supports desired-versus-existing state reconciliation. `core/clab.go` is the central lab object coordinating runtime, nodes, links, state, and lifecycle options.

#### Deployment and lifecycle pipeline
Deployment flows from command input through `core/deploy.go` into staged node/link provisioning, while `core/apply.go` updates an existing lab toward a new desired topology. Start/stop/restart/destroy are distinct lifecycle operations in `core/start.go`, `core/stop.go`, and `core/destroy.go`. The dependency graph manager orders dependent components/stages and is a key concurrency/control boundary: `core/dependency_manager/dependency_manager.go`, `core/dependency_manager/depender_node_stage.go`.

#### Node-kind abstraction
`nodes/node.go` defines the common node contract; `nodes/node_registry.go` selects implementations by topology kind. Each kind encapsulates vendor/image-specific preparation, configuration, boot, and interface behavior, isolating the orchestration core from NOS and VM quirks. Representative implementations are `nodes/srl/srl.go`, `nodes/sros/sros.go`, and `nodes/linux/linux.go`; the repository includes many additional vendor and vrnetlab-oriented kinds.

#### Runtime boundary and infrastructure
The runtime layer abstracts container-engine operations behind `runtime/runtime.go`, with Docker as the principal implementation in `runtime/docker/docker.go` and optional Podman support in `runtime/podman/podman.go`; registration is assembled in `runtime/all/all.go`. It creates/manages containers, networks, events, authentication, and firewall rules. The host must provide Linux container/network primitives and a compatible Docker or Podman service.

#### Network-link realization
Logical topology links are converted into host/network-namespace connectivity by `links/apply.go`. Endpoint and link variants support veth, bridges, host attachments, macvlan, VXLAN, management networks, and stitched links; core definitions include `links/link.go`, `links/endpoint.go`, and `links/link_vxlan_stitched.go`. This is the material boundary between topology intent and Linux netlink/network namespace state.

#### State, artifacts, and operational outputs
Persistent lab/runtime state supports lifecycle and reconciliation through `core/state.go` and `core/runtime_state.go`. Deployment also produces user-facing artifacts such as inventory and SSH configuration via `core/inventory.go` and `core/sshconfig.go`. Graph rendering is generated from the resolved topology in `core/graph.go`, using packaged templates under `core/graph_templates/nextui`.

#### Supporting services and integrations
Certificate provisioning is a first-class deploy concern via `core/cert.go` and the local CA/storage implementation in `cert/`. Commands expose event streaming (`core/events/stream.go`) and utility integrations such as API server, terminal sharing, traffic impairment, and VXLAN tooling under `cmd/tools*.go`. Kubernetes kind nodes are supported as a specialized node implementation at `nodes/k8s_kind/k8s_kind.go`, rather than as the primary execution platform.

Main entry points: [`core/clab.go`](https://github.com/srl-labs/containerlab/blob/main/core/clab.go) (Lab coordinator), [`runtime/runtime.go`](https://github.com/srl-labs/containerlab/blob/main/runtime/runtime.go) (Container runtime), [`cmd/root.go`](https://github.com/srl-labs/containerlab/blob/main/cmd/root.go) (Lifecycle commands), [`core/deploy.go`](https://github.com/srl-labs/containerlab/blob/main/core/deploy.go) (Deploy pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI surface"]
  node_main["CLI entrypoint<br/>Go main<br/>[main.go]"]
  node_commands["Lifecycle commands<br/>Cobra commands<br/>[root.go]"]
end

subgraph group_core["Lab orchestration"]
  node_topology["Topology processing<br/>topology model<br/>[topology.go]"]
  node_lab{{"Lab coordinator<br/>core lab<br/>[clab.go]"}}
  node_deploy["Deploy pipeline<br/>lifecycle operation<br/>[deploy.go]"]
  node_apply["Apply reconciliation<br/>lifecycle operation<br/>[apply.go]"]
  node_lifecycle["Start / stop / destroy<br/>lifecycle operations<br/>[destroy.go]"]
  node_dependencies["Dependency manager<br/>stage scheduler"]
end

subgraph group_execution["Execution adapters"]
  node_node_registry["Node registry<br/>kind resolver<br/>[node_registry.go]"]
  node_node_kinds{{"Node-kind implementations<br/>node adapters<br/>[node.go]"}}
  node_runtime_registry["Runtime assembly<br/>runtime registry<br/>[all.go]"]
  node_runtime{{"Container runtime<br/>runtime interface<br/>[runtime.go]"}}
  node_docker["Docker runtime<br/>runtime implementation<br/>[docker.go]"]
  node_podman["Podman runtime<br/>runtime implementation<br/>[podman.go]"]
  node_links{{"Link realization<br/>netlink provisioning<br/>[apply.go]"}}
  node_host[("Linux host networking<br/>host infrastructure")]
end

subgraph group_outputs["State and outputs"]
  node_state[("Lab runtime state<br/>persistent state<br/>[state.go]")]
  node_artifacts["Operational artifacts<br/>generated outputs<br/>[inventory.go]"]
  node_certificates["Certificate provisioning<br/>deploy service<br/>[cert.go]"]
  node_events["Event streaming<br/>operational stream<br/>[stream.go]"]
end

node_main -->|"launches"| node_commands
node_commands -->|"loads input"| node_topology
node_commands -->|"deploy"| node_deploy
node_commands -->|"apply"| node_apply
node_commands -->|"operates"| node_lifecycle
node_topology -->|"builds desired lab"| node_lab
node_deploy -->|"provisions"| node_lab
node_apply -->|"reconciles"| node_lab
node_lifecycle -->|"controls"| node_lab
node_lab -->|"orders stages"| node_dependencies
node_dependencies -->|"provisions nodes"| node_node_registry
node_dependencies -->|"provisions links"| node_links
node_node_registry -->|"resolves kind"| node_node_kinds
node_node_kinds -->|"uses"| node_runtime
node_lab -->|"selects runtime"| node_runtime_registry
node_runtime_registry -->|"provides interface"| node_runtime
node_runtime -->|"implemented by"| node_docker
node_runtime -->|"implemented by"| node_podman
node_runtime -->|"manages"| node_host
node_links -->|"creates connectivity"| node_host
node_lab -->|"persists"| node_state
node_apply -->|"compares existing state"| node_state
node_deploy -->|"generates"| node_artifacts
node_deploy -->|"provisions"| node_certificates
node_runtime -->|"streams events"| node_events

click node_main "https://github.com/srl-labs/containerlab/blob/main/main.go"
click node_commands "https://github.com/srl-labs/containerlab/blob/main/cmd/root.go"
click node_topology "https://github.com/srl-labs/containerlab/blob/main/core/topology.go"
click node_lab "https://github.com/srl-labs/containerlab/blob/main/core/clab.go"
click node_deploy "https://github.com/srl-labs/containerlab/blob/main/core/deploy.go"
click node_apply "https://github.com/srl-labs/containerlab/blob/main/core/apply.go"
click node_lifecycle "https://github.com/srl-labs/containerlab/blob/main/core/destroy.go"
click node_dependencies "https://github.com/srl-labs/containerlab/blob/main/core/dependency_manager/dependency_manager.go"
click node_node_registry "https://github.com/srl-labs/containerlab/blob/main/nodes/node_registry.go"
click node_node_kinds "https://github.com/srl-labs/containerlab/blob/main/nodes/node.go"
click node_runtime_registry "https://github.com/srl-labs/containerlab/blob/main/runtime/all/all.go"
click node_runtime "https://github.com/srl-labs/containerlab/blob/main/runtime/runtime.go"
click node_docker "https://github.com/srl-labs/containerlab/blob/main/runtime/docker/docker.go"
click node_podman "https://github.com/srl-labs/containerlab/blob/main/runtime/podman/podman.go"
click node_links "https://github.com/srl-labs/containerlab/blob/main/links/apply.go"
click node_state "https://github.com/srl-labs/containerlab/blob/main/core/state.go"
click node_artifacts "https://github.com/srl-labs/containerlab/blob/main/core/inventory.go"
click node_certificates "https://github.com/srl-labs/containerlab/blob/main/core/cert.go"
click node_events "https://github.com/srl-labs/containerlab/blob/main/core/events/stream.go"

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_main,node_commands toneBlue
class node_topology,node_lab,node_deploy,node_apply,node_lifecycle,node_dependencies toneAmber
class node_node_registry,node_node_kinds,node_runtime_registry,node_runtime,node_docker,node_podman,node_links,node_host toneMint
class node_state,node_artifacts,node_certificates,node_events toneRose
```

## Components

### CLI surface

- [CLI entrypoint](https://github.com/srl-labs/containerlab/blob/main/main.go): Go main · `main.go`
- [Lifecycle commands](https://github.com/srl-labs/containerlab/blob/main/cmd/root.go): Cobra commands · Deploy, apply, destroy, exec, graph, and generate commands. · `cmd/root.go`

### Lab orchestration

- [Topology processing](https://github.com/srl-labs/containerlab/blob/main/core/topology.go): topology model · Loads configuration and reconciles desired topology. · `core/topology.go`
- [Lab coordinator](https://github.com/srl-labs/containerlab/blob/main/core/clab.go): core lab · Central object coordinating nodes, links, runtime, state, and lifecycle options. · `core/clab.go`
- [Deploy pipeline](https://github.com/srl-labs/containerlab/blob/main/core/deploy.go): lifecycle operation · Stages node and link provisioning. · `core/deploy.go`
- [Apply reconciliation](https://github.com/srl-labs/containerlab/blob/main/core/apply.go): lifecycle operation · Moves an existing lab toward desired topology. · `core/apply.go`
- [Start / stop / destroy](https://github.com/srl-labs/containerlab/blob/main/core/destroy.go): lifecycle operations · `core/destroy.go`
- [Dependency manager](https://github.com/srl-labs/containerlab/blob/main/core/dependency_manager/dependency_manager.go): stage scheduler · Orders dependent components and deployment stages. · `core/dependency_manager/dependency_manager.go`

### Execution adapters

- [Node registry](https://github.com/srl-labs/containerlab/blob/main/nodes/node_registry.go): kind resolver · Selects node implementations from topology kind. · `nodes/node_registry.go`
- [Node-kind implementations](https://github.com/srl-labs/containerlab/blob/main/nodes/node.go): node adapters · Vendor, Linux, VM, and kind-specific boot and interface behavior. · `nodes/node.go`
- [Runtime assembly](https://github.com/srl-labs/containerlab/blob/main/runtime/all/all.go): runtime registry · Registers supported container runtimes. · `runtime/all/all.go`
- [Container runtime](https://github.com/srl-labs/containerlab/blob/main/runtime/runtime.go): runtime interface · Abstracts containers, networks, events, auth, and firewall operations. · `runtime/runtime.go`
- [Docker runtime](https://github.com/srl-labs/containerlab/blob/main/runtime/docker/docker.go): runtime implementation · `runtime/docker/docker.go`
- [Podman runtime](https://github.com/srl-labs/containerlab/blob/main/runtime/podman/podman.go): runtime implementation · `runtime/podman/podman.go`
- [Link realization](https://github.com/srl-labs/containerlab/blob/main/links/apply.go): netlink provisioning · Converts logical links into namespace and host connectivity. · `links/apply.go`
- **Linux host networking**: host infrastructure · Container engine plus Linux container and network primitives.

### State and outputs

- [Lab runtime state](https://github.com/srl-labs/containerlab/blob/main/core/state.go): persistent state · Supports lifecycle operations and reconciliation. · `core/state.go`
- [Operational artifacts](https://github.com/srl-labs/containerlab/blob/main/core/inventory.go): generated outputs · Inventory, SSH configuration, and resolved-topology graph output. · `core/inventory.go`
- [Certificate provisioning](https://github.com/srl-labs/containerlab/blob/main/core/cert.go): deploy service · Local CA and certificate storage for lab deployment. · `core/cert.go`
- [Event streaming](https://github.com/srl-labs/containerlab/blob/main/core/events/stream.go): operational stream · `core/events/stream.go`

## Connections

- CLI entrypoint → Lifecycle commands: launches
- Lifecycle commands → Topology processing: loads input
- Lifecycle commands → Deploy pipeline: deploy
- Lifecycle commands → Apply reconciliation: apply
- Lifecycle commands → Start / stop / destroy: operates
- Topology processing → Lab coordinator: builds desired lab
- Deploy pipeline → Lab coordinator: provisions
- Apply reconciliation → Lab coordinator: reconciles
- Start / stop / destroy → Lab coordinator: controls
- Lab coordinator → Dependency manager: orders stages
- Dependency manager → Node registry: provisions nodes
- Dependency manager → Link realization: provisions links
- Node registry → Node-kind implementations: resolves kind
- Node-kind implementations → Container runtime: uses
- Lab coordinator → Runtime assembly: selects runtime
- Runtime assembly → Container runtime: provides interface
- Container runtime → Docker runtime: implemented by
- Container runtime → Podman runtime: implemented by
- Container runtime → Linux host networking: manages
- Link realization → Linux host networking: creates connectivity
- Lab coordinator → Lab runtime state: persists
- Apply reconciliation → Lab runtime state: compares existing state
- Deploy pipeline → Operational artifacts: generates
- Deploy pipeline → Certificate provisioning: provisions
- Container runtime → Event streaming: streams events
