Skip to content

Architecture Overview

Claw Insights is a read-only observability sidecar for OpenClaw agents. It reads existing files and CLI output — no code changes to your agent, no cloud dependency, all data stays local.

System Architecture

┌─────────────────────────────────────────────────────────────┐
│                       claw-insights                         │
│                                                             │
│  External I/O          Pipeline              API Layer      │
│  ─────────────     ─────────────────     ──────────────     │
│  sessions.json  →                        /graphql (query,   │
│  transcripts/*  →  Sources → Ports ───→   mutation, sub)    │
│  gateway logs   →                        /api/snapshot      │
│  cron.json      →       ↕               /health             │
│  openclaw CLI   →    Services                               │
│                      (sampling,          Web Dashboard       │
│       ↕              retention,      ←── (React + Vite)     │
│    SQLite            validation)                            │
└─────────────────────────────────────────────────────────────┘

Data flows left to right: external files and CLI → Sources ingest and parse → Pipeline wires components → Ports expose typed read interfaces → GraphQL resolvers serve queries → Web dashboard (or any API client) consumes data.

SQLite provides persistent storage for time-series metrics, token usage, message events, and system samples.

Monorepo Structure

PackagePurpose
packages/serverExpress server: data pipeline, GraphQL API, snapshot renderer, SQLite storage
packages/webReact 19 + Vite dashboard: charts (ECharts), session explorer, log viewer
packages/sharedGenerated TypeScript types from schema.graphql (shared by server and web)

Pipeline Roles

The Pipeline manages all components through five roles:

RoleResponsibility
SourceEmits events from external data (file watchers, CLI clients)
ManagedLifecycle-only resources with no events (event buses, readers)
ProcessorHandles events from Sources (e.g., ingesting logs into the database)
ServiceBackground tasks with start/stop lifecycle (sampling, retention, validation)
PortTyped read interface — the public contract consumed by GraphQL resolvers

Lifecycle: init (register components) → build (bind wiring) → start (launch services) → destroy (teardown in reverse order).

Ports

Ports are the boundary between the pipeline internals and the API layer. Each Port exposes a focused read interface:

PortResponsibility
sessionsSession list, hierarchy, status, and filtering
metricsTime-bucketed metrics with per-model token breakdown
gatewayOpenClaw gateway process status and version
cronScheduled job definitions
logsRecent structured log entries
systemCPU, memory, disk usage, and health checks
lifetimeCumulative statistics across all transcript history
transcriptSession transcript file access for replay
usageToken cost summary from gateway

Next Steps

Released under the MIT License.