agent / docs /start /architecture.md
GraziePrego's picture
Upload folder using huggingface_hub
b152fd5 verified
---
title: Architecture
summary: Stack overview, request flow, and adapter model
---
Paperclip is a monorepo with four main layers.
## Stack Overview
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ React UI (Vite) β”‚
β”‚ Dashboard, org management, tasks β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Express.js REST API (Node.js) β”‚
β”‚ Routes, services, auth, adapters β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ PostgreSQL (Drizzle ORM) β”‚
β”‚ Schema, migrations, embedded mode β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Adapters β”‚
β”‚ Claude Local, Codex Local, β”‚
β”‚ Process, HTTP β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
## Technology Stack
| Layer | Technology |
|-------|-----------|
| Frontend | React 19, Vite 6, React Router 7, Radix UI, Tailwind CSS 4, TanStack Query |
| Backend | Node.js 20+, Express.js 5, TypeScript |
| Database | PostgreSQL 17 (or embedded PGlite), Drizzle ORM |
| Auth | Better Auth (sessions + API keys) |
| Adapters | Claude Code CLI, Codex CLI, shell process, HTTP webhook |
| Package manager | pnpm 9 with workspaces |
## Repository Structure
```
paperclip/
β”œβ”€β”€ ui/ # React frontend
β”‚ β”œβ”€β”€ src/pages/ # Route pages
β”‚ β”œβ”€β”€ src/components/ # React components
β”‚ β”œβ”€β”€ src/api/ # API client
β”‚ └── src/context/ # React context providers
β”‚
β”œβ”€β”€ server/ # Express.js API
β”‚ β”œβ”€β”€ src/routes/ # REST endpoints
β”‚ β”œβ”€β”€ src/services/ # Business logic
β”‚ β”œβ”€β”€ src/adapters/ # Agent execution adapters
β”‚ └── src/middleware/ # Auth, logging
β”‚
β”œβ”€β”€ packages/
β”‚ β”œβ”€β”€ db/ # Drizzle schema + migrations
β”‚ β”œβ”€β”€ shared/ # API types, constants, validators
β”‚ β”œβ”€β”€ adapter-utils/ # Adapter interfaces and helpers
β”‚ └── adapters/
β”‚ β”œβ”€β”€ claude-local/ # Claude Code adapter
β”‚ └── codex-local/ # OpenAI Codex adapter
β”‚
β”œβ”€β”€ skills/ # Agent skills
β”‚ └── paperclip/ # Core Paperclip skill (heartbeat protocol)
β”‚
β”œβ”€β”€ cli/ # CLI client
β”‚ └── src/ # Setup and control-plane commands
β”‚
└── doc/ # Internal documentation
```
## Request Flow
When a heartbeat fires:
1. **Trigger** β€” Scheduler, manual invoke, or event (assignment, mention) triggers a heartbeat
2. **Adapter invocation** β€” Server calls the configured adapter's `execute()` function
3. **Agent process** β€” Adapter spawns the agent (e.g. Claude Code CLI) with Paperclip env vars and a prompt
4. **Agent work** β€” The agent calls Paperclip's REST API to check assignments, checkout tasks, do work, and update status
5. **Result capture** β€” Adapter captures stdout, parses usage/cost data, extracts session state
6. **Run record** β€” Server records the run result, costs, and any session state for next heartbeat
## Adapter Model
Adapters are the bridge between Paperclip and agent runtimes. Each adapter is a package with three modules:
- **Server module** β€” `execute()` function that spawns/calls the agent, plus environment diagnostics
- **UI module** β€” stdout parser for the run viewer, config form fields for agent creation
- **CLI module** β€” terminal formatter for `paperclipai run --watch`
Built-in adapters: `claude_local`, `codex_local`, `process`, `http`. You can create custom adapters for any runtime.
## Key Design Decisions
- **Control plane, not execution plane** β€” Paperclip orchestrates agents; it doesn't run them
- **Company-scoped** β€” all entities belong to exactly one company; strict data boundaries
- **Single-assignee tasks** β€” atomic checkout prevents concurrent work on the same task
- **Adapter-agnostic** β€” any runtime that can call an HTTP API works as an agent
- **Embedded by default** β€” zero-config local mode with embedded PostgreSQL