Skip to Content
ConceptsArchitecture

Architecture

RantAIClaw is trait-driven and factory-registered. Every major extension point — providers, channels, tools, memory backends, observers, runtime adapters, peripherals — is defined as a Rust trait, with concrete implementations registering themselves via factory modules. To add a capability, you implement a trait and register it; you almost never modify orchestration code.

Around that core sit two organizing layers worth knowing about up front:

  • The profile system — everything about a running agent (config, memory, persona, skills, secrets, audit) lives under ~/.rantaiclaw/profiles/<active>/. See Profiles.
  • The subsystem map — 30+ Rust modules under src/, each with a single responsibility. The map below summarizes the ones you’ll touch most often.

The seven extension traits

TraitFileWhat it abstracts
Providersrc/providers/traits.rsLLM backends — OpenRouter, OpenAI, Anthropic, Gemini, Copilot, plus 25+ OpenAI-compatible/regional providers
Channelsrc/channels/traits.rsCommunication endpoints — Discord, Slack, Telegram, WhatsApp, Email, IRC, Signal, Matrix, iMessage, plus more
Toolsrc/tools/traits.rsActions an agent can take — shell, file_*, cron_*, memory_*, web_search_tool, etc.
Memorysrc/memory/traits.rsPersistence — sqlite, lucid (sqlite + markdown overlay), markdown, postgres, none
Observersrc/observability/traits.rsTracing, metrics, audit logs
RuntimeAdaptersrc/runtime/traits.rsProcess model, sandbox, signal handling
Peripheralsrc/peripherals/traits.rsHardware boards — STM32, Raspberry Pi GPIO, Arduino

Top-level subsystem map

The actual src/ tree is broader than the seven traits would suggest. The full top-level subsystems:

SubsystemOwns
agent/Orchestration loop, persona application, tool dispatch, memory loader
approval/Approval gate (CLI prompt, session-scoped allowlist), L1–L4 preset writer
auth/Auth flows for providers — OAuth, OpenAI Codex device-code, Anthropic subscription tokens
channels/Per-channel transport, allowlist enforcement
config/Schema, load/merge, runtime overrides (planned), JSON Schema export
cost/Cost tracking and per-day caps
cron/Cron job storage, scheduler, execution history
daemon/The rantaiclaw daemon supervisor — boots gateway + channels + scheduler + heartbeat
doctor/The rantaiclaw doctor validator and its individual checks
gateway/HTTP control plane — pairing, webhooks, triggers, /api/v1/*
hardware/Hardware discovery (USB, serial)
health/Health endpoint payload, runtime snapshot
heartbeat/Periodic vitality and self-check signals
identity/Agent identity / project-context bootstrap
integrations/External service integrations
lifecycle/Process lifecycle (signals, graceful shutdown)
mcp/MCP server supervision (process-level today)
memory/Memory traits and 5 backends + hygiene + snapshot/hydration + response cache
migration/Profile migrations between versions
multimodal.rsMultimodal payload helpers
observability/Tracing, Prometheus metrics
onboard/The setup / onboard interactive wizards
peripherals/Hardware peripherals (STM32, RPi GPIO, ESP32, Arduino)
persona/Persona presets, persona.toml + SYSTEM.md loader
profile/Profile system — paths, active profile resolution, profile CLI
providers/Provider traits + reliability wrapper + 30+ provider implementations
rag/Retrieval-augmented generation helpers
runtime/Runtime adapter — sandbox detection, Docker, native exec
security/Approval policy, sandbox (Landlock/Firejail/Bubblewrap/Docker/Noop), secret store, audit log
service/systemd / launchd / Windows service generators
services/Service detection and integration
sessions/Session storage and lookup (per-conversation state)
skillforge/Auto-discovery pipeline for community skills
skills/Skill loading (TOML/MD), discovery, prompt injection, ClawHub installer, open-skills sync
tasks/Task / subtask CRUD (HTTP-exposed)
tools/Tool traits + built-in tools + skill-tool adapter
tui/Terminal UI
tunnel/Tunnel manager (cloudflared, ngrok) for public exposure without binding

This is what makes rantaiclaw a single binary that can do a lot — the responsibilities are partitioned narrowly, so each subsystem stays small and auditable.

Boundary contract

These rules keep the architecture stable as the codebase grows:

  • Concrete integrations depend on traits and config, never on each other. Provider code does not import channel internals. Tool code does not mutate gateway policy directly.
  • Each subsystem owns a single concern. Orchestration in agent/. Transport in channels/. Model I/O in providers/. Policy in security/. Execution in tools/.
  • New shared abstractions wait for the rule of three. Duplicate small logic locally rather than create premature abstractions.
  • Config keys are public contract. Adding, renaming, or removing a config key requires documented compatibility impact and a migration path.

Blast radius — risk tiers

Validation depth scales with tier:

TierPathsRequired for changes
Lowdocs/, tests, choresLightweight checks
MediumMost src/** without security/boundary impactFull relevant tests
Highsrc/security/**, src/runtime/**, src/gateway/**, src/tools/**, .github/workflows/**, Cargo.toml, config schema, CLI behaviorRisk note + failure-mode validation + rollback note

When in doubt, classify higher.

The daemon’s role

rantaiclaw daemon is the production deployment shape. It boots:

  • the gateway HTTP server
  • each enabled channel’s listen task
  • the heartbeat / scheduler / cron loops

Each of these runs in its own tokio task, supervised with exponential-backoff restart on crash (src/daemon/mod.rs). A misbehaving channel doesn’t take down the gateway and vice versa.

Why size and determinism matter

Two design constraints visible everywhere in the codebase:

  1. Binary size is a product goal. The release profile uses opt-level = "z", lto = "fat", codegen-units = 1, strip = true, panic = "abort". Convenience dependencies are scrutinized.
  2. Determinism is a CI goal. Tests avoid flaky timing or network dependence. Local validation maps exactly to CI expectations.

Breaking either requires explicit justification.

Last updated on