Alavida Platform Architecture

13 knowledge files · 22 platform decisions · 23 mesh decisions · 6 quantums

1 — Overview

The Platform domain is the engineering backbone of Alavida. It decides how software gets built, maintains architecture standards, provides skill authoring guides, and owns the external repos where code ships. Two parallel tracks converge on shared infrastructure: a GTM workflow registry (5 phases, consumer-facing) and an agentic mesh (4 phases, internal-only).

13
Knowledge Files
6
Quantums
45
Arch Decisions
5
GitHub Repos
3
Runtimes
113
User Stories
2 — Infrastructure Topology

Three runtimes serve different purposes, connected by the Inngest event bus. Railway hosts compute, n8n bridges the external world, and Inngest provides durable event-driven execution with step-level fault tolerance.

Railway
Quantum Compute
FastAPI + Inngest + Alembic. Hosts identity, buying-signals, icp-discovery, lead-discovery, meeting-analysis. Scale-to-zero on Hobby plan (~$5/mo).
n8n
Connector Runtime
Bridges external systems into the mesh. Mode 2: plumbing then Inngest event. Hosts meeting-sync (Granola connector). Free tier = 5 workflows.
Inngest
Event Bus
Self-hosted on Railway. Step memoization, retry with backoff, concurrency controls, event-to-function triggers. All quantums share one bus.
Database: Single Neon PostgreSQL (free tier, auto-scales to zero). Schema-per-component isolation — public (platform), buying_signals, x_scraper, identity. No cross-schema foreign keys. Application-level referential integrity.
3 — Quantum Catalog

Six quantums across two domains. Each satisfies the quantum contract: /run, /health, /data endpoints, Inngest events, and a consumer skill published to the registry. Identity deploys first (deterministic, no LLM), proving the pattern for everything that follows.

Quantum Type Domain Runtime Phase Status
identity deterministic Platform Railway 1 Deployed
buying-signals agentic Prospect-discovery Railway + Langfuse 1 Pending refactor
icp-discovery agentic Prospect-discovery Railway + Langfuse 2 Pending refactor
lead-discovery agentic Prospect-discovery Railway + Langfuse 2 Pending refactor
meeting-sync connector Operations n8n (Mode 2) 3 Not started
meeting-analysis agentic Operations Railway + Langfuse 3 Not started
Quantum Contract (required endpoints)
  • POST /run/{action} — async job acceptance, returns job_id + trace_id
  • GET /health — standard health check with quantum name, version, timestamp
  • GET /data/{entity} — REST endpoints scoped to polyseme UUIDs
  • Events via Inngest — cross-quantum events following {domain}/{entity}.{action}
  • Consumer skill — data contract published to the registry
4 — Cross-Quantum Event Map

Events flow across quantums through Inngest, carrying trace_id and polyseme UUIDs. The prospect scoring pipeline cascades through three quantums. Phase 3 adds cross-domain flow from operations into prospect-discovery.

graph LR
  subgraph OPS["Operations Domain"]
    MS["meeting-sync
(n8n)"] MA["meeting-analysis"] end subgraph PD["Prospect-Discovery Domain"] ICP["icp-discovery"] LD["lead-discovery"] BS["buying-signals"] end subgraph PLAT["Platform Domain"] ID["identity"] end MS -->|"meeting/transcript.added"| MA MA -->|"meeting/company.mentioned"| ICP ICP -->|"icp/company.qualified"| LD LD -->|"lead/company.completed"| BS BS -->|"signal/company.scored"| OUT["Future consumers"] ICP -.->|"resolve-company"| ID LD -.->|"resolve-person"| ID MA -.->|"resolve entities"| ID
Event flow (solid)
API call (dotted)
Fan-out pattern: icp-discovery qualifies 30 companies in one run, emitting 30 icp/company.qualified events. Inngest invokes lead-discovery 30 times with concurrency limits. Each completed company triggers buying-signals independently. No central orchestrator — Observer + Listener pattern.
5 — Data Layer

Single Neon PostgreSQL with schema-per-component isolation. The platform owns public (users, teams, credits, jobs, registry). Components own their schemas with no cross-schema FK constraints. Polysemes (company, person) are resolved through the identity quantum.

erDiagram
  USERS ||--o{ TEAM_MEMBERS : belongs
  TEAMS ||--o{ TEAM_MEMBERS : has
  TEAMS ||--|| CREDIT_ACCOUNTS : "1:1 billing"
  TEAMS ||--o{ JOBS : creates
  TEAMS ||--o{ API_KEYS : owns
  USERS ||--o{ JOBS : submits
  JOBS ||--o| CREDIT_USAGE : charges
  TEAMS ||--o{ CREDIT_PURCHASES : buys

  USERS {
    uuid id PK
    text email
    text name
  }
  TEAMS {
    uuid id PK
    text name
    text stripe_customer_id
  }
  JOBS {
    uuid id PK
    text component_slug
    text status
    jsonb result_payload
    jsonb usage_metrics
  }
  CREDIT_ACCOUNTS {
    uuid team_id PK
    int balance
    int lifetime_used
  }
      
Polysemes
Cross-domain entities resolved through identity quantum. polyseme_company_id and polyseme_person_id columns (nullable UUID) in every quantum's schema. Forward-only migration — new records get UUIDs, old stay NULL.
Migration Strategy
Always-additive migrations. Expand-contract for breaking changes. Neon branches for CI/CD testing (preview/pr-{n}). Point-in-time restore for rollback. Each component owns its own migrations independently.
6 — v4 Release Phases

Four phases, each proving a specific capability. Strict dependency ordering — each phase validates the pattern before the next adds complexity. 23 architecture decisions total. 12 features explicitly deferred.

PHASE 1
The Pattern
identity + buying-signals
6 decisions
PHASE 2
The Chain
icp + lead event chain
5 decisions
PHASE 3
The Portal
meeting-sync + analysis
7 decisions
PHASE 4
The Eyes
Grafana + Langfuse
5 decisions
Registry Platform Phases (parallel track, 5 phases)
P1
Foundation
DONE
P2
First Component
READY
P3
CLI + MCP
Not started
P4
Dashboard
Not started
P5
x-scraper
Not started
7 — Registry Platform

A GTM workflow registry inspired by shadcn-ui — npx alavida add buying-signals. Components are living services, not static code. The platform manages execution, billing, API keys, updates, and data persistence. Three interfaces to the same backend: CLI, MCP, and Dashboard.

Request Flow — Async Workflow
1
User
Claude Code / CLI
reads SKILL.md
2
Platform API
Auth, credits,
job create, route
3
Component
Inngest workflow
Agent SDK pipelines
4
Callback
Results + metrics
Credit deduction
CLI
alavida auth, add, jobs, credits. Commander.js, native fetch. Published as @alavida/cli.
MCP Server
8 tools over stdio. Registry discovery + platform operations. Bundled with CLI. search_registry, install_component.
Dashboard
Next.js + Clerk + Tailwind. 10 pages: jobs, credits, billing, registry, buying-signals views. Stripe checkout integration.
8 — Observability

Four observability concerns, each with its own tooling. The critical requirement: LLM tracing tool's trace_id MUST equal the event trace_id for seamless cross-system navigation.

LLM Tracing
TBD (Langfuse vs Braintrust). Every LLM call, tool call, agent decision. Agentic quantums only.
Dashboards
TBD (Grafana free tier). Quantum health, integration health, cost, throughput, alerting.
Structured Logs
Decided structlog JSON. All quantums. trace_id + span_id + quantum + step + action.
Event Flow
Decided Inngest dashboard. Events fired, functions ran, retries, failures.
Trace correlation: trace_id is generated at flow entry (Platform generates job_id = trace_id, or n8n generates UUID). Each quantum creates its own span_id. Fan-out shares trace_id across all parallel branches.
9 — Workbenches & Skills

Workbenches are persona-scoped environments (skills, hooks, settings) that give different roles the right surface area. The dev workbench implements compound engineering: Plan → Work → Review → Compound. Two skill templates: CLI/API (13 sections) and knowledge processing (8 sections).

Dev Workbench (Creator)
  • /platform:compound — workspace-aware engineering loop
  • agent-sdk-automations — 10 Agent SDK patterns
  • inngest-workflow — durable workflow patterns
  • railway-deployment — deployment patterns
Three-Layer Discovery
  • Marketplace.claude-plugin/marketplace.json lists all available workbenches
  • Activation.claude/settings.json controls which are enabled
  • Implementationdomains/*/workbenches/{type}/{name}/ packages
10 — Knowledge File Map

All 13 knowledge files in domains/platform/knowledge/ and when to consult each one.

File Covers Confidence Go here when
registry-platform-architecture 22 decisions, system topology, API routes medium Making infrastructure choices, reviewing design
v4-release-plan 4 phases, 6 quantums, 23 decisions high Understanding mesh roadmap, in/out of scope
quantum-catalog Per-quantum specs, endpoints, events high Understanding what a quantum does
quantum-event-map Event chains, fan-out, naming migration high Designing event subscriptions, tracing flows
infrastructure-topology 3 runtimes, n8n modes, quantum template high Deploying a new quantum
component-patterns Contract, taxonomy, pipeline arch medium Building or modifying a component
database-design Schemas, migration strategy, Neon branching medium Designing schema changes
observability-architecture LLM tracing, dashboards, structlog medium Instrumenting a quantum
implementation-phases 5-phase registry build plan, 113 stories medium Planning platform work, checking progress
existing-systems Monorepo + prospect-engine architecture medium Working with legacy, planning extraction
workbench-architecture Folder structure, discovery model, plugins high Building a workbench, plugin discovery
skill-authoring-guide SKILL.md structure, config patterns, CLI medium Creating a new skill
user-workflows 3 personas, 25 stories, 9 functional areas medium Understanding user needs, validating scope
Navigation rule: Always route through domains/platform/CLAUDE.md before accessing knowledge files. The domain CLAUDE.md is the interface — it defines boundaries, dependencies, and freshness policies. Never jump directly to knowledge files.