UNPKG

oneie

Version:

Build apps, websites, and AI agents in English. Zero-interaction setup for AI agents (Claude Code, Cursor, Windsurf). Download to your computer, run in the cloud, deploy to the edge. Open source and free forever.

1,560 lines (1,256 loc) 58.6 kB
--- title: Architecture dimension: knowledge category: architecture.md tags: agent, ai, architecture, people, system-design related_dimensions: people, things scope: global created: 2025-11-03 updated: 2025-11-03 version: 1.0.0 ai_context: | This document is part of the knowledge dimension in the architecture.md category. Location: one/knowledge/architecture.md Purpose: Documents one platform - the universal code generation language Related dimensions: people, things For AI agents: Read this to understand architecture. --- # ONE Platform - The Universal Code Generation Language **Version:** 3.0.0 **Purpose:** Explain how ONE creates a Domain-Specific Language (DSL) that enables compound structure accuracy in AI code generation --- ## Why This Changes Everything ### The Breakthrough Insight **Most people think AI code generation has a fundamental problem: it gets worse as codebases grow.** They're right. But not because AI is fundamentally limited. Because **traditional architectures are optimized for humans, not AI**. ONE flips this. It creates an architecture where: - **Every new line of code makes the next line MORE accurate** - **The 10,000-file codebase is EASIER than the 100-file codebase** - **Agents don't just write code—they BUILD a universal language** This isn't incremental improvement. **This is a paradigm shift.** ### The Economic Impact **Traditional Development:** - Developer writes 100 lines/day - AI assistance degrades over time - Technical debt compounds - Codebases become unmaintainable - **Cost scales linearly with codebase size** **ONE Development:** - Agent generates 10,000 lines/day (100x) - AI accuracy improves over time (98%+) - Structure compounds (technical credit) - Codebases become MORE maintainable - **Cost scales sublinearly—larger codebases are cheaper per feature** **Result:** 100x developer productivity. Not hyperbole. Math. ### The "Aha Moment" Traditional codebases have **infinite ways to express the same concept**: ```typescript // 10 different ways to create a user createUser(email) addUser(email) registerUser(email) insertUser(email) saveUser(email) User.create(email) new User(email).save() db.users.add(email) await createNewUser(email) userService.register(email) ``` **Agents see:** 10 different patterns. Accuracy degrades. ONE has **ONE way**: ```typescript // Always the same pattern provider.things.create({ type: "user", name: email, properties: { email } }) ``` **Agents see:** ONE pattern. Accuracy compounds. **This is the insight.** Restrict expressiveness for humans (slight cost). Maximize pattern recognition for AI (massive gain). --- ## The Core Vision This isn't about "simplifying for beginners." This is about creating a **Domain-Specific Language (DSL)** that: 1. **Models reality, not technology** (groups, people, things, connections, events, knowledge) 2. **Never breaks** (because reality doesn't change, even when technology does) 3. **Makes each line of code add structure** (compound accuracy over time) 4. **Enables universal feature import** (clone ANY system into the ontology) ### The Problem with Traditional Architectures **Traditional AI code generation degrades over time:** ``` Generation 1: Clean code → 95% accurate Generation 2: Slight drift → 90% accurate (-5% - patterns starting to diverge) Generation 3: Pattern divergence → 80% accurate (-10% - AI sees multiple patterns) Generation 4: Inconsistency → 65% accurate (-15% - AI confused by variations) Generation N: Unmaintainable mess → 30% accurate (-20% - complete chaos) ``` **Why?** 1. No universal structure (every feature introduces new patterns) 2. Technology-specific abstractions leak (React patterns, SQL patterns, REST patterns) 3. Infinite expressiveness (100 ways to do the same thing) 4. Implicit dependencies (global state, side effects) 5. Untyped errors (try/catch everywhere, no pattern) **The death spiral:** Each feature makes the next feature HARDER to generate accurately. ### The ONE Approach: Compound Structure Accuracy **ONE's AI code generation improves over time:** ``` Generation 1: Maps to ontology → 85% accurate (learning the ontology) Generation 2: Follows patterns → 90% accurate (+5% - recognizing service pattern) Generation 3: Reuses services → 93% accurate (+3% - composing existing services) Generation 4: Predictable structure → 96% accurate (+3% - mastering Effect.ts patterns) Generation N: Perfect consistency → 98%+ accurate (+2% - generalized patterns) ``` **Why?** 1. Universal structure (everything maps to 6 dimensions) 2. Reality-based abstraction (groups/people/things never change) 3. Restricted expressiveness (ONE way to do each thing) 4. Explicit dependencies (Effect.ts makes everything visible) 5. Typed errors (tagged unions, exhaustive patterns) **The virtuous cycle:** Each feature makes the next feature EASIER to generate accurately. ### Visual: Pattern Convergence vs Divergence **Traditional Codebase (Pattern Divergence):** ``` Feature 1: createUser(email) ────────┐ Feature 2: addProduct(name) ─────────┼─→ 10 patterns Feature 3: registerCustomer(data) ───┤ AI confused Feature 4: insertOrder(items) ───────┤ Accuracy: 30% Feature 5: saveInvoice(invoice) ─────┘ ...each uses different approach ``` **ONE Codebase (Pattern Convergence):** ``` Feature 1: provider.things.create({ type: "user" }) ────┐ Feature 2: provider.things.create({ type: "product" }) ─┼─→ 1 pattern Feature 3: provider.things.create({ type: "customer" })─┤ AI masters it Feature 4: provider.things.create({ type: "order" }) ───┤ Accuracy: 98% Feature 5: provider.things.create({ type: "invoice" }) ─┘ ...all use same pattern ``` **The difference:** Traditional codebases teach AI 100 patterns (chaos). ONE teaches AI 1 pattern (mastery). --- ## The Three Pillars of the Universal Language ### Pillar 1: The 6-Dimension Ontology (Reality as DSL) **The ontology IS the language. Every feature in every system maps to these 6 dimensions:** ```typescript interface Reality { groups: Container[]; // Hierarchical spaces (friend circles → governments) people: Actor[]; // Authorization (who can do what) things: Entity[]; // All nouns (users, products, courses, agents) connections: Relation[]; // All verbs (owns, enrolled_in, purchased) events: Action[]; // Audit trail (what happened when) knowledge: Embedding[]; // Understanding (RAG, search, AI) } ``` **Why this works:** 1. **Reality doesn't change** - Groups always contain things, people always authorize, connections always relate 2. **Technology does change** - React → Svelte, REST → GraphQL, MySQL → Convex 3. **The ontology maps to ALL technology** - It's an abstraction of reality itself 4. **Agents understand reality** - Not framework-specific patterns **Example: Mapping Shopify to the Ontology** ``` Shopify Products → things (type: product) Shopify Customers → people (role: customer) Shopify Orders → connections (type: purchased) + events (type: order_placed) Shopify Cart → connections (type: in_cart) Shopify Inventory → properties on product thing Shopify Admin → people (role: org_owner) Shopify Store → groups (type: business) ``` **The agent doesn't learn Shopify. It learns the ontology. Shopify maps to it.** ### Pillar 2: Effect.ts (Composable Structure for Agents) **Effect.ts isn't for humans. It's for AGENTS.** Humans see this: ```typescript const registerUser = Effect.gen(function* () { const validated = yield* validateUser(input); const user = yield* createUser(validated); yield* sendEmail(user); return user; }); ``` Agents see this: ``` PATTERN DETECTED: Service composition - Input: unknown data - Step 1: Validation (Effect<T, ValidationError>) - Step 2: Persistence (Effect<T, DatabaseError>) - Step 3: Side effect (Effect<void, EmailError>) - Output: Success or tagged union error - PREDICTABLE. STRUCTURED. COMPOSABLE. ``` **Why Effect.ts:** 1. **Readable** - Each line is a discrete step (agents can parse steps) 2. **Structured** - Error handling is explicit (tagged unions, no try/catch) 3. **Composable** - Services chain together predictably (agents compose services) 4. **Type-safe** - 100% typed (`Effect<Success, Error, Dependencies>`) 5. **Agent-friendly** - Patterns are consistent across entire codebase **Every service follows this pattern. Every. Single. One. That's compound structure.** ### Pillar 3: Provider Pattern (Universal Adapter) **The provider pattern isn't "extra complexity" - it's the UNIVERSAL INTERFACE.** ```typescript // Frontend speaks ontology (never changes) const provider = getContentProvider("products"); const products = await provider.things.list(); // Backend can be ANYTHING: // - Shopify, WordPress, Convex, Supabase, Custom API // The ontology is the CONTRACT ``` **This is how agent-clone imports ANY feature from ANY system.** ```typescript // Same interface for ALL backends interface ContentProvider { things: { list: (opts) => Effect.Effect<Thing[], QueryError>; get: (id) => Effect.Effect<Thing, NotFoundError>; create: (input) => Effect.Effect<string, CreateError>; }; connections: { /* ... */ }; events: { /* ... */ }; knowledge: { /* ... */ }; } ``` **Implementations:** - `MarkdownProvider` - Development (static files) - `ConvexProvider` - Production (real-time database) - `ShopifyProvider` - E-commerce (Shopify API → ontology) - `WordPressProvider` - Content (WordPress REST → ontology) - `SupabaseProvider` - Custom backend (PostgreSQL → ontology) **The frontend code NEVER changes. One env var switches backends.** --- ## Counter-Arguments Addressed ### "Effect.ts is too verbose and complex" **Counter:** Effect.ts isn't designed for human reading pleasure. It's designed for AI pattern recognition. Compare these: **Option A: Concise (for humans)** ```typescript async function buy(id) { const p = await stripe.charge(99); const t = await mint(id); await db.add(p, t); } ``` **Option B: Explicit (for agents)** ```typescript const buy = (id: string): Effect.Effect<Purchase, StripeError | MintError | DbError> => Effect.gen(function* () { const payment = yield* stripe.charge(99); const tokens = yield* mint(id); const purchase = yield* db.insert({ payment, tokens }); return purchase; }); ``` **Humans prefer A** (less typing, looks cleaner). **Agents need B** because: 1. Input/output types are explicit (`string` → `Purchase`) 2. All possible errors are in the signature (`StripeError | MintError | DbError`) 3. Every dependency is visible (no hidden imports) 4. Every step is discrete (can be pattern-matched) 5. Composition is predictable (always `Effect.gen` + `yield*`) **The tradeoff:** Write 20% more code. Get 300% better AI accuracy. Worth it. ### "The ontology is too generic—you lose domain specificity" **Counter:** Generic schema, specific metadata. Best of both worlds. **Bad approach:** Custom tables for everything ```sql CREATE TABLE courses (...) CREATE TABLE products (...) CREATE TABLE events (...) CREATE TABLE workshops (...) -- 100 custom tables = 100 patterns = AI confusion ``` **ONE approach:** One schema, rich metadata ```typescript // All are "things" with type-specific properties { type: "course", properties: { instructor, curriculum, duration } } { type: "product", properties: { price, inventory, variants } } { type: "event", properties: { date, location, capacity } } { type: "workshop", properties: { instructor, materials, prerequisites } } ``` **Why this works:** - **AI learns ONE pattern** (create thing → connection → event → knowledge) - **Full type safety** (Zod schemas validate properties per type) - **Domain flexibility** (properties can be ANYTHING for each type) - **Query simplicity** (`things.filter(t => t.type === "course")`) **You don't lose specificity. You gain universality.** ### "Nanostores adds unnecessary complexity" **Counter:** Nanostores REMOVES complexity by providing structure. **Without nanostores (Astro islands can't communicate):** ```typescript // Island 1: Header.tsx (can't access cart) // Island 2: AddToCart.tsx (can't update header) // Island 3: CartSidebar.tsx (can't sync with others) // "Solutions": // - localStorage (unstructured, no types) // - URL params (messy, limited data) // - window.dispatchEvent (no types, manual sync) // - Rebuild as SPA (lose Astro benefits) ``` **With nanostores (ONE pattern):** ```typescript // stores/cart.ts export const cart$ = atom<CartItem[]>([]); // ANY island can read/write const cart = useStore(cart$); cart$.set([...cart, newItem]); ``` **Agents see:** ONE way to share state across islands. Pattern learned. Accuracy compounds. ### "Provider pattern is over-engineering" **Counter:** Provider pattern is the ONLY way to achieve backend agnosticism. **Without providers:** ```typescript // Tightly coupled to Convex const product = await ctx.db.query("products").first(); // Want to switch to WordPress? REWRITE EVERYTHING. ``` **With providers:** ```typescript // Backend-agnostic const product = await provider.things.get(productId); // Switch backends with ONE ENV VAR: // CONTENT_SOURCE=markdown (development) // CONTENT_SOURCE=convex (production) // CONTENT_SOURCE=wordpress (existing site) // CONTENT_SOURCE=shopify (e-commerce) // CODE NEVER CHANGES. ``` **This isn't over-engineering. This is the MINIMUM structure needed for true portability.** --- ## The Agent's Perspective: What AI Actually "Sees" ### Humans vs Agents **Humans think in concepts:** - "I need to create a user" - "I should add authentication" - "Let's build a shopping cart" **Agents think in patterns:** - "I've seen `provider.things.create` 47 times. 98% confidence this is the pattern." - "Every time I see `Effect.gen`, the next line is `yield*`. 100% confidence." - "Services always have dependencies in the constructor. Pattern complete." ### What Traditional Codebases Look Like to Agents **Agent analyzing traditional codebase:** ``` File 1: createUser(email) { await db.users.insert({email}) } File 2: addProduct(name, price) { await database.products.add({name, price}) } File 3: registerCustomer(data) { try { await api.post('/customers', data) } catch (e) { ... } } File 4: insertOrder(items) { const order = new Order(items); await order.save(); } File 5: saveInvoice(inv) { await db.collection('invoices').insertOne(inv) } AGENT ANALYSIS: - Pattern confidence: 23% - 5 different function naming conventions - 4 different data access patterns - 3 different error handling approaches - 2 different promise patterns - PREDICTION: Next "create entity" function will use ??? ACCURACY: 45% (guessing) ``` **Agent analyzing ONE codebase:** ``` File 1: provider.things.create({ type: "user", name: email, properties: { email } }) File 2: provider.things.create({ type: "product", name, properties: { price } }) File 3: provider.things.create({ type: "customer", name: data.name, properties: data }) File 4: provider.things.create({ type: "order", name: `Order ${id}`, properties: { items } }) File 5: provider.things.create({ type: "invoice", name: inv.number, properties: inv }) AGENT ANALYSIS: - Pattern confidence: 98% - 1 function pattern (provider.things.create) - 1 data structure ({ type, name, properties }) - 1 error handling pattern (Effect errors) - 1 promise pattern (Effect<T, E>) - PREDICTION: Next "create entity" function will use provider.things.create ACCURACY: 98% (certainty) ``` **The difference:** Traditional code requires AI to be a "code psychic" (guess the pattern). ONE code requires AI to be a "pattern matcher" (recognize the pattern). ### Learning Progression: How Agents Master ONE **Generation 1-5: Learning the Ontology (85% accurate)** Agent thinks: ``` "I see things being created with `type` field. Let me check..." "All entities are things? Even users, products, courses?" "Connections link things together. Got it." "Events log actions. People are actors." "Pattern emerging: 6 dimensions for everything." CONFIDENCE: 85% (still learning) ``` **Generation 6-20: Recognizing Patterns (90% accurate)** Agent thinks: ``` "Every create operation uses provider.things.create. 100% of the time." "Every service uses Effect.gen. Pattern confirmed." "All errors are tagged unions. I can handle exhaustively." "Dependencies are injected. I know what's needed." CONFIDENCE: 90% (pattern recognized) ``` **Generation 21-50: Composing Services (93% accurate)** Agent thinks: ``` "I can reuse existing services:" "- createThing service exists" "- createConnection service exists" "- logEvent service exists" "My new feature: compose these three services." "No new patterns needed. Just composition." CONFIDENCE: 93% (composing existing patterns) ``` **Generation 51-100: Mastering Structure (96% accurate)** Agent thinks: ``` "I've generated 50 services. All follow same structure:" "1. Get provider from context" "2. Call provider operation" "3. Handle typed errors" "4. Return typed result" "Pattern is UNIVERSAL. Works for ANY feature." CONFIDENCE: 96% (mastered the structure) ``` **Generation 100+: Generalizing (98%+ accurate)** Agent thinks: ``` "I don't even need to think. The pattern IS the system." "New feature request? Map to 6 dimensions." "Need validation? Effect.ts service." "Need data? Provider interface." "Need state? Nanostores." "Every decision is deterministic." CONFIDENCE: 98%+ (system internalized) ``` --- ## What 98% Accuracy Enables ### Today (With 30-70% AI Accuracy) **Development workflow:** 1. Developer writes spec (1 hour) 2. AI generates code (30-70% accurate) 3. Developer fixes bugs (3-5 hours) 4. Developer refactors for consistency (2 hours) 5. **Total: 6-8 hours per feature** **Economics:** - AI saves maybe 30% of time - Still need senior developers - Still accumulates technical debt - **Cost: $150/hour × 6 hours = $900/feature** ### Tomorrow (With 98% AI Accuracy via ONE) **Development workflow:** 1. Developer writes spec (1 hour) 2. AI generates code (98% accurate) 3. Developer reviews (30 minutes) 4. **Total: 1.5 hours per feature** **Economics:** - AI saves 80% of time - Junior developers can review - Structure compounds (technical credit) - **Cost: $50/hour × 1.5 hours = $75/feature** **Result: 12x cheaper per feature. Not 2x. 12x.** ### Future (With Agent-Clone) **Development workflow:** 1. Point agent-clone at Shopify repo (5 minutes) 2. AI maps to ontology automatically (5 minutes) 3. AI generates entire e-commerce platform (10 minutes) 4. **Total: 20 minutes for full clone** **Economics:** - Cloning Shopify from scratch normally takes 6-12 months - With agent-clone: 20 minutes - **Time savings: 99.999%** - **Cost savings: Infinite (effectively free after ONE setup)** ### What Becomes Possible **1. Infinite Customization (No Cost Penalty)** Traditional: Every customization adds technical debt. Eventually unmaintainable. ONE: Every customization adds to the ontology. System becomes MORE maintainable. **2. Instant Platform Migration** Traditional: Migrating from WordPress to custom backend takes months. ONE: Switch `CONTENT_SOURCE` env var. Done in 1 minute. **3. Universal Feature Import** Traditional: Want Shopify's checkout? Build it from scratch (3 months). ONE: Point agent-clone at Shopify. Clone checkout feature (20 minutes). **4. Compound Velocity** Traditional: Feature #100 takes LONGER than feature #1 (technical debt). ONE: Feature #100 takes LESS TIME than feature #1 (pattern reuse). **5. AI-Native Development** Traditional: AI is an assistant. Human is the driver. ONE: AI is the primary builder. Human is the architect. --- ## Real Metrics: Why This Matters ### Context Efficiency **Before (Traditional Architecture):** - Agent needs to read 10,000+ lines to understand patterns - 80% of context is irrelevant to current task - Pattern recognition confidence: 30-50% - Generation time: 60 seconds per feature - **Cost: $0.06/1k tokens × 50k tokens = $3/feature** **After (ONE Architecture):** - Agent needs to read 2,000 lines (ontology + patterns) - 90% of context is directly relevant - Pattern recognition confidence: 98% - Generation time: 15 seconds per feature - **Cost: $0.06/1k tokens × 5k tokens = $0.30/feature** **Result: 10x context efficiency. 4x faster. 10x cheaper.** ### Accuracy Compounding **Example: Building a SaaS with 100 features** **Traditional approach:** ``` Feature 1-10: 90% accurate × 10 = 9 working features, 1 broken Feature 11-20: 80% accurate × 10 = 8 working features, 2 broken Feature 21-30: 70% accurate × 10 = 7 working features, 3 broken Feature 31-40: 60% accurate × 10 = 6 working features, 4 broken ... Feature 91-100: 30% accurate × 10 = 3 working features, 7 broken Total: 50/100 features working correctly Time to fix: 250 hours (debugging mess) ``` **ONE approach:** ``` Feature 1-10: 85% accurate × 10 = 8.5 working features, 1.5 broken Feature 11-20: 90% accurate × 10 = 9 working features, 1 broken Feature 21-30: 93% accurate × 10 = 9.3 working features, 0.7 broken Feature 31-40: 96% accurate × 10 = 9.6 working features, 0.4 broken ... Feature 91-100: 98% accurate × 10 = 9.8 working features, 0.2 broken Total: 95/100 features working correctly Time to fix: 25 hours (minor tweaks) ``` **Difference:** - 1.9x more working features - 10x less debugging time - System is MORE maintainable at the end (not less) ### The Exponential Payoff **Feature #1:** - Traditional: 8 hours (70% AI, 30% human) - ONE: 8 hours (70% AI, 30% human) - **No difference yet** **Feature #10:** - Traditional: 10 hours (60% AI, 40% human - patterns diverging) - ONE: 6 hours (85% AI, 15% human - patterns converging) - **ONE is 1.7x faster** **Feature #50:** - Traditional: 16 hours (40% AI, 60% human - technical debt) - ONE: 3 hours (95% AI, 5% human - pattern mastery) - **ONE is 5.3x faster** **Feature #100:** - Traditional: 24 hours (25% AI, 75% human - chaos) - ONE: 1.5 hours (98% AI, 2% human - generalized) - **ONE is 16x faster** **Cumulative for 100 features:** - Traditional: 1,400 hours - ONE: 350 hours - **ONE is 4x faster overall** - **And the gap keeps growing** --- ## The Architecture: Layered Reality **Every single thing in ONE platform exists within one of these 6 dimensions:** ``` ┌──────────────────────────────────────────────────────────────┐ │ 1. GROUPS │ │ Multi-tenant isolation with hierarchical nesting - who owns │ │ what at group level (friend circles → DAOs → governments) │ └──────────────────────────────────────────────────────────────┘ ↓ ┌──────────────────────────────────────────────────────────────┐ │ 2. PEOPLE │ │ Authorization & governance - platform owner, group owners │ └──────────────────────────────────────────────────────────────┘ ↓ ┌──────────────────────────────────────────────────────────────┐ │ 3. THINGS │ │ Every "thing" - users, agents, content, tokens, courses │ └──────────────────────────────────────────────────────────────┘ ↓ ┌──────────────────────────────────────────────────────────────┐ │ 4. CONNECTIONS │ │ Every relationship - owns, follows, taught_by, powers │ └──────────────────────────────────────────────────────────────┘ ↓ ┌──────────────────────────────────────────────────────────────┐ │ 5. EVENTS │ │ Every action - purchased, created, viewed, completed │ └──────────────────────────────────────────────────────────────┘ ↓ ┌──────────────────────────────────────────────────────────────┐ │ 6. KNOWLEDGE │ │ Labels + chunks + vectors powering RAG & search │ └──────────────────────────────────────────────────────────────┘ ``` **How Technology Layers Implement the 6-Dimension DSL:** ``` ┌─────────────────────────────────────────────────────────────────────┐ │ LAYER 1: UNIVERSAL INTERFACE │ │ (The 6-Dimension DSL) │ ├─────────────────────────────────────────────────────────────────────┤ │ groups → Hierarchical containers (friend circles → governments)│ │ people → Authorization & governance (who can do what) │ │ things → All entities (66 types: user, product, course...) │ │ connections → All relationships (25 types: owns, purchased...) │ │ events → All actions (67 types: created, updated, logged...) │ │ knowledge → AI understanding (embeddings, search, RAG) │ │ │ │ This layer NEVER changes. It models reality. │ └──────────────────┬──────────────────────────────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ LAYER 2: COMPOSITION ENGINE │ │ (Effect.ts Services) │ ├─────────────────────────────────────────────────────────────────────┤ │ ALL business logic (pure functional programming) │ │ ├─ Service layer (composable business logic) │ │ ├─ Provider layer (external system adapters) │ │ ├─ Layer system (dependency injection) │ │ └─ 100% Effect.ts (typed errors, automatic retry/timeout) │ │ │ │ Services compose ontology operations into features. │ └──────────────────┬──────────────────────────────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ LAYER 3: TECHNOLOGY ADAPTERS │ │ (Convex, Hono, Astro, React) │ ├─────────────────────────────────────────────────────────────────────┤ │ Backend: Hono API + Convex Database (implements ontology) │ │ Frontend: Astro SSR + React Islands (renders ontology) │ │ Real-time: Convex hooks (live ontology subscriptions) │ │ Static: Astro Content Collections (ontology as files) │ │ │ │ Technology can be swapped. Ontology stays the same. │ └─────────────────────────────────────────────────────────────────────┘ ``` ### Layer Interactions **Example: User purchases a course** ```typescript // LAYER 1: Ontology (The Language) // These dimensions are ALWAYS the same, regardless of technology Group: "fitnesspro" (organization boundary) Person: "john@fitnesspro.com" (actor, role: customer) Thing: "Fitness Fundamentals" (entity, type: course) Connection: john -[purchased]-> course (relationship) Event: "purchase_completed" (action, actorId: john) Knowledge: "John likes fitness courses" (AI learning) // LAYER 2: Service (Effect.ts - The Composition) const purchaseCourse = Effect.gen(function* () { const provider = yield* DataProvider; // Step 1: Validate (ontology operation) const person = yield* provider.people.get(userId); const course = yield* provider.things.get(courseId); // Step 2: Create connection (ontology operation) const purchase = yield* provider.connections.create({ fromPersonId: person._id, toThingId: course._id, relationshipType: "purchased", metadata: { amount: 99, method: "stripe" }, }); // Step 3: Log event (ontology operation) yield* provider.events.log({ type: "purchase_completed", actorId: person._id, targetId: purchase._id, metadata: { amount: 99 }, }); return { success: true, purchaseId: purchase._id }; }); // LAYER 3: Technology (Adapters - The Implementation) // Convex implementation class ConvexProvider implements DataProvider { people = { get: (id) => Effect.tryPromise({ try: () => this.client.query(api.people.get, { id }), catch: (e) => new PersonNotFoundError(id), }), }; // ... implements all ontology operations } // WordPress implementation (different technology, SAME interface) class WordPressProvider implements DataProvider { people = { get: (id) => Effect.tryPromise({ try: () => wpClient.users.get(id).then(mapToOntology), catch: (e) => new PersonNotFoundError(id), }), }; // ... implements all ontology operations } // Frontend (Astro + React) const purchaseButton = ( <Button onClick={() => provider.purchaseCourse(courseId)}> Buy Course </Button> ); ``` **The magic:** Same ontology operations work with Convex, WordPress, Shopify, Supabase, or ANY backend. The frontend never changes. --- ## Why This Enables Compound Structure Accuracy ### Traditional Approach: Degrading Patterns ```typescript // Generation 1: Create user (initial pattern) async function createUser(email: string) { const user = await db.users.create({ email }); return user; } // Generation 2: Create product (different pattern - drift begins) async function createProduct(name: string) { try { const product = await db.products.insert({ name }); await logProductCreated(product); return product; } catch (e) { console.error(e); throw new Error("Failed"); } } // Generation 3: Create course (more drift) async function createCourse(title: string) { let course; try { course = await database.addCourse({ title }); await notifyAdmins(course); await updateMetrics("course_created"); } catch (error) { if (course) { await database.deleteCourse(course.id); } throw error; } return course; } // Agent sees three different patterns. Accuracy degrades. ``` ### ONE Approach: Converging Patterns ```typescript // Generation 1: Create user (ontology pattern) export const createUser = Effect.gen(function* () { const provider = yield* DataProvider; const userId = yield* provider.things.create({ type: "user", name: input.email, properties: { email: input.email }, }); return userId; }); // Generation 2: Create product (SAME ontology pattern) export const createProduct = Effect.gen(function* () { const provider = yield* DataProvider; const productId = yield* provider.things.create({ type: "product", name: input.name, properties: { price: input.price }, }); return productId; }); // Generation 3: Create course (SAME ontology pattern) export const createCourse = Effect.gen(function* () { const provider = yield* DataProvider; const courseId = yield* provider.things.create({ type: "course", name: input.title, properties: { instructor: input.instructor }, }); return courseId; }); // Agent sees ONE pattern. Accuracy compounds. ``` **What the agent learns:** ``` PATTERN: Create entity 1. Get DataProvider from context 2. Call provider.things.create() 3. Specify type (maps to thingType in ontology) 4. Specify name (required field) 5. Specify properties (type-specific data) 6. Return entity ID (Effect<string, CreateError>) LEARNED: This pattern works for ALL entity types. RESULT: Next generation uses same pattern → more accurate. ``` ### Compound Structure in Action ```typescript // Generation 50: Agent has seen 49 entity creation patterns // Agent recognizes the universal pattern immediately export const createAnything = <T extends Thing>( type: ThingType, input: CreateThingInput<T> ) => Effect.gen(function* () { const provider = yield* DataProvider; // Validation (learned pattern) const validated = yield* validateThing(type, input); // Creation (learned pattern) const thingId = yield* provider.things.create({ type, name: validated.name, properties: validated.properties, }); // Event logging (learned pattern) yield* provider.events.log({ type: `${type}_created`, actorId: validated.creatorId, targetId: thingId, }); return thingId; }); // Agent has GENERALIZED the pattern. // Accuracy is now 98%+ because pattern is universal. ``` --- ## The 6-Dimension Ontology: Complete Specification ### Dimension 1: Groups (Containers) **Purpose:** Hierarchical spaces that partition all other dimensions. **For comprehensive documentation, see:** `/one/connections/groups.md` ```typescript interface Group { _id: Id<"groups">; slug: string; // Unique identifier (URL-friendly) name: string; type: "friend_circle" | "business" | "community" | "dao" | "government" | "organization"; parentGroupId?: Id<"groups">; // CRITICAL: Infinite hierarchical nesting description?: string; metadata: any; settings: { visibility: "public" | "private"; joinPolicy: "open" | "invite_only" | "approval_required"; plan?: "starter" | "pro" | "enterprise"; limits?: { users: number; storage: number; apiCalls: number; }; }; status: "active" | "archived"; createdAt: number; updatedAt: number; } ``` **Key insights:** - **Every other dimension is scoped to a `groupId`** - This is the foundation of multi-tenancy - **Groups can contain groups** - Hierarchical via `parentGroupId` (infinite nesting) - **Scales infinitely** - From friend circles (2 people) to governments (billions) - **Multi-tenancy:** Each group has isolated data, billing, quotas, and customization - **6 group types:** friend_circle, business, community, dao, government, organization - **Access control:** Parent groups can access child groups (configurable) **Why groups are dimension #1:** - Without groups → single-tenant system - With groups → infinite multi-tenant scale - All queries MUST filter by `groupId` first - All entities MUST include `groupId` field **See `/one/connections/groups.md` for:** - Complete group lifecycle (create, update, archive) - Hierarchical query patterns (children, descendants, ancestors) - Multi-tenancy isolation guarantees - Access control patterns - Usage tracking & quotas - Real-world examples (lemonade stand → enterprise → DAO) ### Dimension 2: People (Authorization) **Purpose:** Actors who perform actions and control access. **Conceptual Model (for understanding):** ```typescript interface Person { _id: Id<"entities">; // NOTE: Stored in entities table type: "creator" | "ai_clone" | "audience_member"; name: string; groupId: Id<"groups">; properties: { email: string; username?: string; displayName?: string; role: "platform_owner" | "org_owner" | "org_user" | "customer"; groups?: Id<"groups">[]; // Multi-org membership permissions?: string[]; image?: string; bio?: string; }; status: "active" | "inactive" | "archived"; createdAt: number; updatedAt: number; } ``` **Implementation Note:** People are **conceptually a separate dimension** but **implemented as entities** with special types (`creator`, `ai_clone`, `audience_member`). This design choice provides: 1. **Unified interface:** All dimensions use the same base structure (groupId, type, name, properties) 2. **Flexible properties:** Role and permissions stored in `properties.role` field 3. **Relationship simplicity:** Connections can link people ↔ things without special handling 4. **Query efficiency:** Same index patterns work for people and things **Why not a separate table?** - Eliminates JOIN operations (people and things share connections) - Consistent query patterns (all entities use same indexes) - Simpler schema evolution (one entity type system) - Better agent code generation (one pattern to learn, not two) **Key insights:** - Every action has an `actorId` (entity with type="creator") - Roles define permissions (stored in `properties.role`) - People can belong to multiple groups (via `properties.groups` array) - Implementation uses entities table, but conceptually a separate dimension ### Dimension 3: Things (Entities) **Purpose:** All nouns in the system. ```typescript interface Thing { _id: Id<"things">; type: ThingType; // 66 types: user, product, course, agent, token... name: string; groupId: Id<"groups">; // Scoped to group description?: string; properties: any; // Type-specific data (flexible) status: "draft" | "active" | "published" | "archived"; createdAt: number; updatedAt: number; } ``` **66 thing types organized by domain:** **Platform:** website, landing_page, template, livestream, recording, media_asset **Content:** post, article, lesson, module, course, series **Commerce:** product, variant, collection, subscription, plan **Social:** creator, community, group, event **Business:** invoice, payment, metric, insight, prediction, report **Crypto:** token, wallet, nft, contract **AI:** agent, model, prompt, workflow **Communication:** notification, email, message, announcement **Key insights:** - Flexible `properties` field for type-specific data - Every thing belongs to a group (scoped) - Status lifecycle: draft → active → published → archived ### Dimension 4: Connections (Relationships) **Purpose:** All relationships between entities. ```typescript interface Connection { _id: Id<"connections">; fromThingId?: Id<"things">; toThingId?: Id<"things">; fromPersonId?: Id<"people">; // Can connect people → things toPersonId?: Id<"people">; // Or people → people relationshipType: ConnectionType; // 25 types groupId: Id<"groups">; // Scoped to group metadata: any; // Relationship-specific data createdAt: number; } ``` **25 connection types (consolidated):** **User Relationships (6):** follows, subscribes_to, owns, purchased, created, manages **Content Relationships (6):** belongs_to, tagged_with, appears_in, references, derived_from, version_of **Token & Financial (5):** holds_tokens, staked_in, earned_from, spent_on, paid_for **Platform & Infrastructure (4):** hosted_on, deployed_to, integrated_with, streamed_on **Business & Analytics (3):** tracked_by, invoiced_by, referred_by **Key insights:** - Bidirectional (from → to) - Rich metadata for relationship-specific data - Can connect things ↔ things, people ↔ things, people ↔ people - Temporal validity (can add validFrom/validTo to metadata) ### Dimension 5: Events (Actions) **Purpose:** Complete audit trail of all actions over time. ```typescript interface Event { _id: Id<"events">; type: EventType; // 55 types (44 specific + 11 consolidated) actorId: Id<"people">; // REQUIRED: Who did it targetId?: Id<"things"> | Id<"people"> | Id<"connections">; // What was acted upon groupId: Id<"groups">; // Scoped to group metadata: any; // Event-specific data timestamp: number; } ``` **55 event types (44 specific + 11 consolidated):** **Entity Lifecycle (4):** entity_created, entity_updated, entity_deleted, entity_archived **User Events (5):** user_registered, user_verified, user_login, user_logout, profile_updated **Authentication Events (6):** password_reset_requested, password_reset_completed, email_verification_sent, email_verified, two_factor_enabled, two_factor_disabled **Organization Events (5):** organization_created, organization_updated, user_invited_to_org, user_joined_org, user_removed_from_org **Dashboard & UI Events (4):** dashboard_viewed, settings_updated, theme_changed, preferences_updated **AI/Clone Events (4):** clone_created, clone_updated, voice_cloned, appearance_cloned **Agent Events (4):** agent_created, agent_executed, agent_completed, agent_failed **Token Events (7):** token_created, token_minted, token_burned, tokens_purchased, tokens_staked, tokens_unstaked, tokens_transferred **Course Events (5):** course_created, course_enrolled, lesson_completed, course_completed, certificate_earned **Analytics Events (5):** metric_calculated, insight_generated, prediction_made, optimization_applied, report_generated **Consolidated Event Types (11):** content_event, payment_event, subscription_event, commerce_event, livestream_event, notification_event, referral_event, communication_event, task_event, mandate_event, price_event (use metadata.action for variants) **Key insights:** - Every event has an `actorId` (person) - Events are immutable (append-only) - Rich metadata for event-specific data - Enables complete audit trail, analytics, AI learning ### Dimension 6: Knowledge (Understanding) **Purpose:** Embeddings, vectors, and semantic search for AI. ```typescript interface Knowledge { _id: Id<"knowledge">; type: "embedding" | "label" | "category" | "tag"; text?: string; embedding?: number[]; // Vector embedding embeddingModel?: string; embeddingDim?: number; sourceThingId?: Id<"things">; sourcePersonId?: Id<"people">; groupId: Id<"groups">; // Scoped to group labels?: string[]; metadata?: any; createdAt: number; updatedAt: number; } ``` **Key insights:** - Vector storage for RAG (Retrieval-Augmented Generation) - Linked to things/people via sourceId - Enables semantic search, recommendations, AI learning - Scoped to groups (knowledge isolation) --- ## Protocols as Metadata: Universal Integration **X402 (Blockchain Settlement)** ```typescript yield* provider.connections.create({ fromPersonId: senderId, toPersonId: receiverId, relationshipType: "transacted", metadata: { protocol: "x402", blockchain: "ethereum", amount: "1.5", currency: "USDC", txHash: "0x...", }, }); ``` **ActivityPub 2.0 (Federation)** ```typescript yield* provider.connections.create({ fromPersonId: localUserId, toPersonId: remoteUserId, relationshipType: "follows", metadata: { protocol: "activitypub", activityType: "Follow", actor: "https://mastodon.social/@user", object: "https://one.ie/@otheruser", }, }); ``` **A2A (Agent-to-Agent)** ```typescript yield* provider.connections.create({ fromThingId: agentId1, toThingId: agentId2, relationshipType: "delegated", metadata: { protocol: "a2a", task: "generate_invoice", status: "pending", payload: { orderId: "123" }, }, }); ``` **Key insight:** Protocols don't require new tables or schemas. They're just metadata on connections. The ontology is protocol-agnostic. --- ## Technology Layer: Implementation Details ### Backend: Convex + Hono + Effect.ts **Convex Schema (Plain, No Convex Ents):** ```typescript // backend/convex/schema.ts export default defineSchema({ groups: defineTable({ name: v.string(), type: v.string(), parentGroupId: v.optional(v.id("groups")), properties: v.any(), status: v.string(), createdAt: v.number(), updatedAt: v.number(), }).index("by_type", ["type"]), people: defineTable({ email: v.string(), username: v.string(), displayName: v.string(), role: v.string(), groupId: v.id("groups"), groups: v.array(v.id("groups")), createdAt: v.number(), updatedAt: v.number(), }).index("by_email", ["email"]) .index("by_group", ["groupId"]), things: defineTable({ type: v.string(), name: v.string(), groupId: v.id("groups"), properties: v.any(), status: v.string(), createdAt: v.number(), updatedAt: v.number(), }).index("by_type", ["type"]) .index("by_group", ["groupId"]) .index("by_group_type", ["groupId", "type"]), connections: defineTable({ fromThingId: v.optional(v.id("things")), toThingId: v.optional(v.id("things")), fromPersonId: v.optional(v.id("people")), toPersonId: v.optional(v.id("people")), relationshipType: v.string(), groupId: v.id("groups"), metadata: v.any(), createdAt: v.number(), }).index("by_from_thing", ["fromThingId"]) .index("by_to_thing", ["toThingId"]) .index("by_from_person", ["fromPersonId"]) .index("by_to_person", ["toPersonId"]) .index("by_relationship", ["relationshipType"]) .index("by_group", ["groupId"]), events: defineTable({ type: v.string(), actorId: v.id("people"), targetId: v.optional(v.union(v.id("things"), v.id("people"), v.id("connections"))), groupId: v.id("groups"), metadata: v.any(), timestamp: v.number(), }).index("by_actor", ["actorId"]) .index("by_target", ["targetId"]) .index("by_type", ["type"]) .index("by_group", ["groupId"]) .index("by_timestamp", ["timestamp"]), knowledge: defineTable({ type: v.string(), text: v.optional(v.string()), embedding: v.optional(v.array(v.number())), embeddingModel: v.optional(v.string()), sourceThingId: v.optional(v.id("things")), sourcePersonId: v.optional(v.id("people")), groupId: v.id("groups"), labels: v.optional(v.array(v.string())), metadata: v.optional(v.any()), createdAt: v.number(), updatedAt: v.number(), }).index("by_source_thing", ["sourceThingId"]) .index("by_source_person", ["sourcePersonId"]) .index("by_group", ["groupId"]) .vectorIndex("by_embedding", { vectorField: "embedding", dimensions: 768, filterFields: ["type", "groupId"], }), }); ``` **Effect.ts Service Pattern:** ```typescript // backend/convex/services/things.ts export class ThingService extends Effect.Service<ThingService>()("ThingService", { effect: Effect.gen(function* () { const db = yield* ConvexDatabase; return { create: (input: CreateThingInput) => Effect.gen(function* () { // Validation const validated = yield* validateThing(input); // Creation const thingId = yield* db.insert("things", { type: validated.type, name: validated.name, groupId: validated.groupId, properties: validated.properties, status: "draft", createdAt: Date.now(), updatedAt: Date.now(), }); // Event logging yield* db.insert("events", { type: `${validated.type}_created`, actorId: validated.creatorId, targetId: thingId, groupId: validated.groupId, metadata: {}, timestamp: Date.now(), }); return thingId; }).pipe( Effect.retry({ times: 3 }), Effect.timeout("30 seconds"), Effect.catchTags({ ValidationError: (e) => Effect.fail(new ThingCreateError(e)), DatabaseError: (e) => Effect.fail(new ThingCreateError(e)), }) ), }; }), dependencies: [ConvexDatabase.Default], }) {} ``` ### Frontend: Astro + React + Provider Pattern **Progressive Complexity (5 Layers):** **Layer 1:** Content + Pages (static) - 80% of apps stop here **Layer 2:** + Validation (Effect.ts services) - 15% of apps **Layer 3:** + State (Nanostores + hooks) - 4% of apps **Layer 4:** + Multiple Sources (provider pattern) - 1% of apps **Layer 5:** + Backend (REST API + database) - <1% of apps **Layer 1 Example (Blog):** ```astro --- // src/pages/blog/index.astro import { getCollection } from "astro:content"; const posts = await getCollection("posts"); --- <Layout> {posts.map(post => ( <PostCard post={post.data} /> ))} </Layout> ``` **Layer 4 Example (Multi-Source):** ```typescript // src/lib/providers/getContentProvider.ts export function getContentProvider(collection: string) { const mode = import.meta.env.CONTENT_SOURCE || "markdown"; switch (mode) { case "api": return new ApiProvider(apiUrl); case "hybrid": return new HybridProvider( new ApiProvider(apiUrl), new MarkdownProvider(collection) ); default: return new MarkdownProvider(collection); } } // Same code, different backends const provider = getContentProvider("products"); const products = await provider.things.list({ type: "product" }); ``` --- ## Agent Clone: Import ANY Feature from ANY System ### Example: Clone Shopify E-commerce ```bash npx oneie clone https://github.com/Shopify/shopify-api-node ``` **Agent workflow:** **Step 1: Analyze Shopify schema** ``` Products → things (type: product) Customers → people (role: customer) Orders → connections (purchased) + events (order_placed) Cart → connections (in_cart) Inventory → thing properties Collections → groups (type: collection) ``` **Step 2: Generate ShopifyProvider** ```typescript export class ShopifyProvider implements ContentProvider { things = { list: ({ type }) => { if (type === "product") { return Effect.tryPromise({ try: async () => { const products = await shopify.product.list(); return products.map(p => ({ _id: p.id, type: "product", name: p.title, properties: { price: p.variants[0].price, inventory: p.variants[0].inventory_quantity, shopifyId: p.id, }, })); }, catch: (e) => new QueryError(String(e)), }); } }, }; // ... implement all ontology operations } ``` **Step 3: Generate Effect.ts services** ```typescript export const createOrder = Effect.gen(function* () { const provider = yield* DataProvider; const product = yield* provider.things.get(productId); const customer = yield* provider.people.get(customerId); const connection = yield* provider.connections.create({ fromPersonId: customer._id, toThingId: product._id, relationshipType: "purchased", metadata: { quantity, price: product.properties.price }, }); yield* provider.events.log({ type: "order_placed", actorId: customer._id, targetId: connection._id, metadata: { amount: quantity * product.properties.price }, });