System Architecture
Core Components
Single Process Design
NanoClaw Pro runs as a single Node.js process that:- Manages all channel connections (WhatsApp, Telegram, Slack, Discord, Gmail)
- Polls SQLite for new messages every 2 seconds
- Routes messages to the appropriate container
- Manages agent lifecycle and concurrency
- Handles scheduled task execution
- Simple deployment (one service, one process)
- Easy to debug and monitor
- No IPC complexity between services
- Graceful shutdown handling
src/index.ts:465-575
SQLite Storage
All persistent state is stored in a single SQLite database atstore/messages.db:
| Table | Purpose |
|---|---|
messages | Message history for registered groups |
chats | Chat metadata (name, last activity) |
registered_groups | Group configuration and permissions |
sessions | Claude session IDs for conversation continuity |
scheduled_tasks | Task definitions and schedules |
task_run_logs | Task execution history |
router_state | Message processing cursors |
- Zero configuration
- Transactional integrity
- Fast local queries
- Embeddable (no separate database process)
- Automatic backups via file copy
src/db.ts:17-86
SQLite is perfect for single-machine deployments. NanoClaw Pro doesn’t need distributed databases or message queues.
Container Execution Model
Agents run in isolated Linux containers (lightweight VMs) spawned on-demand:- Spawn - Container created when messages arrive for a group
- Execute - Agent processes messages with full Claude SDK capabilities
- Idle - Container stays alive after output (configurable timeout)
- Pipe - New messages piped to stdin while container is idle
- Terminate - Container exits after idle timeout or on error
- Security: Filesystem and process isolation
- Resource cleanup: Automatic with
--rmflag - Fresh environment: No state pollution between runs
- Safe Bash: Commands execute in container, not on host
src/container-runner.ts:258-638
Technology Stack
| Component | Technology | Purpose |
|---|---|---|
| Host Process | Node.js 20+ | Main orchestrator |
| Database | SQLite (better-sqlite3) | Persistent storage |
| Container Runtime | Container (Linux VM) | Agent isolation |
| Agent SDK | @anthropic-ai/claude-agent-sdk | Claude with tools |
| Channels | Self-registering modules | Multi-platform support |
| Scheduler | Cron parser + interval timer | Task scheduling |
Data Flow
Incoming Message Flow
Scheduled Task Flow
Deployment Model
NanoClaw Pro runs as a single system service:macOS (launchd)
Linux (systemd)
Startup Sequence
When NanoClaw Pro starts:- Container Runtime Check - Ensures runtime is running, kills orphaned containers
- Database Init - Creates schema, runs migrations from JSON files if needed
- Load State - Restores sessions, groups, and message cursors from SQLite
- Connect Channels - Instantiates configured channels, skips those without credentials
- Start Subsystems - Scheduler loop, IPC watcher, group queue processor
- Recover Messages - Re-processes any messages that arrived before shutdown
- Message Loop - Begins polling for new messages
src/index.ts:465-575
NanoClaw Pro automatically recovers from crashes by re-processing unhandled messages from SQLite.
Concurrency Control
TheGroupQueue manages container concurrency:
- Global limit: Max 5 concurrent containers (configurable via
MAX_CONCURRENT_CONTAINERS) - Per-group serialization: One container per group at a time
- Message piping: New messages sent to active containers via stdin
- Idle reuse: Containers stay alive 30 minutes after output
- Prevents race conditions in group folder writes
- Ensures conversation order
- Simpler session management
src/group-queue.ts
Next Steps
Message Flow
Deep dive into message routing and processing
Channel System
How channels self-register and integrate
Session Management
Conversation continuity and memory
Security
Container isolation and security model