How steipete/birdclaw works
Purpose and Entry Points
Birdclaw is a local-first Twitter/X workspace. It imports archives and optionally syncs live X data into a shared local SQLite model, then exposes that model through a CLI, local React web app, and restricted MCP read endpoint. CLI startup is bin/birdclaw.mjs and command registration is centered in src/cli.ts; the web router starts at src/router.tsx with route modules under src/routes/.
Canonical Local Data Layer
SQLite under ~/.birdclaw is the system of record: canonical tweets/profiles plus account-scoped timeline, collection, follow, list, DM, and moderation edges. FTS-backed read models power local search and UI/API reads. Database lifecycle, migrations, and access are concentrated in src/lib/db.ts, src/lib/database-migrations.ts, and src/lib/queries.ts. Media and avatars are filesystem caches, deliberately outside SQLite.
Ingestion and Synchronization
Two inputs converge into the same normalized store:
• Archive discovery/import parses selective slices (tweets, profiles, follows, DMs, bookmarks), applies them transactionally, and extracts bundled media.
• Live sync adapters fetch through optional external xurl and bird CLIs, then persist canonical entities and account membership edges.
Core orchestration is in src/lib/archive-import.ts, src/lib/live-sync-engine.ts, and src/lib/web-sync.ts. This boundary isolates remote/auth/rate-limit variability from offline reads.
CLI, Jobs, and External Process Boundary
The CLI is the automation/control plane: core, sync, search, compose, moderation, graph, storage, analysis, and job commands are registered through modules such as src/cli/register-sync.ts, src/cli/register-core.ts, and src/cli/register-jobs.ts. Subprocess integration with bird/xurl is centralized behind adapters including src/lib/bird.ts, src/lib/xurl.ts, and src/lib/subprocess.ts. macOS LaunchAgent scheduling and durable sync audit behavior live in src/lib/launchd.ts and src/lib/account-sync-job.ts.
Web Application and Local APIs
The Vite/React application provides local timeline, mentions, DMs, inbox, links, blocks, profile, and analysis screens. Route modules compose DB-backed loaders/UI, while /api endpoints expose actions, sync triggers, queries, streams, and status. Key boundaries are src/routes/__root.tsx, src/routes/api/query.tsx, and src/routes/api/sync.tsx. UI components consume route/API data rather than directly accessing storage; timeline composition is represented by src/components/TimelineFeedShell.tsx.
Read Models, Triage, and Graph Analysis
Specialized local read models turn normalized data into operational views: DM conversations, inbox ranking, follow graph analysis, link indexing, profile identity evidence, and timeline/search results. Representative modules are src/lib/dm-read-model.ts, src/lib/inbox.ts, and src/lib/follow-graph.ts. These remain local-first; graph commands and ordinary search do not require live X access.
AI and Streaming Features
OpenAI is optional and layered over cached local context for inbox scoring, digest/discussion streams, and profile analysis; it is not a data source of truth. Typed Effect-based I/O programs are preferred internally and exposed as Promise boundaries to CLI/routes/components. Relevant runtime and streaming modules are src/lib/openai-response-runtime.ts, src/lib/analysis-runtime.ts, and src/lib/ndjson-stream.ts.
Backup, Serving, and Security Boundaries
Deterministic JSONL backup/export/import provides Git-friendly replication of durable SQLite data, managed by src/lib/backup.ts and src/lib/backup-table-codecs.ts. The production local server is implemented in src/lib/production-server.ts. Web access defaults to loopback; optional web token protection is separate from the read-only, tokenized MCP endpoint implemented by src/lib/mcp-http.ts. MCP excludes DMs, live sync, writes, and AI operations.
Main entry points: query.tsx Routes and local APIs · db.ts Canonical SQLite store · live-sync-engine.ts Live sync engine · cli.ts Birdclaw CLI
Components 18
Entry points
- Birdclaw CLI · Registers core, sync, search, job, and analysis commands.
src/cli.ts - CLI launcher
bin/birdclaw.mjs - React router · Composes local route modules and API endpoints.
src/router.tsx
Ingestion and jobs
- Archive import · Selectively parses archives, applies transactions, and extracts media.
src/lib/archive-import.ts - Live sync engine · Normalizes remote data and account membership edges.
src/lib/live-sync-engine.ts - bird / xurl adapters · Isolates optional external CLI, authentication, and rate-limit behavior.
src/lib/subprocess.ts - Scheduled sync jobs · Records sync audits and integrates with macOS scheduling.
src/lib/account-sync-job.ts
Local data and read models
- Canonical SQLite store · Stores canonical entities and account-scoped relationship edges under ~/.birdclaw.
src/lib/db.ts - Database migrations
src/lib/database-migrations.ts - Query layer and FTS · Provides FTS-backed search and UI/API reads.
src/lib/queries.ts - Operational read models · Builds DM, inbox, follow-graph, link, and identity views.
src/lib/inbox.ts - Media and avatar cache · Archive media is cached outside SQLite.
Local surfaces
- Routes and local APIs · DB-backed screens plus query, action, stream, status, and sync endpoints.
src/routes/api/query.tsx - Timeline UI · Consumes route/API data rather than storage directly.
src/components/TimelineFeedShell.tsx - Optional AI runtime · Uses cached local context for scoring, digests, and profile analysis.
src/lib/analysis-runtime.ts - JSONL backup replication · Deterministic Git-friendly replication of SQLite data.
src/lib/backup.ts - Local production server · Serves web access on loopback by default.
src/lib/production-server.ts - Read-only MCP endpoint · Excludes DMs, sync, writes, and AI operations.
src/lib/mcp-http.ts
Connections 22
- CLI launcher → Birdclaw CLI: starts
- Birdclaw CLI → Archive import: imports archives
- Birdclaw CLI → Live sync engine: runs sync
- Birdclaw CLI → Scheduled sync jobs: manages jobs
- Scheduled sync jobs → Live sync engine: executes
- Live sync engine → bird / xurl adapters: fetches through
- Archive import → Canonical SQLite store: transactional writes
- Archive import → Media and avatar cache: extracts media
- Live sync engine → Canonical SQLite store: persists normalized data
- Database migrations → Canonical SQLite store: evolves schema
- Canonical SQLite store → Query layer and FTS: canonical data
- Canonical SQLite store → Operational read models: normalized records
- React router → Routes and local APIs: mounts
- Routes and local APIs → Query layer and FTS: local reads
- Routes and local APIs → Operational read models: operational views
- Routes and local APIs → Live sync engine: sync triggers
- Timeline UI → Routes and local APIs: route/API data
- Routes and local APIs → Optional AI runtime: analysis streams
- Optional AI runtime → Query layer and FTS: cached context
- JSONL backup replication → Canonical SQLite store: exports and imports
- Local production server → React router: serves
- Read-only MCP endpoint → Query layer and FTS: restricted reads