Architecture & Orchestration
OmniTek
A distributed operating system for businesses.
Cell-based multi-tenancy meets event-driven LLM orchestration.
Scroll
Vercel Edge Isolated Shards Row-Level Security

Global Multi-Tenant Topology

OmniTek solves the multi-tenancy problem using a strict Database-per-Tenant (Isolated Cell) model, decoupled by a stateless edge routing layer. The system is split into a Control Plane (fleet management) and a Tenant Plane (isolated execution environments).

Ingress

Stateless Routing

The Next.js tier contains zero hardcoded tenant logic. proxy.ts queries the Control Plane and injects Supabase credentials on the fly.

Isolation

Hard Boundaries

Each tenant lives in a physically distinct Supabase project. RLS provides secondary logical isolation, eliminating noisy neighbors.

Click to Enlarge
graph TD classDef control fill:#ffffff,stroke:#ef2f9a,stroke-width:2px,color:#112229,rx:12,ry:12; classDef tenant fill:#ffffff,stroke:#0aa4cf,stroke-width:2px,color:#112229,rx:12,ry:12; classDef edge fill:#f8f9fa,stroke:#4a5d66,stroke-width:1px,color:#112229,stroke-dasharray: 4 4,rx:12,ry:12; classDef user fill:#ffffff,stroke:#112229,stroke-width:2px,color:#112229,rx:99,ry:99; U1[User: acme.com]:::user --> V[Vercel Edge Network]:::edge U2[User: beta.omnitek.io]:::user --> V subgraph "Vercel Stateless Routing Layer" V --> P(proxy.ts Middleware):::edge end P -- "1. Resolve Hostname\n2. Fetch DB Credentials" --> CP[(Control Plane DB)]:::control CP -. "x-tenant-supabase-url\nx-tenant-anon-key" .-> P P -- "3. Route Request + Headers" --> N[Next.js App Server]:::edge N -- "createServerClient()" --> T1[(Tenant A: Acme)]:::tenant N -- "createServerClient()" --> T2[(Tenant B: Beta)]:::tenant N -- "createServerClient()" --> T3[(Tenant C: Corp)]:::tenant
Claude 3 pgmq Task Workers Deno Edge

The "Teleplay" Orchestration

The "One Prompt Does Everything" model relies on a hierarchical agent network that fans out tasks asynchronously. We model agents as the CPU, Skills as the ABI, and Edge Functions as the Actuators.

Reliability

Execution Guarantees

By offloading execution from the synchronous HTTP request to a pgmq-backed background worker queue, OmniTek achieves At-Least-Once delivery for AI commands. If an Edge Function times out, the Task Worker retries automatically.

Click to Enlarge
sequenceDiagram autonumber actor Human participant ChatRoute as Next.js API participant RAG as Context Assembler participant LLM as Orchestrator participant TaskQ as tasks (PG) participant Worker as pgmq Worker participant Edge as Deno Edge Human->>ChatRoute: "Onboard Sarah..." ChatRoute->>RAG: Retrieve Context RAG-->>ChatRoute: Vector + KG Context ChatRoute->>LLM: Prompt + Tools Note over LLM: Decomposes intent LLM->>ChatRoute: Call: delegate(HR, IT) ChatRoute->>TaskQ: INSERT (status: pending) ChatRoute-->>Human: "Delegating tasks..." Note over TaskQ, Worker: Async Execution Layer Worker->>TaskQ: Claim tasks (SKIP LOCKED) Worker->>Edge: Invoke hr-platform Edge->>Edge: Execute External API Edge->>TaskQ: UPDATE action_log Worker->>TaskQ: Mark task 'completed'
pgvector Postgres Triggers Knowledge Graph

Event-Driven RAG Pipeline

Knowledge indexing is a continuous, reactive subsystem. Any state mutation in the tenant plane triggers an immediate vectorization and graph extraction pipeline natively at the database level.

Triggers

Reactive Indexing

Invoked via PostgreSQL triggers attached to critical tables, guaranteeing every business event is queued for indexing without dual-writes.

Search

Five-Layer Retrieval

Combines Metadata filtering, Dense Vector Search (70%), Sparse Keyword (30%), and Entity Graph Traversal.

Click to Enlarge
flowchart LR classDef db fill:#ffffff,stroke:#0aa4cf,stroke-width:2px,color:#112229,rx:8,ry:8; classDef trigger fill:#ffffff,stroke:#ff8a3d,stroke-width:2px,color:#112229,rx:99,ry:99; classDef edge fill:#ffffff,stroke:#ef2f9a,stroke-width:2px,color:#112229,rx:8,ry:8; subgraph "Tenant Operational State" AL[(action_log)]:::db D[(decisions)]:::db CRM[(crm_*)]:::db end TR((Postgres Trigger)):::trigger AL --> TR D --> TR CRM --> TR TR -- pg_net Async HTTP --> RAG[rag-pipeline]:::edge subgraph "Processing (Deno)" RAG --> CH[Adaptive Chunking] RAG --> LLM_EXT[Entity Extraction] CH --> EMB[text-embedding-3] end subgraph "Knowledge Repository" DOC[(documents)]:::db KG[(kg_entities)]:::db VEC[(pgvector)]:::db end EMB --> VEC CH --> DOC LLM_EXT --> KG