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.
440 lines (315 loc) • 12.5 kB
Markdown
---
title: 2 Backend Agnostic Frontend
dimension: things
category: ideas
tags: agent, architecture, backend, connections, convex, events, frontend, ontology, things, ui
related_dimensions: connections, events, groups
scope: global
created: 2025-11-03
updated: 2025-11-03
version: 1.0.0
ai_context: |
This document is part of the things dimension in the ideas category.
Location: one/things/ideas/2-backend-agnostic-frontend.md
Purpose: Documents idea: backend-agnostic frontend architecture
Related dimensions: connections, events, groups
For AI agents: Read this to understand 2 backend agnostic frontend.
---
# Idea: Backend-Agnostic Frontend Architecture
**Status:** Validated by Director Agent
**Decision:** Approved as Plan #2
**Priority:** High - Strategic Enhancement
**Idea Number:** 2
---
## Description
Transform the tightly-coupled Astro/React frontend + Convex backend architecture into a fully backend-agnostic system using the DataProvider interface pattern. This enables organizations to use ANY backend (Convex, WordPress, Notion, Supabase, custom APIs) by changing ONE line of configuration.
**Core Concept:** Introduce a thin abstraction layer (DataProvider interface) that maps the 6-dimension ontology operations to ANY backend implementation. Frontend components use generic hooks (`useThings`, `useConnections`, `useEvents`) that work identically regardless of backend.
**Strategic Value:**
- Removes vendor lock-in (not tied to Convex)
- Enables multi-backend federation (one org uses Convex, another uses WordPress)
- Supports organizations with existing infrastructure
- Proves ontology is truly protocol-agnostic
- Opens market to enterprises with backend requirements
---
## Problem Statement
**Current Architecture:**
```
Frontend Components → Convex Hooks (useQuery/useMutation) → Convex Backend
```
**Issues:**
1. Frontend tightly coupled to Convex SDK
2. Cannot swap backends without rewriting components
3. Organizations locked into Convex infrastructure
4. Violates "protocol-agnostic" ontology principle
5. Hard to support enterprises with existing systems
**Example Lock-in:**
```typescript
// Current: Tightly coupled to Convex
import { useQuery } from "convex/react";
import { api } from "@/convex/_generated/api";
function MyComponent() {
const entities = useQuery(api.queries.entities.list, { type: "course" });
// Component now depends on Convex API structure
}
```
---
## Proposed Solution
**New Architecture:**
```
Frontend Components → DataProvider Interface → Backend Adapter → Any Backend
↓
ConvexProvider | WordPressProvider | NotionProvider
```
**Key Components:**
### 1. DataProvider Interface
```typescript
interface DataProvider {
// 6-dimension ontology operations
things: ThingOperations;
connections: ConnectionOperations;
events: EventOperations;
knowledge: KnowledgeOperations;
organizations: OrganizationOperations;
people: PeopleOperations;
}
```
### 2. Configuration System
```typescript
// One line to configure backend
export const dataProvider = createDataProvider({
type: "convex", // or "wordpress" | "notion" | "supabase"
config: { url: process.env.BACKEND_URL },
});
```
### 3. Generic React Hooks
```typescript
// Works with ANY backend
function MyComponent() {
const entities = useThings({ type: "course" });
// Component now backend-agnostic
}
```
---
## Ontology Validation
### 1. Organizations (Who owns what at org level)
- ✅ Each organization configures `properties.backendProvider`
- ✅ Multi-tenant isolation maintained across ALL providers
- ✅ Organizations can swap providers independently
- ✅ Example: `org_123` uses Convex, `org_456` uses WordPress
### 2. People (Who can do what)
- ✅ Only `org_owner` role can configure backend providers
- ✅ Authorization enforced at backend, NOT frontend
- ✅ All 4 roles work identically across providers
- ✅ Frontend never sees auth implementation details
### 3. Things (All entities)
- ✅ New thing type: `external_connection` (backend configurations)
- ✅ All 66 thing types work through DataProvider interface
- ✅ Generic ThingService handles all types uniformly
- ✅ Example: `creator`, `course`, `lesson` work on any backend
### 4. Connections (All relationships)
- ✅ New relationship: `configured_by` (org → external_connection)
- ✅ Uses consolidated type: `communicated` with `metadata.protocol`
- ✅ Cross-backend connections supported (Convex course → WordPress user)
- ✅ Example: `owns`, `enrolled_in`, `part_of` work identically
### 5. Events (All actions)
- ✅ New event: `provider_changed` (when backend swaps)
- ✅ Uses consolidated type: `communication_event` with protocol metadata
- ✅ Complete audit trail preserved regardless of backend
- ✅ Example: `course_created`, `lesson_completed` logged to events table
### 6. Knowledge (Labels + vectors)
- ✅ Labels tag backend provider capabilities
- ✅ Tags: `protocol:data_provider`, `provider:convex`, `status:active`
- ✅ RAG can index provider documentation for help system
- ✅ Example: Search "how to configure WordPress backend"
**Verdict:** ✅ PASS - All 6 dimensions successfully mapped
---
## Complexity Assessment
**Scope:** Medium-Large (4-6 weeks for full implementation)
**Breakdown:**
- Week 1-2: DataProvider interface + ConvexProvider + Config system
- Week 2-3: Effect.ts service layer (ThingService, ConnectionService, etc.)
- Week 3-4: Migrate auth components (50+ tests must pass)
- Week 4-5: Migrate dashboard components
- Week 5: Remove direct Convex dependencies
- Week 6: Implement alternative providers (WordPress + Notion)
**Risk:** Medium
**Risks:**
1. Auth tests break during migration (50+ test cases)
2. Performance regression (additional abstraction layer)
3. TypeScript errors proliferate across codebase
4. Context budget explosion (more files to maintain)
**Mitigation:**
1. Run auth tests after EVERY component migration
2. Benchmark performance, target <10ms overhead
3. Strong interface types from day 1
4. Use code generation for boilerplate
---
## Success Criteria
### Immediate (MVP - Week 2)
- [ ] DataProvider interface defined and typed
- [ ] ConvexProvider implemented and tested
- [ ] Configuration system working
- [ ] ONE component migrated as proof of concept
- [ ] All existing tests still pass
### Near-term (Month 1)
- [ ] All auth components use DataProvider (50+ tests pass)
- [ ] All dashboard components use DataProvider
- [ ] Zero direct Convex imports in components
- [ ] Performance within 10% of baseline
- [ ] TypeScript compiles with zero errors
### Long-term (Month 2)
- [ ] WordPress provider functional
- [ ] Notion provider functional
- [ ] Organizations can swap backends via config
- [ ] Complete documentation and migration guide
- [ ] 98% context reduction (150K → 3K tokens)
---
## Business Impact
**Why this matters:**
1. **Market Expansion:** Enterprises with existing backends can adopt
2. **Vendor Independence:** Not locked into any single backend
3. **Federation:** Multi-backend support enables broader use cases
4. **Ontology Proof:** Proves 6-dimension model is truly universal
5. **Developer Velocity:** Clear patterns for ALL future features
6. **Cost Flexibility:** Organizations choose backend based on needs
**Cost-benefit:**
- **Investment:** 4-6 weeks upfront
- **Return:** Opens enterprise market, reduces vendor risk
- **Break-even:** First enterprise customer with backend requirement
- **Ongoing:** 50% faster to add new providers after initial implementation
**Strategic Alignment:**
- Aligns with "protocol-agnostic" ontology principle
- Supports multi-tenant flexibility
- Enables beautiful, simple, powerful systems (our philosophy)
- Proves architecture scales from lemonade stands to enterprises
---
## Technical Architecture
### Layer 1: DataProvider Interface (Protocol)
```typescript
// Defines WHAT operations are possible (ontology operations)
interface DataProvider {
things: ThingOperations;
connections: ConnectionOperations;
events: EventOperations;
// ... other 6-dimension operations
}
```
### Layer 2: Backend Adapters (Implementation)
```typescript
// Defines HOW operations work for specific backends
class ConvexProvider implements DataProvider { ... }
class WordPressProvider implements DataProvider { ... }
class NotionProvider implements DataProvider { ... }
```
### Layer 3: Effect.ts Services (Business Logic)
```typescript
// Pure business logic, backend-agnostic
class ThingService {
constructor(private provider: DataProvider) {}
async createThing(args: CreateThingArgs): Promise<Thing> {
// Validation, business rules, then:
return this.provider.things.create(args);
}
}
```
### Layer 4: React Hooks (Frontend API)
```typescript
// Simple, type-safe hooks for components
function useThings(filter: ThingFilter): Thing[] {
const provider = useDataProvider();
return provider.things.list(filter);
}
```
### Layer 5: Components (UI)
```typescript
// Clean, backend-agnostic components
function EntityList({ type }: { type: string }) {
const entities = useThings({ type });
return <div>{entities.map(e => <EntityCard key={e._id} entity={e} />)}</div>;
}
```
**Separation of Concerns:**
- Interface defines protocol (ontology operations)
- Adapters handle backend specifics
- Services implement business logic
- Hooks provide React integration
- Components focus on UI only
---
## Migration Strategy
### Phase 1: Foundation (Non-breaking)
1. Add DataProvider interface
2. Implement ConvexProvider (wraps existing Convex hooks)
3. Add configuration system
4. Migrate ONE component to prove pattern
**Rollback:** Easy - just don't use new provider
### Phase 2: Auth Migration (Breaking)
1. Migrate auth components one by one
2. Run auth tests after EACH component
3. Keep rollback branch at each milestone
**Rollback:** Revert to previous commit, restore Convex hooks
### Phase 3: Full Migration (Breaking)
1. Migrate all remaining components
2. Remove direct Convex dependencies
3. Update documentation
**Rollback:** Not possible after Feature 6 completes
### Phase 4: Alternative Providers (Additive)
1. Implement WordPress provider
2. Implement Notion provider
3. Prove organizations can swap backends
**Rollback:** Not needed - purely additive
---
## Next Steps
**Director Agent Decision:**
- ✅ Approved as Plan #2
- ✅ Assign plan number: `2-backend-agnostic-frontend`
- ✅ Create team structure:
- Backend Specialist (DataProvider interface, services, ConvexProvider)
- Frontend Specialist (Auth migration, dashboard migration, hooks)
- Integration Specialist (Alternative providers, remove dependencies)
**Proceed to Level 2 (PLANS):**
- Break into 7 features (see feature list below)
- Assign features to specialists
- Create feature specifications
- Define success criteria and tests
---
## Feature Breakdown
### Feature 2-1: DataProvider Interface & ConvexProvider
**Owner:** Backend Specialist
**Duration:** 1 week
**Dependencies:** None
### Feature 2-2: Configuration System
**Owner:** Backend Specialist
**Duration:** 3 days
**Dependencies:** Feature 2-1
### Feature 2-3: Effect.ts Service Layer
**Owner:** Backend Specialist
**Duration:** 1 week
**Dependencies:** Features 2-1, 2-2
### Feature 2-4: React Hooks
**Owner:** Frontend Specialist
**Duration:** 3 days
**Dependencies:** Feature 2-1
### Feature 2-5: Auth Component Migration
**Owner:** Frontend Specialist
**Duration:** 1 week
**Dependencies:** Features 2-1, 2-4
### Feature 2-6: Dashboard Component Migration
**Owner:** Frontend Specialist
**Duration:** 1 week
**Dependencies:** Feature 2-5
### Feature 2-7: Alternative Providers (WordPress + Notion)
**Owner:** Integration Specialist
**Duration:** 2 weeks
**Dependencies:** Feature 2-6
---
## References
- **Ontology:** `one/knowledge/ontology.md` (6-dimension specification)
- **Patterns:** `one/connections/patterns.md` (implementation patterns)
- **Architecture:** `one/knowledge/architecture.md` (system design)
- **Original Plan:** `one/things/plans/backend-agnostic-frontend.md` (detailed plan)
- **Philosophy:** Protocol-agnostic ontology. Everything else is just data.
---
**Status:** Validated ✅ → Proceeding to Plan #2
**Created:** 2025-10-13
**Validated By:** Engineering Director Agent
**Ontology Check:** ✅ PASS (all 6 dimensions mapped)