Namaste Ji by Ayushman Dash

Docs / frameworks.md · mirrored from the repo

Frameworks, stack & patterns

Status: operational reference. The technologies the system runs on and the recurring code patterns we apply, with the why for each. Choices are Cloudflare-first (P-9); the deep rationale lives in BACK-OFFICE.md (BO-*) and ARCHITECTURE.md (D-*). Companion to SYSTEM-DESIGN.md and PRINCIPLES.md.

1. Runtime substrate (Cloudflare)

LayerTechRole / notes
Durable orchestrationCloudflare WorkflowsGA durable execution: per-step retries, persisted state, waitForEvent for human gates. The orchestration spine (BO-2).
Stateful agentsCloudflare Agents SDK (agents)Each agent is a Durable Object (identity, SQLite state, WebSockets, scheduling, agents/observability). Avoid preview bits on the critical path.
Request handlersWorkers (+ Hono for services)console-api and agents are Workers; Hono is the HTTP framework.
FrontendReact + Vite → Cloudflare Pagesapps/console (Direct Upload, CI-deployed). Consumer frontend TBD (Android-first).
Async fan-outQueuesPipeline render/embed have independent queues for independent backpressure; one shared DLQ.
SchedulingCron Triggers + Agents scheduled tasksRollout, prefetch, profile/playlist rebuilds, batch polling.
ResearchBrowser RenderingScraping/inspiration where needed.

2. Data & storage

ConcernTechPattern
Metadata / control / auditD1 (SQLite)No ORM — typed access modules over raw prepared statements; the row shape is a JSON payload + a few promoted/indexed columns (see @namaste-ji/catalog). Parse payload → contract on read; keep indexed columns in sync on write.
Asset bytesR2 + Cloudflare ImagesMasters + device/network-sized variants; cache-first (P-7).
Operational configKV (@namaste-ji/config)Non-safety knobs; anything safety-shaped goes in the Control DO, not KV.
VectorsVectorize (cloud) / Qdrant (local)Behind a VectorIndex port; one multimodal index (dim 1024) for retrieval/dedup/diversity/analysis.

3. Model & AI layer

ConcernTechNotes
Model interfaceVercel AI SDK (ai) behind ModelPort / EmbedderPortProvider-agnostic LanguageModel/EmbeddingModel; our own interface so a provider swap is config (BO-2).
Routing/cost/cache/logsAI GatewayAll production model calls route through it; BYOK (provider keys live in the gateway, not code).
Prompt registry + tracing + evalsLangfusePrompts resolved by name@label (cache + last-known-good fallback); resolved version logged in the trace. AI Gateway routes; Langfuse registers/traces — separate concerns (AK-6).
Text LLM (local)Ollama (OSS models)Local dev loop; behavioural parity, not identical to prod model.
Multimodal embeddings (local)Infinity + jina-clip-v2Ollama can’t embed images; Infinity is the local CLIP workhorse.
Multimodal embeddings (cloud)Jina CLIP v2 / Cohere embed-v4 / Voyage or Workers AIBehind EmbedderPort; Matryoshka-truncatable to the index dim.

Considered, not adopted: Mastra (great TS agent framework, but brings its own durable-workflow + memory model that overlaps Workflows + Agents-SDK-on-DO — we borrow its ideas, e.g. evals-first, not its runtime, BO-2).

4. Contracts, types & validation

  • Zod versioned contracts in @namaste-ji/shared are the interface between components: the brief, the Content Strategy (strategy@vN), FeedPolicy, OnboardingSignals. A downstream agent consumes one cold, so contracts are immutable + versioned + reproducible (CP-3, FL-2, P-13).
  • TypeScript everywhere (incl. infra — Alchemy is pure TS). @cloudflare/workers-types on Workers.

5. Control, auth & governance

ConcernTech
Autonomy / gates / kill switchControl Durable Object (policy engine, WebSocket broadcast)
BO authCloudflare Access (perimeter SSO/MFA) + D1 RBAC (@namaste-ji/rbac) — coarse in Access, fine in app
Consumer authBetter Auth on Workers (D1-native, phone-OTP + social, no per-MAU fee)
SecretsCloudflare Secrets Store (secrets_store_secrets bindings)
ExperimentationStatsigdeferred to the consumer/frontend plane; the BO uses KV + Control DO + vars

6. Infra, CI/CD & tooling

ConcernTech
Infra as codeAlchemy (infra/alchemy.run.ts) — provisions CF backing resources; account hard-pinned
DeployGitHub Actions → Wrangler (CI-as-deployer, path-scoped; wrangler v4 on Node 22)
Local meshDocker Compose (Workers via wrangler dev/workerd, + Ollama/Infinity/Qdrant)
Monoreponpm workspaces now → Turborepo --affected when the JS apps grow (CI-2)
Qualitytypecheck + the /code-review, /security-review, /simplify, /verify skills; tests per-workspace where present

7. Recurring patterns (apply these, don’t reinvent)

PatternWhat it isWhere
Ports & adaptersProvider-agnostic interface (ModelPort/EmbedderPort/VectorIndex); local vs cloud adapters swap by configBACK-OFFICE §2–4 (P-12)
Versioned Zod contractsThe typed, immutable interface between agents/stages@namaste-ji/shared (P-13)
Agent Kernel + manifestOne agent shape; new agent = manifest + prompts, not a runtimeAGENT-KERNEL.md (P-19)
Subagent-as-tool + context firewallSubagent burns context internally, returns distilled artifact + lineageAK-4 (P-20)
Reflection loopgenerate → critique → revise against a rubric, as a WorkflowAP §5
Isomorphic serving/simOne rank() / coldStartVector() for both the Feed Lab and productionFEED-LAB.md (P-14)
JSON-payload + indexed-columns D1 rowsStore the contract as JSON, promote a few columns for querying@namaste-ji/catalog
Object-presentation contractsClassify an object’s shape → apply the matching list/detail/action pattern; server-authoritative collections; URL-stateconsole/DESIGN-PATTERNS.md
Markdown artifacts (YAML frontmatter)Agent outputs are readable + diffable; machine fields in frontmatterAK-7 (P-25)
IaC + CI-as-deployerAlchemy owns resources; CI deploys only changed targetsCI-1/CI-4 (P-16)

8. Adoption stance

  • Core (committed): Agents SDK, Workflows, Workers/Pages/Hono, D1/R2/KV/Vectorize/Queues, Vercel AI SDK behind our ports, AI Gateway, Langfuse, Alchemy, Zod, Cloudflare Access + D1 RBAC.
  • Adopt-when-needed: Better Auth (consumer surface), Statsig (frontend plane), Turborepo (JS monorepo growth), Cloudflare State Store for Alchemy.
  • Borrowed, not adopted: Mastra’s ideas (evals-first), the funnel machinery of TikTok/IG/YT with an inverted objective (DIST §4).