Vibecodr – How It Works

This document describes how Vibecodr actually works, step by step, based on the implemented architecture. It follows a request from the browser through the web app, API Worker, execution workers, and back.

1. Web App and API Boundary

The web UI is a React single-page app (apps/web) that uses React Router for client-side navigation. All data comes from an edge Worker API whose base URL is computed by helpers in the web app.

A typical browser request follows this path:

  1. User navigates to a route like /, /player/:postId, or /settings
  2. The SPA route component uses an API helper to call the Worker API (e.g., GET /posts, GET /profile/:handle)
  3. The API Worker reads/writes from D1, R2, Durable Objects, and Analytics Engine
  4. The route component maps the JSON response into view models and renders the page
Browser → React SPA → API Worker → D1/R2/KV/DO → Response → SPA renders

Key idea: All data flows through a single API Worker endpoint. The SPA never talks directly to storage services.

2. Feed and Post Flow

The home feed and post views are backed by feed endpoints in the API worker:

The SPA uses shared schemas from @vibecodr/shared to validate API responses before mapping them into feed and player models.

3. Feed Ranking and Personalization

Feed ranking uses linear, non-ML scoring over existing signals to keep behavior auditable while allowing future model swaps without API changes.

Signals Used

Feed Modes

Safety Filters

Excludes muted/blocked users, quarantined content; applies search/tag filters before scoring; falls back to discover feed if personalization is empty.

4. Vibe Runtime Execution

When a user opens a vibe in the player at /player/:postId, the system loads and runs that vibe in a sandboxed iframe:

  1. Player page fetches the post and associated runtime manifest from the Worker API
  2. Player enforces client-side runtime budgets (max concurrent runners, boot timeouts by surface and plan)
  3. Runtime HTML and bundle are served from a separate origin and embedded in an iframe with sandbox attributes and restricted CSP
  4. The iframe runs user code purely client-side; there is no server-side Node.js runtime
  5. Iframe and host communicate via postMessage protocol carrying params, logs, and telemetry
  6. Logs and runtime events are forwarded to the Worker; runs are finalized via runtime completion APIs
Player Page → Fetch Manifest → Load Iframe (sandbox + CSP) ↓ Iframe runs vibe code (client-only) ↓ postMessage bridge ↔ Host SPA ↓ Telemetry → API Worker → D1/Analytics Engine

Key idea: Vibes execute entirely in the browser. The iframe is sandboxed and communicates with the host only via postMessage. No server-side Node.js runtime.

Runtime Budgets

5. Pulse Execution Flow

Pulses are per-user server-side functions deployed on Workers for Platforms. The execution path is implemented in the API Worker and dispatch worker.

  1. Pulse is created and managed via pulse APIs in workers/api
  2. Deployment scripts build and deploy a per-pulse Worker using the template in workers/vibe-template
  3. Manual runs are quota-checked against the user's plan in the API Worker
  4. Vibes and triggers use grant-based execution: API mints a short-lived grant, host calls pulse run endpoint with grant as bearer token
  5. Dispatch worker validates grant, enforces rate limits and concurrency caps, checks kill switches
  6. Dispatch routes to the user's pulse Worker in the dispatch namespace
  7. Pulse Worker returns a Response or JSON result; dispatch attaches metadata headers
Vibe iframe → postMessage("pulse:run") → Host SPA ↓ POST /pulse-grants (with Clerk session) → API Worker → Grant token ↓ POST /pulses/:id/run (with grant) → API Worker → Dispatch Worker ↓ Dispatch validates grant, enforces limits → User's Pulse Worker ↓ Response → Host SPA → postMessage → Vibe iframe

Key idea: Browser only talks to API Worker; pulses are always reached via grant-based dispatch worker. Grants are short-lived (30-90s) and scoped to {userId, pulseId}.

6. Integrations and Proxy Flow

Integrations and their secrets are modeled in D1 tables and surfaced through the API Worker.

  1. Integration is created with type, name, and config; secrets are stored encrypted with AES-GCM
  2. Vibes are associated with integrations so a vibe (and its pulses) knows which provider config to use
  3. Server-side code sends external HTTP requests through a proxy that enforces per-provider host allowlists and blocks private/loopback IPs
  4. Proxy derives auth headers from stored secrets and returns upstream response after stripping sensitive headers

Supported Providers

OpenAI, Supabase, Stripe, Slack, Discord, GitHub, email services, and generic HTTP endpoints through a single, observable gateway.

7. Safety, Limits, and Plans

Safety and cost controls are implemented across the API Worker, dispatch worker, and shared config:

Plan Limits Summary

Plan Storage Pulses Runs/mo
Free 1 GB 1 100
Creator 5 GB 10 100,000
Pro 20 GB 30 500,000
Team (internal) 50 GB 100 2,000,000

8. Real-time Streams

Vibecodr provides SSE streams for admin analytics:

Notifications use client-side SWR polling (GET /notifications/unread-count) for cost efficiency. Streams send heartbeats to keep connections alive; clients back off on 429/5xx and retain REST endpoints as fallback.

9. Key API Endpoints

Anchor endpoints organized by domain:

Domain Endpoints Purpose
Feed/Read GET /posts, GET /posts/discover Timeline with modes (latest, following, foryou), search, tags
Posts GET/POST /posts/:id, /like, /comments CRUD, social interactions
Capsules GET /capsules/:id, /manifest, /bundle Vibe container data, runtime manifest, compiled bundles
Pulse CRUD GET/POST /pulses, PATCH/DELETE /pulses/:id Manage server-side functions
Pulse Run POST /pulse-grants, POST /pulses/:id/run Grant acquisition + execution (requires grant)
Integrations GET/POST /integrations, POST /integrations/proxy Manage providers, proxy external calls with secrets
Webhooks POST /t/:token Public webhook entry point for automations
Profiles GET /users/:handle, GET /profile/:handle User profiles, follow relationships

10. Architecture Summary

Taken together, these flows describe how a request moves through Vibecodr: from the browser into Workers, through D1/R2/Durable Objects and back, using only the behavior defined in the codebase.

┌─────────────────────────────────────────────────────────────────┐ │ BROWSER │ │ React SPA (apps/web) ←→ postMessage ←→ Vibe Iframe (sandbox) │ └─────────────────────────────────────────────────────────────────┘ ↓ HTTPS ┌─────────────────────────────────────────────────────────────────┐ │ API WORKER (workers/api) │ │ Routes, Auth, Quotas, Feed Ranking, Capsule/Pulse Management │ │ ↔ D1 (SQLite) ↔ R2 (Storage) ↔ KV ↔ Durable Objects │ └─────────────────────────────────────────────────────────────────┘ ↓ Grant-based dispatch ┌─────────────────────────────────────────────────────────────────┐ │ DISPATCH WORKER (workers/dispatch) │ │ Grant validation, Rate limits, Concurrency caps, Kill switches │ └─────────────────────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────────────────────┐ │ USER PULSE WORKERS (Workers for Platforms) │ │ Per-user isolated Workers running pulse code with scoped tools │ └─────────────────────────────────────────────────────────────────┘

Key idea: Three-layer architecture. Browser SPA handles UI. API Worker handles data and orchestration. Dispatch Worker routes to isolated per-user pulse Workers. Each layer adds security/isolation.