Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AIPentest CyberStrikeAI Application Composition Root

From Leeroopedia
Knowledge Sources
Domains Software_Architecture, Server_Lifecycle
Last Updated 2026-10-19 04:10 GMT

Overview

Architectural pattern that centralizes the construction and wiring of every subsystem (database, auth, MCP, agents, audit) into a single composition root, so dependencies are resolved in one place and the runtime lifecycle is driven by a context-aware entry point.

Description

A composition root is the single location in an application where object graphs are built and wired together. It solves the problem of scattered initialization: instead of each subsystem constructing its own dependencies (leading to hidden coupling, duplicate lifecycles, and untestable wiring), one function receives configuration and a logger and returns a fully-assembled application object.

In CyberStrikeAI, app.New is that root. It instantiates the toolguard manager, initializes the Eino ADK, creates the Gin router with CORS middleware, opens the SQLite database, attaches the RBAC store to the auth manager, and wires the MCP server, external MCP manager, agent, C2 subsystem, robot handlers, audit service, and storage handler. The companion RunWithContext starts the HTTP/MCP servers and blocks until the context is cancelled, then performs graceful shutdown. Because every subsystem is constructed here, the dependency direction is explicit and the lifecycle (start, run, shutdown) is a single coherent flow.

Usage

Use this pattern when building a long-running server that integrates many independent subsystems behind a single binary. It is the right choice when you need centralized, configuration-driven wiring, testable construction, and graceful shutdown coordinated across HTTP servers, background workers, and long-lived connections.

Theoretical Basis

The composition root inverts the conventional "each module builds what it needs" approach into a single dependency-injection point:

Config + Logger
     |
     v
 composition root  -- constructs -->  Subsystem A, Subsystem B, ...
     |                                       ^
     v                                       | (deps injected)
 App{ router, db, auth, mcp, agent, ... }
     |
     v
 RunWithContext(ctx)  -- blocks until ctx.Done() --> graceful shutdown

The root is the only place that knows about concrete implementations; every subsystem depends on interfaces. This keeps the graph acyclic and the wiring auditable.

Practical Guide

  • Keep the composition root the single place that imports concrete subsystem packages.
  • Inject a cancellable context so SIGINT/SIGTERM trigger a single graceful-shutdown path.
  • Construct dependencies in an order that respects availability (e.g. database before RBAC, config before toolguard).

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment