Skip to content

System Architecture

OSTwin is built from four independent subsystems that communicate through the filesystem. There is no central process, no message broker, and no shared database. This section maps the complete system architecture.

Architecture Overview

┌──────────────────────────────────────────────────────────┐
│ User / CLI │
└──────────────┬───────────────────────────┬───────────────┘
│ │
┌──────────▼──────────┐ ┌──────────▼──────────┐
│ Engine (PS) │ │ Dashboard (Py+JS) │
│ │ │ │
│ Invoke-Agent.ps1 │ │ FastAPI backend │
│ Build-DAG.ps1 │◄───►│ Next.js frontend │
│ New-WarRoom.ps1 │ │ SSE streaming │
│ Resolve-*.ps1 │ │ │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
┌──────────▼───────────────────────────▼──────────┐
│ Filesystem (.agents/) │
│ plans/ war-rooms/ roles/ skills/ ledger.jsonl │
└──────────┬───────────────────────────┬──────────┘
│ │
┌──────────▼──────────┐ ┌──────────▼──────────┐
│ MCP Servers (Py) │ │ Bot (TS) │
│ │ │ │
│ memory server │ │ Discord adapter │
│ warroom server │ │ Telegram adapter │
│ dashboard server │ │ Slack adapter │
│ skills server │ │ │
└─────────────────────┘ └─────────────────────┘

Subsystem 1: Engine (PowerShell)

The engine is the orchestration core. Written in PowerShell, it manages plan execution, agent invocation, and lifecycle enforcement.

Key Scripts

ScriptPurpose
Invoke-Agent.ps1Universal agent runner — assembles prompt, resolves role/skills/MCP, launches LLM session
Build-DAG.ps1Kahn’s algorithm — converts epic dependencies into executable waves
New-WarRoom.ps1War-room scaffolding — creates directory structure, config, lifecycle
Get-NextWave.ps1Wave resolution — determines which epics can execute next
Resolve-Role.ps15-tier role discovery
Resolve-Skills.ps13-tier skill resolution with union merge
Resolve-McpConfig.ps14-tier MCP configuration merge
Set-RoomStatus.ps1Lifecycle transition with validation
Watch-Timeouts.ps1Timeout enforcement loop
New-Role.ps1Dynamic role creation
Invoke-PlanReview.ps1Plan review orchestration and DAG generation

Engine Responsibilities

  • Parse PLAN.md and build the DAG
  • Create war-rooms for each wave of epics
  • Invoke agents in the correct sequence within each room
  • Monitor timeouts and enforce lifecycle transitions
  • Handle retries and escalations
  • Coordinate cross-room memory injection

Subsystem 2: Dashboard (FastAPI + Next.js)

The dashboard provides real-time visibility into plan execution.

Backend (FastAPI)

The Python backend exposes REST and SSE endpoints:

EndpointMethodPurpose
/api/plansGETList all plans with status
/api/plans/{id}/dagGETDAG visualization data
/api/roomsGETList all war-rooms with current state
/api/rooms/{id}/channelGETRead room’s message channel
/api/rooms/{id}/progressGETCurrent progress snapshot
/api/streamSSEReal-time updates for all rooms
/api/searchPOSTSemantic search across memories
/api/statsGETAggregate statistics

Frontend (Next.js)

The Next.js frontend renders:

  • Plan overview — DAG visualization with wave grouping
  • War-room dashboard — grid of active rooms with status badges
  • Room detail — channel messages, progress bars, artifact list
  • Memory explorer — search and browse the shared ledger
  • Settings — role registry, skill index, MCP configuration

Features

  • Real-time updates via SSE (no polling)
  • DAG rendered as an interactive graph
  • Channel messages displayed as a chat timeline
  • Progress bars driven by progress.json from each room
  • Error highlighting with escalation status

Subsystem 3: Bot (TypeScript)

The bot subsystem provides chat platform integrations for human interaction with OSTwin.

PlatformAdapterStatus
Discordbot/discord/Production
Telegrambot/telegram/Production
Slackbot/slack/Beta

The bot enables users to:

  • Start plans from chat messages
  • Monitor room progress in real-time
  • Receive alerts on failures and escalations
  • Override lifecycle states manually
  • Query the memory ledger via natural language

Subsystem 4: MCP Servers (Python)

Four Python-based MCP servers provide tool interfaces for agents:

ServerModuleKey Tools
Memorymcp_servers.memorypublish, query, search, get_context, list_memories
War-Roommcp_servers.warroompost_message, read_messages, get_latest, update_status, report_progress, list_artifacts
Dashboardmcp_servers.dashboardget_plan_status, get_room_state, aggregate_stats
Skillsmcp_servers.skillssearch_skills, install_skill, list_installed

Each server runs as a separate process, launched by Invoke-Agent.ps1 with room-specific arguments. Servers communicate with agents over stdio using the MCP protocol.

Filesystem as Coordination Layer

The filesystem is OSTwin’s coordination backbone. All state is stored as files:

File/DirectoryPurposeFormat
.agents/plans/*/PLAN.mdPlan definitionsMarkdown
.agents/plans/*/DAG.jsonDependency graphsJSON
.agents/war-rooms/*/config.jsonRoom contractsJSON
.agents/war-rooms/*/channel.jsonlMessage channelsJSON Lines
.agents/war-rooms/*/status.txtCurrent lifecycle statePlain text
.agents/war-rooms/*/progress.jsonCompletion trackingJSON
.agents/war-rooms/*/lifecycle.jsonState machine definitionJSON
.agents/ledger.jsonlShared memoryJSON Lines
.agents/roles/*/role.jsonRole configurationsJSON
.agents/skills/*/SKILL.mdSkill definitionsMarkdown
.agents/registry.jsonRole catalogJSON
.agents/vault.jsonSecrets (gitignored)JSON

Why Filesystem?

The tradeoff is that concurrent writes require file locking (handled by fcntl.LOCK_EX in MCP servers) and cross-machine coordination requires shared filesystem access or synchronization.

Concurrency Model

ComponentConcurrencyMechanism
War-roomsUp to 50 parallelWave-based scheduling from DAG
Agents within a roomSequentialManager orchestrates turn order
MCP servers1 per agent sessionProcess-per-session isolation
Channel writesSerializedfcntl.LOCK_EX file locking
Ledger writesSerializedfcntl.LOCK_EX file locking
Dashboard readsConcurrentRead-only polling, no locks needed
Bot commandsQueuedEvent loop with sequential dispatch

Data Flow

User Input
PLAN.md ──► Build-DAG.ps1 ──► DAG.json
Get-NextWave.ps1
New-WarRoom.ps1 ──► room directories
Invoke-Agent.ps1
│ │
┌──────┘ └──────┐
▼ ▼
LLM Session MCP Servers
│ │
├── channel.jsonl ◄──────┤
├── artifacts/ ──────────┤
├── progress.json ◄──────┤
└── ledger.jsonl ◄───────┘
Dashboard (SSE)
Next.js Frontend

Key Source Locations

DirectoryLanguagePurpose
engine/PowerShellOrchestration scripts
mcp_servers/PythonMCP server implementations
dashboard/api/Python (FastAPI)REST + SSE backend
dashboard/web/TypeScript (Next.js)Frontend application
bot/TypeScriptChat platform adapters
.agents/Config filesRuntime state and configuration
.agents/roles/JSON + MarkdownRole definitions
.agents/skills/MarkdownSkill documents
.agents/plans/MixedPlan files and DAGs
.agents/war-rooms/MixedRoom state and artifacts