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
Markdown
---
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)