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.

600 lines (408 loc) • 14.6 kB
--- title: Backend Status dimension: things category: plans tags: ai, auth, backend, convex, frontend related_dimensions: connections, events, groups, knowledge, people 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 plans category. Location: one/things/plans/backend-status.md Purpose: Documents backend status: what's complete, what's next Related dimensions: connections, events, groups, knowledge, people For AI agents: Read this to understand backend status. --- # Backend Status: What's Complete, What's Next **Date:** 2025-10-24 **Status:** āœ… Foundation Complete, 🚧 Features In Progress **Version:** 1.0.0 --- ## Executive Summary The ONE Platform backend is **fully functional with Better Auth integration**. The connection between frontend and backend is working. Here's what exists and what's next. --- ## āœ… COMPLETE: What Already Works ### 1. Authentication Backend (Working) **Location:** `/backend/convex/auth.ts` **Implemented:** - āœ… Email/Password signup - āœ… Email/Password signin - āœ… Sign out - āœ… JWT token generation (access + refresh) - āœ… Password hashing (SHA-256 for demo, needs bcrypt for production) - āœ… Email verification token generation - āœ… Rate limiting (5 mutations per second) - āœ… Sessions table with token validation **Current Flow:** ``` Frontend (Better Auth) → POST /auth/signup ↓ Backend (auth.ts) → Hash password, create user, generate JWT ↓ Frontend stores JWT → Uses for subsequent requests ``` ### 2. Database Schema (Complete) **Location:** `/backend/convex/schema.ts` **Tables:** - āœ… users (email, passwordHash, emailVerified) - āœ… sessions (userId, token, expiresAt) - āœ… groups (slug, name, type, parentGroupId, settings) - āœ… entities (groupId, type, name, properties, status) - āœ… connections (groupId, type, fromId, toId, metadata) - āœ… events (groupId, type, actorId, targetId, timestamp) - āœ… knowledge (groupId, type, text, embedding, metadata) **Status:** - āœ… Schema defined - āœ… All 6 dimensions represented - āœ… Indexes created for common queries - āš ļø Missing: apiKeys table (for API key authentication) ### 3. Frontend Auth Integration (Working) **Location:** `/web/src/lib/auth-client.ts` **Components:** - āœ… Better Auth client configured - āœ… Auth hooks (useSession, useSignIn, useSignUp) - āœ… Auth page (`/account/auth.astro`) - āœ… Tests for auth flows (50+ test cases) - āœ… OAuth configuration (Google, GitHub) **Test Coverage:** - āœ… Email/password signup - āœ… Email/password signin - āœ… Session management - āœ… Token refresh - āœ… OAuth flows ### 4. Core Mutations (Partial) **Location:** `/backend/convex/mutations/` **Implemented:** - āœ… entities.ts (create, update, delete things) - āœ… groups.ts (create, update groups) - āœ… connections.ts (create, delete relationships) - āœ… contact.ts (contact form submissions) - āœ… onboarding.ts (user onboarding) **Status:** - āœ… Basic CRUD for core entities - āš ļø Missing: Full 66 thing types - āš ļø Missing: Event logging on mutations - āš ļø Missing: Group scoping enforcement ### 5. Core Queries (Partial) **Location:** `/backend/convex/queries/` **Implemented:** - āœ… entities.ts (list, get things) - āœ… groups.ts (list, get groups) - āœ… connections.ts (list connections) - āœ… ontology.ts (get available types) - āœ… init.ts (initialization data) **Status:** - āœ… Basic read operations - āš ļø Missing: Vector search for RAG - āš ļø Missing: Complex filtering/sorting ### 6. Services (Partial) **Location:** `/backend/convex/services/` **Implemented:** - āœ… ontologyMapper.ts (map features to ontology) - āœ… websiteAnalyzer.ts (analyze existing websites) - āœ… brandGuideGenerator.ts (generate brand guides) - āœ… featureRecommender.ts (recommend features) **Status:** - āœ… Specialized services working - āš ļø Missing: General CRUD services - āš ļø Missing: RAG service - āš ļø Missing: AI SDK integration --- ## 🚧 IN PROGRESS: What Needs Work ### 1. HTTP API Layer (NOT STARTED) **Needed:** Hono HTTP endpoints for external access **What's Missing:** - [ ] `/backend/convex/http.ts` - Hono setup - [ ] API key authentication middleware - [ ] REST endpoints for all 6 dimensions - [ ] OpenAPI documentation - [ ] Rate limiting per group - [ ] CORS configuration **Priority:** HIGH - Required for multi-client support **Estimated Effort:** 1-2 weeks ### 2. API Key Management (NOT STARTED) **Needed:** API key generation and validation **What's Missing:** - [ ] apiKeys table in schema - [ ] createApiKey mutation - [ ] verifyApiKey query - [ ] revokeApiKey mutation - [ ] API key middleware in Hono **Priority:** HIGH - Needed for external access **Estimated Effort:** 3-4 days ### 3. Event Logging (PARTIAL) **Current:** Events table exists, but not auto-logged **What's Missing:** - [ ] Auto-log events on all mutations - [ ] Event filtering/search - [ ] Timeline views - [ ] Event retention policies **Priority:** MEDIUM - Important for audit trail **Estimated Effort:** 1 week ### 4. Group Scoping (PARTIAL) **Current:** Groups table exists, but not enforced **What's Missing:** - [ ] Middleware to extract groupId from auth - [ ] Enforce groupId on all queries/mutations - [ ] Hierarchical group access (parent → child) - [ ] Resource quotas per group **Priority:** MEDIUM - Critical for multi-tenancy **Estimated Effort:** 1 week ### 5. AI SDK Integration (NOT STARTED) **Needed:** RAG pipeline and AI features **What's Missing:** - [ ] Install AI SDK: `npm install ai @ai-sdk/openai` - [ ] RAG ingestion (document chunking) - [ ] Vector embeddings (OpenAI embedding model) - [ ] Vector search query - [ ] Generation action (with context) - [ ] Streaming support **Priority:** MEDIUM - Needed for AI features **Estimated Effort:** 2 weeks ### 6. Better Auth Expansion (PARTIAL) **Current:** Email/password + basic OAuth setup **What's Missing:** - [ ] Magic links - [ ] Email verification (UI/API) - [ ] Password reset flow - [ ] 2FA (TOTP) - [ ] Session management (revoke, list) - [ ] OAuth provider expansion **Priority:** MEDIUM - Improve security/UX **Estimated Effort:** 1-2 weeks ### 7. Complete CRUD (PARTIAL) **Current:** Basic CRUD for ~5-10 entity types **What's Missing:** - [ ] CRUD mutations for all 66+ thing types - [ ] CRUD for 25 connection types - [ ] Bulk operations - [ ] Batch mutations **Priority:** MEDIUM - Needed for feature completeness **Estimated Effort:** 2-3 weeks ### 8. Production Hardening (NOT STARTED) **What's Missing:** - [ ] Use bcrypt instead of SHA-256 for password hashing - [ ] Input validation on all endpoints - [ ] SQL injection prevention (already handled by Convex) - [ ] Rate limiting tuning - [ ] Security headers - [ ] HTTPS enforcement **Priority:** HIGH - Critical for production **Estimated Effort:** 1 week --- ## Architecture: Current State ``` ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ FRONTEND (Astro + React) │ │ Better Auth Components │ │ āœ… Working & Tested │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ │ JWT Token ↓ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ CONVEX FUNCTIONS (Current) │ │ āœ… Auth (signup/signin/signout) │ │ āœ… Basic CRUD (groups, things) │ │ āš ļø Missing: HTTP API │ │ āš ļø Missing: RAG/AI │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ │ ↓ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ CONVEX DATABASE (Complete) │ │ āœ… 6-dimension ontology schema │ │ āœ… All tables with indexes │ │ āš ļø Missing: apiKeys table │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ``` **Gap:** Frontend currently uses Convex hooks directly. Need HTTP API for: - External clients (mobile, desktop, CLI) - Third-party integrations - Easier client library generation --- ## Next Priority: What to Build First ### Phase 1: HTTP API Layer (Weeks 1-2) **Goal:** Make backend accessible via REST API **Steps:** 1. Install Hono: `npm install hono` 2. Create `http.ts` with Hono app 3. Add API key authentication 4. Implement `/api/health` endpoint 5. Add rate limiting middleware 6. Set up CORS **Deliverable:** External clients can call `/api/health` ### Phase 2: API Key Management (Week 3) **Goal:** Enable API key-based authentication **Steps:** 1. Add `apiKeys` table to schema 2. Create `createApiKey` mutation 3. Create `verifyApiKey` query 4. Add API key middleware 5. Test with curl/Postman **Deliverable:** Can generate and use API keys ### Phase 3: CRUD Endpoints (Weeks 4-5) **Goal:** All 6 dimensions accessible via REST **Steps:** 1. Implement 37 REST endpoints 2. Add input validation 3. Add error handling 4. Add pagination 5. Add filtering/sorting **Deliverable:** Full REST API for all ontology dimensions ### Phase 4: AI SDK Integration (Weeks 6-7) **Goal:** RAG pipeline working **Steps:** 1. Install AI SDK 2. Implement ingestion (chunking) 3. Add embeddings 4. Add vector search 5. Add generation with context **Deliverable:** `/api/ai/search` and `/api/ai/generate` working ### Phase 5: Production Hardening (Week 8) **Goal:** Production-ready backend **Steps:** 1. Use bcrypt for passwords 2. Add input validation 3. Tune rate limits 4. Set up monitoring 5. Security audit **Deliverable:** Backend ready for production deployment --- ## Code Quality Assessment ### āœ… What's Good 1. **Schema Design** - Clean, normalized, well-indexed 2. **Type Safety** - Full TypeScript with Convex types 3. **Error Handling** - Rate limiting, duplicate checking 4. **Testing** - 50+ auth tests with good coverage 5. **Documentation** - Schema well-commented 6. **Multi-tenancy Foundation** - Groups table ready ### āš ļø What Needs Improvement 1. **Password Hashing** - SHA-256 demo → needs bcrypt 2. **Event Logging** - Not auto-logged on mutations 3. **Input Validation** - Minimal validation 4. **Error Messages** - Generic error handling 5. **API Documentation** - No OpenAPI spec 6. **Tests** - Only auth tested, need full coverage --- ## Commands to Get Started ### Install Dependencies ```bash cd backend npm install hono @ai-sdk/openai ai bcryptjs zod ``` ### Create HTTP Layer ```typescript // /backend/convex/http.ts import { Hono } from "hono"; import { cors } from "hono/cors"; import { handle } from "hono/vercel"; import { httpRouter } from "convex/server"; const app = new Hono(); app.use("*", cors()); app.get("/api/health", (c) => { return c.json({ status: "ok" }); }); export default httpRouter({ "/": handle(app), }); ``` ### Test It ```bash # Start dev server npx convex dev # Test endpoint curl http://localhost:3000/api/health # Should return: {"status":"ok"} ``` --- ## Key Files to Reference **Frontend Auth:** - `/web/src/lib/auth-client.ts` - Auth setup - `/web/src/pages/account/auth.astro` - Auth page - `/web/tests/auth/auth.test.ts` - Test examples **Backend Auth:** - `/backend/convex/auth.ts` - Auth mutations - `/backend/convex/auth.config.ts` - Auth config - `/backend/convex/lib/jwt.ts` - JWT utilities **Schema:** - `/backend/convex/schema.ts` - Complete 6-dimension schema - `/backend/convex/types/ontology.ts` - Generated types **CRUD Examples:** - `/backend/convex/mutations/entities.ts` - Example mutations - `/backend/convex/queries/entities.ts` - Example queries --- ## Team Assignments (Cycle-Based) **Phase 1 (HTTP API): Cycle 101-120 (3 weeks)** - Agent-backend: Implement Hono routes - Agent-backend: Add middleware - Agent-quality: Write API tests **Phase 2 (API Keys): Cycle 121-140 (2 weeks)** - Agent-backend: Schema + mutations - Agent-frontend: Generate API key UI - Agent-quality: Security testing **Phase 3 (CRUD): Cycle 141-160 (2 weeks)** - Agent-backend: Implement endpoints - Agent-integrator: Generate OpenAPI - Agent-quality: Integration tests **Phase 4 (AI SDK): Cycle 161-180 (2 weeks)** - Agent-backend: RAG pipeline - Agent-quality: RAG tests - Agent-documenter: API docs **Phase 5 (Production): Cycle 181-200 (1 week)** - Agent-ops: Monitoring setup - Agent-clean: Code review - Agent-documenter: Final docs --- ## Success Metrics After Phase 1 (HTTP API): - āœ… `/api/health` returns 200 - āœ… External clients can query backend - āœ… Rate limiting working After Phase 2 (API Keys): - āœ… Can generate API key - āœ… API key authentication working - āœ… Group-scoped requests After Phase 3 (CRUD): - āœ… All 37 REST endpoints working - āœ… Input validation passing - āœ… Error handling consistent After Phase 4 (AI SDK): - āœ… Vector search working - āœ… Generation with context working - āœ… Streaming responses working After Phase 5 (Production): - āœ… bcrypt passwords - āœ… All tests passing - āœ… OpenAPI documentation - āœ… Monitoring alerts working --- ## Related Documentation - **`one/things/plans/backend.md`** - Complete backend architecture plan - **`one/knowledge/ontology.md`** - 6-dimension specification - **`CLAUDE.md`** - Development workflow - **`web/AGENTS.md`** - Convex patterns reference --- ## What's Working Right Now You can immediately: 1. āœ… Sign up with email/password (frontend) 2. āœ… Sign in with OAuth (Google, GitHub) 3. āœ… Stay logged in (JWT tokens) 4. āœ… Create/update/delete entities (via Convex hooks) 5. āœ… Create/manage groups 6. āœ… View connections and events What's NOT working yet: 1. āŒ External API access (HTTP) 2. āŒ API key authentication 3. āŒ AI/RAG features 4. āŒ Third-party integrations 5. āŒ Mobile apps (no HTTP API) --- ## Bottom Line **The foundation is solid.** Backend auth is working, schema is complete, frontend integration is done. The main gaps are: 1. **HTTP API** - Make it accessible externally 2. **AI SDK** - Add RAG/generation features 3. **Production Hardening** - bcrypt, validation, monitoring Everything else is in place. Build the HTTP layer first (1-2 weeks), then everything else follows naturally. **Status:** 🟢 Ready to build Phase 1 (HTTP API)