oneie 3.6.25 → 3.6.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/TROUBLESHOOTING.md +530 -0
- package/.claude/agents/agent-builder.md +226 -198
- package/.claude/agents/agent-claude.md +645 -0
- package/.claude/agents/agent-designer.md +166 -11
- package/.claude/agents/agent-director.md +109 -41
- package/.claude/agents/agent-frontend.md +314 -27
- package/.claude/agents/agent-quality.md +377 -0
- package/.claude/commands/chat.md +504 -0
- package/.claude/commands/create.md +134 -18
- package/.claude/commands/fast.md +531 -0
- package/.claude/commands/one.md +12 -85
- package/.claude/commands/optimize.md +74 -0
- package/.claude/commands/plan.md +420 -373
- package/.claude/commands/review.md +99 -0
- package/.claude/commands/test.md +197 -0
- package/.claude/commands/validate.md +140 -0
- package/.claude/hooks/__pycache__/todo.cpython-312.pyc +0 -0
- package/.claude/hooks/auto-format.sh +106 -0
- package/.claude/hooks/formatting.py +187 -0
- package/.claude/hooks/ontology-validation.py +255 -0
- package/.claude/hooks/validate-imports.py +182 -0
- package/.claude/hooks/validate-ontology.py +140 -0
- package/CLAUDE.md +105 -0
- package/dist/commands/agent.d.ts +18 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +271 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-detection.d.ts +19 -0
- package/dist/lib/agent-detection.d.ts.map +1 -0
- package/dist/lib/agent-detection.js +87 -0
- package/dist/lib/agent-detection.js.map +1 -0
- package/dist/lib/detect.d.ts +45 -0
- package/dist/lib/detect.d.ts.map +1 -0
- package/dist/lib/detect.js +221 -0
- package/dist/lib/detect.js.map +1 -0
- package/llms.txt +257 -0
- package/one/knowledge/cascading-context-specification.md +1617 -0
- package/one/knowledge/claude-code-integration.md +1293 -0
- package/one/knowledge/development-commands.md +251 -0
- package/one/knowledge/games-english.md +691 -0
- package/one/knowledge/games.md +1082 -0
- package/one/knowledge/guidelines.md +314 -0
- package/one/knowledge/parallel-agents.md +932 -0
- package/one/knowledge/performance.md +459 -0
- package/one/knowledge/troubleshooting.md +434 -0
- package/one/things/plans/dsl-claude-code.md +1011 -0
- package/one/things/plans/npx-agent-safety.md +785 -0
- package/one/things/plans/npx-agent.md +1089 -0
- package/one/things/plans/remove-backend-development-from-agents.md +1331 -0
- package/package.json +3 -2
- package/.claude/agents/AUDIT-agent-ops-alignment.md +0 -379
|
@@ -0,0 +1,1331 @@
|
|
|
1
|
+
# Plan: Frontend-First Development Strategy
|
|
2
|
+
|
|
3
|
+
**Status:** Draft
|
|
4
|
+
**Version:** 1.0.0
|
|
5
|
+
**Created:** 2025-11-07
|
|
6
|
+
**Owner:** Platform Team
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## TL;DR
|
|
11
|
+
|
|
12
|
+
**🚨 CRITICAL: ALL AGENTS DEFAULT TO FRONTEND-ONLY 🚨**
|
|
13
|
+
|
|
14
|
+
**DEFAULT BEHAVIOR:**
|
|
15
|
+
- ✅ Build frontend with nanostores (NO backend code)
|
|
16
|
+
- ✅ Use Stripe.js for payments (client-side)
|
|
17
|
+
- ✅ Use Astro + React for UI
|
|
18
|
+
- ✅ Deploy to Vercel/Netlify
|
|
19
|
+
- ❌ NEVER import Convex
|
|
20
|
+
- ❌ NEVER write backend code
|
|
21
|
+
- ❌ NEVER create mutations/queries
|
|
22
|
+
|
|
23
|
+
**UNLESS user explicitly says:**
|
|
24
|
+
- "Use the backend"
|
|
25
|
+
- "Add groups/multi-tenant"
|
|
26
|
+
- "Integrate with ONE Platform"
|
|
27
|
+
- "Use services from /web/src/services"
|
|
28
|
+
|
|
29
|
+
**Then** help integrate existing services (don't build new backend code).
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
**Production apps with NO backend:**
|
|
34
|
+
- 🛒 **Ecommerce:** nanostores + Stripe.js
|
|
35
|
+
- 🎓 **LMS:** nanostores + local state
|
|
36
|
+
- 💼 **SaaS:** nanostores + localStorage
|
|
37
|
+
|
|
38
|
+
**Optional ONE Platform backend:**
|
|
39
|
+
- 👥 Groups (multi-tenant)
|
|
40
|
+
- 🔐 Multi-user (auth + roles)
|
|
41
|
+
- 📊 Events (tracking)
|
|
42
|
+
- 🔗 Connections (relationships)
|
|
43
|
+
- 🧠 Knowledge (RAG)
|
|
44
|
+
|
|
45
|
+
**Integration:** Import `/web/src/services` + `/web/src/providers` when explicitly requested.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Problem Statement
|
|
50
|
+
|
|
51
|
+
When users request features like "build an ecommerce store," agents currently default to building both backend and frontend, even though:
|
|
52
|
+
|
|
53
|
+
1. **Users can build PRODUCTION-READY apps** with NO backend code
|
|
54
|
+
2. **Everything works in the browser** - payments (Stripe), storage (nanostores), business logic
|
|
55
|
+
3. **Backend is ONLY needed for** authentication and multi-device sync
|
|
56
|
+
4. **Frontend agents should build first** - focus on pure frontend development
|
|
57
|
+
|
|
58
|
+
**Current behavior:**
|
|
59
|
+
- User: "Build an ecommerce store with Stripe"
|
|
60
|
+
- Agent: Creates Convex backend, mutations, queries, schema, AND frontend
|
|
61
|
+
- Result: User forced to deploy backend, manage database, configure Convex
|
|
62
|
+
|
|
63
|
+
**Desired behavior:**
|
|
64
|
+
- User: "Build an ecommerce store with Stripe"
|
|
65
|
+
- Agent: Creates pure frontend with nanostores + Stripe.js client-side
|
|
66
|
+
- Result: **COMPLETE, WORKING ECOMMERCE STORE** with NO backend code
|
|
67
|
+
- User: "Add auth so users can access from multiple devices" (explicit need)
|
|
68
|
+
- Agent: Then adds backend for auth + multi-device sync
|
|
69
|
+
|
|
70
|
+
## Real-World Examples (NO Backend Needed)
|
|
71
|
+
|
|
72
|
+
### ✅ Full Ecommerce Store
|
|
73
|
+
- Product catalog (nanostores)
|
|
74
|
+
- Shopping cart (persistent in browser)
|
|
75
|
+
- Stripe checkout (client-side Stripe.js)
|
|
76
|
+
- Order history (localStorage)
|
|
77
|
+
- **NO backend required**
|
|
78
|
+
|
|
79
|
+
### ✅ Learning Management System
|
|
80
|
+
- Course catalog with videos, lessons, quizzes (nanostores)
|
|
81
|
+
- Lesson content and resources (local data)
|
|
82
|
+
- Progress tracking per course (persistent in browser)
|
|
83
|
+
- Certificates generated client-side (canvas/PDF)
|
|
84
|
+
- Quiz results and scoring (nanostores)
|
|
85
|
+
- **NO backend required**
|
|
86
|
+
- **Add backend later** for multi-user authentication
|
|
87
|
+
|
|
88
|
+
### ✅ Project Management Tool
|
|
89
|
+
- Projects, tasks, kanban boards (nanostores)
|
|
90
|
+
- Drag-and-drop (local state)
|
|
91
|
+
- Filters, search (client-side)
|
|
92
|
+
- **NO backend required** (except real-time collaboration)
|
|
93
|
+
|
|
94
|
+
### 🚀 When to Add ONE Platform Backend
|
|
95
|
+
- **Groups/Communities** - Multi-tenant organizations, teams
|
|
96
|
+
- **Multi-user** - Multiple users per group with roles
|
|
97
|
+
- **Activity tracking** - Events, analytics, audit logs
|
|
98
|
+
- **Connections** - Rich relationships between entities
|
|
99
|
+
- **Knowledge/RAG** - Semantic search, embeddings, AI
|
|
100
|
+
- **Real-time sync** - Live updates across devices
|
|
101
|
+
- **6-Dimension Ontology** - Full platform capabilities
|
|
102
|
+
|
|
103
|
+
**Integration: Import services from `/web/src/services` + providers from `/web/src/providers`**
|
|
104
|
+
|
|
105
|
+
## Goals
|
|
106
|
+
|
|
107
|
+
1. **ALWAYS build frontend-only by default** - NO backend code unless explicitly requested
|
|
108
|
+
2. **Frontend agents ONLY build UI** - nanostores + React + Astro
|
|
109
|
+
3. **Backend integration is OPTIONAL** - Only when user says "use backend" or "add groups/multi-user"
|
|
110
|
+
4. **All agents updated** - Every agent defaults to frontend-only
|
|
111
|
+
5. **Users ship TODAY** - No backend setup, no database config, just pure frontend
|
|
112
|
+
|
|
113
|
+
## Strategy
|
|
114
|
+
|
|
115
|
+
### 1. Mindset Shift: Production Apps Need No Backend
|
|
116
|
+
|
|
117
|
+
**EVERYTHING works client-side: Payments, business logic, data storage, user flows.**
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
❌ OLD: "Build ecommerce" → Backend + database + API + frontend
|
|
121
|
+
✅ NEW: "Build ecommerce" → Pure frontend + Stripe.js (DONE!)
|
|
122
|
+
|
|
123
|
+
❌ OLD: "Build LMS" → Convex schema + mutations + queries + frontend
|
|
124
|
+
✅ NEW: "Build LMS" → Pure frontend + nanostores (DONE!)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**What Works Without Backend (Production-Ready):**
|
|
128
|
+
- ✅ **Payments** - Stripe.js, PayPal SDK (client-side checkout)
|
|
129
|
+
- ✅ **Storage** - nanostores + localStorage (up to 10MB per domain)
|
|
130
|
+
- ✅ **Business logic** - All in TypeScript client-side
|
|
131
|
+
- ✅ **User flows** - Cart, checkout, courses, progress tracking
|
|
132
|
+
- ✅ **Offline-first** - Progressive Web Apps with service workers
|
|
133
|
+
- ✅ **Analytics** - Google Analytics, Plausible (client-side tracking)
|
|
134
|
+
- ✅ **Email** - EmailJS, FormSubmit (client-side email services)
|
|
135
|
+
|
|
136
|
+
**ONE Platform Backend Provides:**
|
|
137
|
+
1. **Groups** - Multi-tenant organizations (friend circles → businesses → governments)
|
|
138
|
+
2. **People** - Multi-user with roles (platform_owner, org_owner, org_user, customer)
|
|
139
|
+
3. **Things** - 66+ entity types (users, content, courses, products, tokens, NFTs, etc.)
|
|
140
|
+
4. **Connections** - 25+ relationship types (owns, follows, enrolled_in, etc.)
|
|
141
|
+
5. **Events** - 67+ event types (activity tracking, analytics, audit logs)
|
|
142
|
+
6. **Knowledge** - RAG, embeddings, semantic search
|
|
143
|
+
|
|
144
|
+
**But users should build FRONTEND FIRST, then add backend via `/web/src/services` + `/web/src/providers`**
|
|
145
|
+
|
|
146
|
+
### 2. Two Development Modes
|
|
147
|
+
|
|
148
|
+
| Mode | When | What Gets Built |
|
|
149
|
+
|------|------|-----------------|
|
|
150
|
+
| **Pure Frontend** (default) | "Build ecommerce store"<br/>"Build LMS"<br/>"Build SaaS tool" | ✅ Complete, production-ready app<br/>✅ nanostores for state<br/>✅ Stripe.js for payments<br/>✅ NO backend code<br/>✅ Deploy to Vercel/Netlify |
|
|
151
|
+
| **Add ONE Platform** (explicit) | "Add groups/multi-user"<br/>"Add activity tracking"<br/>"Add connections/events"<br/>"Add knowledge/RAG" | ✅ Keep frontend mostly as-is<br/>✅ Import from `/web/src/services`<br/>✅ Add providers from `/web/src/providers`<br/>✅ Get full 6-dimension ontology |
|
|
152
|
+
|
|
153
|
+
### 3. Detection Keywords
|
|
154
|
+
|
|
155
|
+
**Frontend-Only Indicators** (default):
|
|
156
|
+
- "Build a [feature]" (no backend mentioned)
|
|
157
|
+
- "Create a page for..."
|
|
158
|
+
- "Add a component that..."
|
|
159
|
+
- "Design a UI for..."
|
|
160
|
+
- "Show users..."
|
|
161
|
+
- "Display..."
|
|
162
|
+
- "Make it look like..."
|
|
163
|
+
|
|
164
|
+
**ONE Platform Integration** (explicit request):
|
|
165
|
+
- "Add groups/multi-tenant"
|
|
166
|
+
- "Add multi-user with roles"
|
|
167
|
+
- "Add activity tracking/events"
|
|
168
|
+
- "Add connections between entities"
|
|
169
|
+
- "Add knowledge/RAG"
|
|
170
|
+
- "Integrate with ONE Platform"
|
|
171
|
+
- "Add the backend"
|
|
172
|
+
|
|
173
|
+
**How users integrate:**
|
|
174
|
+
```typescript
|
|
175
|
+
// Look at /web/src/services and /web/src/providers
|
|
176
|
+
import { GroupProvider } from '@/providers/GroupProvider';
|
|
177
|
+
import { useGroups } from '@/services/groups';
|
|
178
|
+
|
|
179
|
+
// Drop in providers
|
|
180
|
+
<GroupProvider>
|
|
181
|
+
<App />
|
|
182
|
+
</GroupProvider>
|
|
183
|
+
|
|
184
|
+
// Use services (replaces nanostores)
|
|
185
|
+
const groups = useGroups();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Implementation Plan
|
|
189
|
+
|
|
190
|
+
### Phase 1: Update Agent Instructions
|
|
191
|
+
|
|
192
|
+
#### A. Update `agent-director.md`
|
|
193
|
+
|
|
194
|
+
```markdown
|
|
195
|
+
## Routing Logic (UPDATED)
|
|
196
|
+
|
|
197
|
+
**🚨 CRITICAL: ALWAYS ROUTE TO FRONTEND-ONLY BY DEFAULT 🚨**
|
|
198
|
+
|
|
199
|
+
**DEFAULT BEHAVIOR (99% of requests):**
|
|
200
|
+
Route to `agent-frontend` ONLY. Build pure frontend with nanostores.
|
|
201
|
+
|
|
202
|
+
Examples:
|
|
203
|
+
- "Build an ecommerce store" → `agent-frontend` ONLY (nanostores + Stripe.js)
|
|
204
|
+
- "Build an LMS" → `agent-frontend` ONLY (nanostores)
|
|
205
|
+
- "Build a SaaS tool" → `agent-frontend` ONLY (nanostores)
|
|
206
|
+
- "Add payment processing" → `agent-frontend` ONLY (Stripe.js client-side)
|
|
207
|
+
- "Add user dashboard" → `agent-frontend` ONLY (nanostores)
|
|
208
|
+
|
|
209
|
+
**EXCEPTION: User Explicitly Requests Backend Integration (1% of requests)**
|
|
210
|
+
|
|
211
|
+
Only route to `agent-backend` when user explicitly says:
|
|
212
|
+
- "Use the backend"
|
|
213
|
+
- "Add groups/multi-tenant"
|
|
214
|
+
- "Add multi-user"
|
|
215
|
+
- "Integrate with ONE Platform"
|
|
216
|
+
- "Add activity tracking with backend"
|
|
217
|
+
- "Use services from /web/src/services"
|
|
218
|
+
|
|
219
|
+
Then `agent-backend` helps integrate existing services/providers (NOT build new backend code).
|
|
220
|
+
|
|
221
|
+
**KEY RULE: If user doesn't say "backend" or "use services", route to frontend-only.**
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### B. Update `agent-frontend.md`
|
|
225
|
+
|
|
226
|
+
```markdown
|
|
227
|
+
## Core Principle: ALWAYS Build Frontend-Only
|
|
228
|
+
|
|
229
|
+
**🚨 CRITICAL: YOU ONLY BUILD FRONTEND. NEVER TOUCH BACKEND. 🚨**
|
|
230
|
+
|
|
231
|
+
**Your ONLY job:**
|
|
232
|
+
1. Build UI with React components
|
|
233
|
+
2. Manage state with nanostores
|
|
234
|
+
3. Create Astro pages
|
|
235
|
+
4. Style with Tailwind + shadcn/ui
|
|
236
|
+
5. Deploy to Vercel/Netlify
|
|
237
|
+
|
|
238
|
+
**You NEVER:**
|
|
239
|
+
- ❌ Import from Convex
|
|
240
|
+
- ❌ Write backend code
|
|
241
|
+
- ❌ Create mutations/queries
|
|
242
|
+
- ❌ Touch database
|
|
243
|
+
- ❌ Use API calls (except client-side like Stripe.js)
|
|
244
|
+
|
|
245
|
+
**Default tools:**
|
|
246
|
+
- ✅ nanostores (state + persistence)
|
|
247
|
+
- ✅ React 19 components
|
|
248
|
+
- ✅ Astro 5 pages
|
|
249
|
+
- ✅ shadcn/ui components
|
|
250
|
+
- ✅ Tailwind CSS v4
|
|
251
|
+
- ✅ TypeScript
|
|
252
|
+
|
|
253
|
+
**If user wants backend integration, tell them to explicitly request "use backend" - then agent-backend will help integrate services from /web/src/services.**
|
|
254
|
+
|
|
255
|
+
## State Management with Nanostores
|
|
256
|
+
|
|
257
|
+
### Option 1: Atoms (Simple Values) - Recommended
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
// src/stores/cart.ts
|
|
261
|
+
import { atom } from 'nanostores';
|
|
262
|
+
import { persistentAtom } from '@nanostores/persistent';
|
|
263
|
+
|
|
264
|
+
// Simple atom (in-memory only)
|
|
265
|
+
export const cartCount = atom(0);
|
|
266
|
+
|
|
267
|
+
// Persistent atom (saved to localStorage)
|
|
268
|
+
export const cart = persistentAtom('cart', [], {
|
|
269
|
+
encode: JSON.stringify,
|
|
270
|
+
decode: JSON.parse,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// Actions
|
|
274
|
+
export function addToCart(item) {
|
|
275
|
+
cart.set([...cart.get(), item]);
|
|
276
|
+
cartCount.set(cart.get().length);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function clearCart() {
|
|
280
|
+
cart.set([]);
|
|
281
|
+
cartCount.set(0);
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Usage in React:**
|
|
286
|
+
```typescript
|
|
287
|
+
import { useStore } from '@nanostores/react';
|
|
288
|
+
import { cart, addToCart } from '@/stores/cart';
|
|
289
|
+
|
|
290
|
+
export function Cart() {
|
|
291
|
+
const $cart = useStore(cart);
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<div>
|
|
295
|
+
{$cart.map(item => (
|
|
296
|
+
<div key={item.id}>{item.name}</div>
|
|
297
|
+
))}
|
|
298
|
+
</div>
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Usage in Astro:**
|
|
304
|
+
```astro
|
|
305
|
+
---
|
|
306
|
+
import { cart } from '@/stores/cart';
|
|
307
|
+
const items = cart.get();
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
<div>
|
|
311
|
+
{items.map(item => (
|
|
312
|
+
<div>{item.name}</div>
|
|
313
|
+
))}
|
|
314
|
+
</div>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Option 2: Maps (Complex Objects)
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
// src/stores/products.ts
|
|
321
|
+
import { map } from 'nanostores';
|
|
322
|
+
import { persistentMap } from '@nanostores/persistent';
|
|
323
|
+
|
|
324
|
+
export const products = persistentMap('products:', {
|
|
325
|
+
items: [],
|
|
326
|
+
loading: false,
|
|
327
|
+
error: null,
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Actions
|
|
331
|
+
export function setProducts(items) {
|
|
332
|
+
products.setKey('items', items);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function setLoading(loading) {
|
|
336
|
+
products.setKey('loading', loading);
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Option 3: IndexedDB for Large Data
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import { openDB } from 'idb';
|
|
344
|
+
|
|
345
|
+
const db = await openDB('my-database', 1, {
|
|
346
|
+
upgrade(db) {
|
|
347
|
+
db.createObjectStore('items');
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Store data
|
|
352
|
+
await db.put('items', item, id);
|
|
353
|
+
|
|
354
|
+
// Retrieve data
|
|
355
|
+
const item = await db.get('items', id);
|
|
356
|
+
|
|
357
|
+
// List all
|
|
358
|
+
const allItems = await db.getAll('items');
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Storage Guidelines
|
|
362
|
+
|
|
363
|
+
**Use nanostores for everything:**
|
|
364
|
+
|
|
365
|
+
- **persistentAtom**: Most use cases - auto-syncs to localStorage (< 5MB)
|
|
366
|
+
- **atom**: In-memory only state (when persistence not needed)
|
|
367
|
+
- **map**: Complex objects with multiple properties
|
|
368
|
+
- **computed**: Derived values from other stores
|
|
369
|
+
|
|
370
|
+
**Only use IndexedDB if:**
|
|
371
|
+
- Need to store > 5MB of data
|
|
372
|
+
- Need complex queries on large datasets
|
|
373
|
+
- Building offline-first with sync capabilities
|
|
374
|
+
|
|
375
|
+
**Default choice: persistentAtom** (334 bytes, works everywhere, auto-persists)
|
|
376
|
+
|
|
377
|
+
## Frontend-Only Development Pattern
|
|
378
|
+
|
|
379
|
+
**Example: Build an Ecommerce Store**
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
// ✅ PURE FRONTEND - NO BACKEND CODE
|
|
383
|
+
|
|
384
|
+
// 1. Define your data types
|
|
385
|
+
interface Product {
|
|
386
|
+
id: string;
|
|
387
|
+
name: string;
|
|
388
|
+
price: number;
|
|
389
|
+
description: string;
|
|
390
|
+
inventory: number;
|
|
391
|
+
image: string;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
interface CartItem {
|
|
395
|
+
product: Product;
|
|
396
|
+
quantity: number;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// 2. Create nanostores for state management
|
|
400
|
+
// src/stores/ecommerce.ts
|
|
401
|
+
import { persistentAtom } from '@nanostores/persistent';
|
|
402
|
+
|
|
403
|
+
// Persistent stores (saved to localStorage)
|
|
404
|
+
export const products = persistentAtom<Product[]>('products', [], {
|
|
405
|
+
encode: JSON.stringify,
|
|
406
|
+
decode: JSON.parse,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
export const cart = persistentAtom<CartItem[]>('cart', [], {
|
|
410
|
+
encode: JSON.stringify,
|
|
411
|
+
decode: JSON.parse,
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
export const orders = persistentAtom<Order[]>('orders', [], {
|
|
415
|
+
encode: JSON.stringify,
|
|
416
|
+
decode: JSON.parse,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// Actions
|
|
420
|
+
export function addToCart(product: Product) {
|
|
421
|
+
const currentCart = cart.get();
|
|
422
|
+
const existing = currentCart.find(item => item.product.id === product.id);
|
|
423
|
+
|
|
424
|
+
if (existing) {
|
|
425
|
+
cart.set(
|
|
426
|
+
currentCart.map(item =>
|
|
427
|
+
item.product.id === product.id
|
|
428
|
+
? { ...item, quantity: item.quantity + 1 }
|
|
429
|
+
: item
|
|
430
|
+
)
|
|
431
|
+
);
|
|
432
|
+
} else {
|
|
433
|
+
cart.set([...currentCart, { product, quantity: 1 }]);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export function checkout() {
|
|
438
|
+
const currentCart = cart.get();
|
|
439
|
+
const order = {
|
|
440
|
+
id: crypto.randomUUID(),
|
|
441
|
+
items: currentCart,
|
|
442
|
+
total: currentCart.reduce((sum, item) => sum + item.product.price * item.quantity, 0),
|
|
443
|
+
date: new Date().toISOString()
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
orders.set([...orders.get(), order]);
|
|
447
|
+
cart.set([]);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// 3. Build UI components
|
|
451
|
+
import { useStore } from '@nanostores/react';
|
|
452
|
+
|
|
453
|
+
export function ProductList() {
|
|
454
|
+
const $products = useStore(products);
|
|
455
|
+
|
|
456
|
+
return (
|
|
457
|
+
<div className="grid grid-cols-3 gap-4">
|
|
458
|
+
{$products.map(product => (
|
|
459
|
+
<div key={product.id} className="border rounded p-4">
|
|
460
|
+
<img src={product.image} alt={product.name} />
|
|
461
|
+
<h3>{product.name}</h3>
|
|
462
|
+
<p>${product.price}</p>
|
|
463
|
+
<button onClick={() => addToCart(product)}>
|
|
464
|
+
Add to Cart
|
|
465
|
+
</button>
|
|
466
|
+
</div>
|
|
467
|
+
))}
|
|
468
|
+
</div>
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export function Cart() {
|
|
473
|
+
const $cart = useStore(cart);
|
|
474
|
+
|
|
475
|
+
return (
|
|
476
|
+
<div>
|
|
477
|
+
{$cart.map(item => (
|
|
478
|
+
<div key={item.product.id}>
|
|
479
|
+
{item.product.name} x {item.quantity} = ${item.product.price * item.quantity}
|
|
480
|
+
</div>
|
|
481
|
+
))}
|
|
482
|
+
<button onClick={checkout}>Checkout</button>
|
|
483
|
+
</div>
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
// 4. Stripe Integration (Client-Side Checkout)
|
|
489
|
+
import { loadStripe } from '@stripe/stripe-js';
|
|
490
|
+
|
|
491
|
+
const stripe = await loadStripe('pk_test_...');
|
|
492
|
+
|
|
493
|
+
export async function handleCheckout() {
|
|
494
|
+
const $cart = cart.get();
|
|
495
|
+
|
|
496
|
+
// Create Stripe checkout session (client-side)
|
|
497
|
+
const { error } = await stripe.redirectToCheckout({
|
|
498
|
+
lineItems: $cart.map(item => ({
|
|
499
|
+
price: item.product.stripePriceId,
|
|
500
|
+
quantity: item.quantity,
|
|
501
|
+
})),
|
|
502
|
+
mode: 'payment',
|
|
503
|
+
successUrl: `${window.location.origin}/success`,
|
|
504
|
+
cancelUrl: `${window.location.origin}/cart`,
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
if (error) {
|
|
508
|
+
console.error('Stripe error:', error);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// 5. Success page - record order
|
|
513
|
+
// src/pages/success.astro
|
|
514
|
+
---
|
|
515
|
+
import { orders, cart } from '@/stores/ecommerce';
|
|
516
|
+
|
|
517
|
+
// On successful payment, save order
|
|
518
|
+
const order = {
|
|
519
|
+
id: crypto.randomUUID(),
|
|
520
|
+
items: cart.get(),
|
|
521
|
+
total: cart.get().reduce((sum, item) => sum + item.product.price * item.quantity, 0),
|
|
522
|
+
date: new Date().toISOString(),
|
|
523
|
+
status: 'paid'
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
orders.set([...orders.get(), order]);
|
|
527
|
+
cart.set([]); // Clear cart
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
<h1>Order Confirmed!</h1>
|
|
531
|
+
<p>Order ID: {order.id}</p>
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
**What you build (PRODUCTION-READY):**
|
|
535
|
+
- ✅ Product catalog with images, prices, descriptions
|
|
536
|
+
- ✅ Shopping cart with add/remove/quantity
|
|
537
|
+
- ✅ **Stripe checkout (real payments!)**
|
|
538
|
+
- ✅ Order confirmation page
|
|
539
|
+
- ✅ Order history
|
|
540
|
+
- ✅ ALL state in nanostores
|
|
541
|
+
- ✅ Deploy to Vercel/Netlify
|
|
542
|
+
- ✅ **ZERO backend code**
|
|
543
|
+
|
|
544
|
+
**What you DON'T build:**
|
|
545
|
+
- ❌ ANY backend code
|
|
546
|
+
- ❌ NO Convex imports
|
|
547
|
+
- ❌ NO API calls
|
|
548
|
+
- ❌ NO database
|
|
549
|
+
- ❌ NO server
|
|
550
|
+
|
|
551
|
+
## When to Add ONE Platform Backend
|
|
552
|
+
|
|
553
|
+
**⚠️ BUILD FRONTEND FIRST. Default answer: "Use nanostores."**
|
|
554
|
+
|
|
555
|
+
**Integrate ONE Platform when user explicitly requests:**
|
|
556
|
+
|
|
557
|
+
1. **"Add groups/multi-tenant"** → Import `/web/src/services/groups` + `GroupProvider`
|
|
558
|
+
2. **"Add multi-user with roles"** → Import `/web/src/providers/AuthProvider`
|
|
559
|
+
3. **"Add activity tracking"** → Import `/web/src/services/events`
|
|
560
|
+
4. **"Add connections/relationships"** → Import `/web/src/services/connections`
|
|
561
|
+
5. **"Add knowledge/RAG"** → Import `/web/src/services/knowledge`
|
|
562
|
+
6. **"Integrate with ONE Platform"** → Show user how to import services/providers
|
|
563
|
+
|
|
564
|
+
**DON'T build new backend code. Just show users how to integrate existing services:**
|
|
565
|
+
- ✅ Point them to `/web/src/services` (available services)
|
|
566
|
+
- ✅ Point them to `/web/src/providers` (available providers)
|
|
567
|
+
- ✅ Show integration examples
|
|
568
|
+
- ❌ Don't create new Convex mutations/queries
|
|
569
|
+
- ❌ Don't extend backend schema
|
|
570
|
+
|
|
571
|
+
**Remember: Frontend agents build UI. Backend integration is a drop-in via services/providers.**
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
#### C. Update `agent-backend.md`
|
|
575
|
+
|
|
576
|
+
```markdown
|
|
577
|
+
## When to Use This Agent
|
|
578
|
+
|
|
579
|
+
**⚠️ IMPORTANT: Don't build new backend code. Show users how to integrate existing services.**
|
|
580
|
+
|
|
581
|
+
The ONE Platform backend is COMPLETE with:
|
|
582
|
+
- Groups (multi-tenant)
|
|
583
|
+
- People (multi-user + roles)
|
|
584
|
+
- Things (66+ entity types)
|
|
585
|
+
- Connections (25+ relationship types)
|
|
586
|
+
- Events (67+ event types)
|
|
587
|
+
- Knowledge (RAG/embeddings)
|
|
588
|
+
|
|
589
|
+
**Your job: Help users integrate existing services/providers, not build new backend code.**
|
|
590
|
+
|
|
591
|
+
**When user requests backend integration:**
|
|
592
|
+
|
|
593
|
+
1. **Point them to `/web/src/services`**
|
|
594
|
+
- `services/groups` - Multi-tenant organizations
|
|
595
|
+
- `services/events` - Activity tracking
|
|
596
|
+
- `services/connections` - Relationships
|
|
597
|
+
- `services/knowledge` - RAG/embeddings
|
|
598
|
+
- `services/auth` - Authentication
|
|
599
|
+
|
|
600
|
+
2. **Point them to `/web/src/providers`**
|
|
601
|
+
- `GroupProvider` - Wrap app for multi-tenant
|
|
602
|
+
- `AuthProvider` - User authentication
|
|
603
|
+
- `EventProvider` - Activity tracking
|
|
604
|
+
|
|
605
|
+
3. **Show integration example:**
|
|
606
|
+
```typescript
|
|
607
|
+
// Replace nanostores with services
|
|
608
|
+
// Before: const groups = persistentAtom('groups', []);
|
|
609
|
+
// After: const groups = useGroups(); // from /web/src/services/groups
|
|
610
|
+
|
|
611
|
+
// Wrap app with providers
|
|
612
|
+
<GroupProvider>
|
|
613
|
+
<EventProvider>
|
|
614
|
+
<App />
|
|
615
|
+
</EventProvider>
|
|
616
|
+
</GroupProvider>
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
**DON'T:**
|
|
620
|
+
- ❌ Create new Convex mutations/queries
|
|
621
|
+
- ❌ Extend backend schema
|
|
622
|
+
- ❌ Build custom backend logic
|
|
623
|
+
|
|
624
|
+
**DO:**
|
|
625
|
+
- ✅ Show available services in `/web/src/services`
|
|
626
|
+
- ✅ Show available providers in `/web/src/providers`
|
|
627
|
+
- ✅ Provide integration examples
|
|
628
|
+
- ✅ Help migrate nanostores → services
|
|
629
|
+
|
|
630
|
+
**Default answer: "Use existing services from /web/src/services"**
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
#### D. Update `CLAUDE.md`
|
|
634
|
+
|
|
635
|
+
Add new section:
|
|
636
|
+
|
|
637
|
+
```markdown
|
|
638
|
+
## Pure Frontend Development (Default Mode)
|
|
639
|
+
|
|
640
|
+
**CRITICAL: Default to pure frontend development with NO backend code.**
|
|
641
|
+
|
|
642
|
+
### Build Complete Apps Without Backend
|
|
643
|
+
|
|
644
|
+
Users can build fully-functional applications using ONLY frontend code:
|
|
645
|
+
- ✅ nanostores (state + persistence in 334 bytes)
|
|
646
|
+
- ✅ React components and hooks
|
|
647
|
+
- ✅ Astro pages (SSR or static)
|
|
648
|
+
- ✅ TypeScript for type safety
|
|
649
|
+
- ✅ shadcn/ui components
|
|
650
|
+
- ✅ Tailwind CSS styling
|
|
651
|
+
|
|
652
|
+
**NO backend code required. NO database. NO server. NO API calls.**
|
|
653
|
+
|
|
654
|
+
### What This Means for Feature Development
|
|
655
|
+
|
|
656
|
+
**When user says: "Build [feature]"**
|
|
657
|
+
1. ✅ Build pure frontend with nanostores
|
|
658
|
+
2. ✅ Use persistentAtom (auto-syncs to localStorage)
|
|
659
|
+
3. ✅ Create beautiful, functional UI
|
|
660
|
+
4. ❌ DON'T write ANY backend code
|
|
661
|
+
5. ❌ DON'T import from Convex
|
|
662
|
+
6. ❌ DON'T make API calls
|
|
663
|
+
|
|
664
|
+
**When user says: "Add backend to [feature]"**
|
|
665
|
+
1. ✅ Now integrate with backend
|
|
666
|
+
2. ✅ Replace nanostores with API calls
|
|
667
|
+
3. ✅ Add real-time sync if needed
|
|
668
|
+
|
|
669
|
+
### Quick Reference
|
|
670
|
+
|
|
671
|
+
**Pure Frontend (default):**
|
|
672
|
+
```typescript
|
|
673
|
+
// ✅ User: "Build an ecommerce store"
|
|
674
|
+
import { persistentAtom } from '@nanostores/persistent';
|
|
675
|
+
|
|
676
|
+
export const cart = persistentAtom('cart', [], {
|
|
677
|
+
encode: JSON.stringify,
|
|
678
|
+
decode: JSON.parse,
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
export function addToCart(product) {
|
|
682
|
+
cart.set([...cart.get(), product]);
|
|
683
|
+
}
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
**With Backend Integration (explicit request):**
|
|
687
|
+
```typescript
|
|
688
|
+
// ✅ User: "Add backend to sync cart across devices"
|
|
689
|
+
import { useQuery, useMutation } from 'convex/react';
|
|
690
|
+
import { api } from '@/convex/_generated/api';
|
|
691
|
+
|
|
692
|
+
const cart = useQuery(api.queries.cart.get);
|
|
693
|
+
const addToCart = useMutation(api.mutations.cart.add);
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
### Why Nanostores
|
|
697
|
+
|
|
698
|
+
- **Tiny**: 334 bytes (smallest state library)
|
|
699
|
+
- **Persistent**: `persistentAtom` auto-syncs localStorage
|
|
700
|
+
- **Universal**: Works in Astro, React, Vue, Svelte, vanilla JS
|
|
701
|
+
- **Type-safe**: Full TypeScript support
|
|
702
|
+
- **Simple**: `.get()` to read, `.set()` to write
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
### Phase 2: Create Frontend-Only Examples
|
|
706
|
+
|
|
707
|
+
Create `one/knowledge/frontend-patterns.md`:
|
|
708
|
+
|
|
709
|
+
```markdown
|
|
710
|
+
# Frontend-Only Development Patterns
|
|
711
|
+
|
|
712
|
+
## Pattern 1: Social Media App (Pure Frontend)
|
|
713
|
+
|
|
714
|
+
**Example: Twitter/X Clone**
|
|
715
|
+
|
|
716
|
+
```typescript
|
|
717
|
+
// ✅ PURE FRONTEND - NO BACKEND CODE
|
|
718
|
+
|
|
719
|
+
interface Post {
|
|
720
|
+
id: string;
|
|
721
|
+
authorId: string;
|
|
722
|
+
authorName: string;
|
|
723
|
+
authorAvatar: string;
|
|
724
|
+
content: string;
|
|
725
|
+
mediaUrl?: string;
|
|
726
|
+
tags: string[];
|
|
727
|
+
likes: number;
|
|
728
|
+
createdAt: string;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
interface User {
|
|
732
|
+
id: string;
|
|
733
|
+
name: string;
|
|
734
|
+
username: string;
|
|
735
|
+
avatar: string;
|
|
736
|
+
bio: string;
|
|
737
|
+
following: string[]; // User IDs
|
|
738
|
+
followers: string[]; // User IDs
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// State management with nanostores
|
|
742
|
+
// src/stores/social.ts
|
|
743
|
+
import { persistentAtom } from '@nanostores/persistent';
|
|
744
|
+
|
|
745
|
+
export const currentUser = persistentAtom<User | null>('currentUser', null, {
|
|
746
|
+
encode: JSON.stringify,
|
|
747
|
+
decode: JSON.parse,
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
export const users = persistentAtom<User[]>('users', [], {
|
|
751
|
+
encode: JSON.stringify,
|
|
752
|
+
decode: JSON.parse,
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
export const posts = persistentAtom<Post[]>('posts', [], {
|
|
756
|
+
encode: JSON.stringify,
|
|
757
|
+
decode: JSON.parse,
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
// Actions
|
|
761
|
+
export function createPost(content: string, mediaUrl?: string) {
|
|
762
|
+
const user = currentUser.get();
|
|
763
|
+
if (!user) return;
|
|
764
|
+
|
|
765
|
+
const newPost: Post = {
|
|
766
|
+
id: crypto.randomUUID(),
|
|
767
|
+
authorId: user.id,
|
|
768
|
+
authorName: user.name,
|
|
769
|
+
authorAvatar: user.avatar,
|
|
770
|
+
content,
|
|
771
|
+
mediaUrl,
|
|
772
|
+
tags: content.match(/#\w+/g) || [],
|
|
773
|
+
likes: 0,
|
|
774
|
+
createdAt: new Date().toISOString()
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
posts.set([newPost, ...posts.get()]);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export function followUser(targetUserId: string) {
|
|
781
|
+
const user = currentUser.get();
|
|
782
|
+
if (!user) return;
|
|
783
|
+
|
|
784
|
+
currentUser.set({
|
|
785
|
+
...user,
|
|
786
|
+
following: [...user.following, targetUserId]
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
users.set(
|
|
790
|
+
users.get().map(u =>
|
|
791
|
+
u.id === targetUserId
|
|
792
|
+
? { ...u, followers: [...u.followers, user.id] }
|
|
793
|
+
: u
|
|
794
|
+
)
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export function likePost(postId: string) {
|
|
799
|
+
posts.set(
|
|
800
|
+
posts.get().map(p =>
|
|
801
|
+
p.id === postId ? { ...p, likes: p.likes + 1 } : p
|
|
802
|
+
)
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// UI Components
|
|
807
|
+
import { useStore } from '@nanostores/react';
|
|
808
|
+
|
|
809
|
+
export function Feed() {
|
|
810
|
+
const $posts = useStore(posts);
|
|
811
|
+
const $currentUser = useStore(currentUser);
|
|
812
|
+
const following = $currentUser?.following || [];
|
|
813
|
+
|
|
814
|
+
// Filter to show posts from followed users
|
|
815
|
+
const feedPosts = $posts.filter(p =>
|
|
816
|
+
following.includes(p.authorId) || p.authorId === $currentUser?.id
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
return (
|
|
820
|
+
<div className="space-y-4">
|
|
821
|
+
{feedPosts.map(post => (
|
|
822
|
+
<PostCard key={post.id} post={post} />
|
|
823
|
+
))}
|
|
824
|
+
</div>
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
export function PostComposer() {
|
|
829
|
+
const [content, setContent] = useState('');
|
|
830
|
+
|
|
831
|
+
return (
|
|
832
|
+
<div className="bg-white p-4 rounded shadow">
|
|
833
|
+
<textarea
|
|
834
|
+
value={content}
|
|
835
|
+
onChange={e => setContent(e.target.value)}
|
|
836
|
+
placeholder="What's happening?"
|
|
837
|
+
className="w-full p-2 border rounded"
|
|
838
|
+
/>
|
|
839
|
+
<button
|
|
840
|
+
onClick={() => {
|
|
841
|
+
createPost(content);
|
|
842
|
+
setContent('');
|
|
843
|
+
}}
|
|
844
|
+
className="mt-2 px-4 py-2 bg-blue-500 text-white rounded"
|
|
845
|
+
>
|
|
846
|
+
Post
|
|
847
|
+
</button>
|
|
848
|
+
</div>
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
**What you build (PURE FRONTEND):**
|
|
854
|
+
- ✅ Feed page (`src/pages/feed.astro`)
|
|
855
|
+
- ✅ Post composer (`src/components/PostComposer.tsx`)
|
|
856
|
+
- ✅ User profile (`src/pages/profile/[id].astro`)
|
|
857
|
+
- ✅ Follow/unfollow UI
|
|
858
|
+
- ✅ Like/comment components
|
|
859
|
+
- ✅ Local state with browser persistence
|
|
860
|
+
|
|
861
|
+
**What you DON'T build:**
|
|
862
|
+
- ❌ ANY backend code
|
|
863
|
+
- ❌ NO API calls
|
|
864
|
+
- ❌ NO database operations
|
|
865
|
+
|
|
866
|
+
## Pattern 2: Course Platform (Pure Frontend)
|
|
867
|
+
|
|
868
|
+
**Example: Online Learning App**
|
|
869
|
+
|
|
870
|
+
```typescript
|
|
871
|
+
// ✅ PURE FRONTEND - NO BACKEND CODE
|
|
872
|
+
|
|
873
|
+
interface Course {
|
|
874
|
+
id: string;
|
|
875
|
+
name: string;
|
|
876
|
+
description: string;
|
|
877
|
+
instructor: string;
|
|
878
|
+
price: number;
|
|
879
|
+
lessons: Lesson[];
|
|
880
|
+
difficulty: 'beginner' | 'intermediate' | 'advanced';
|
|
881
|
+
tags: string[];
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
interface Lesson {
|
|
885
|
+
id: string;
|
|
886
|
+
courseId: string;
|
|
887
|
+
title: string;
|
|
888
|
+
content: string;
|
|
889
|
+
videoUrl: string;
|
|
890
|
+
duration: number; // seconds
|
|
891
|
+
order: number;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
interface Enrollment {
|
|
895
|
+
userId: string;
|
|
896
|
+
courseId: string;
|
|
897
|
+
progress: number; // percentage
|
|
898
|
+
completedLessons: string[]; // lesson IDs
|
|
899
|
+
enrolledAt: string;
|
|
900
|
+
lastAccessedAt: string;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// State management with nanostores
|
|
904
|
+
// src/stores/courses.ts
|
|
905
|
+
import { persistentAtom } from '@nanostores/persistent';
|
|
906
|
+
|
|
907
|
+
export const courses = persistentAtom<Course[]>('courses', [], {
|
|
908
|
+
encode: JSON.stringify,
|
|
909
|
+
decode: JSON.parse,
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
export const enrollments = persistentAtom<Enrollment[]>('enrollments', [], {
|
|
913
|
+
encode: JSON.stringify,
|
|
914
|
+
decode: JSON.parse,
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
// Actions
|
|
918
|
+
export function enrollInCourse(courseId: string, userId: string) {
|
|
919
|
+
const enrollment: Enrollment = {
|
|
920
|
+
userId,
|
|
921
|
+
courseId,
|
|
922
|
+
progress: 0,
|
|
923
|
+
completedLessons: [],
|
|
924
|
+
enrolledAt: new Date().toISOString(),
|
|
925
|
+
lastAccessedAt: new Date().toISOString()
|
|
926
|
+
};
|
|
927
|
+
enrollments.set([...enrollments.get(), enrollment]);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
export function completeLesson(userId: string, courseId: string, lessonId: string) {
|
|
931
|
+
const allEnrollments = enrollments.get();
|
|
932
|
+
const enrollment = allEnrollments.find(
|
|
933
|
+
e => e.userId === userId && e.courseId === courseId
|
|
934
|
+
);
|
|
935
|
+
|
|
936
|
+
if (!enrollment) return;
|
|
937
|
+
|
|
938
|
+
const course = courses.get().find(c => c.id === courseId);
|
|
939
|
+
if (!course) return;
|
|
940
|
+
|
|
941
|
+
const updatedEnrollment = {
|
|
942
|
+
...enrollment,
|
|
943
|
+
completedLessons: [...enrollment.completedLessons, lessonId],
|
|
944
|
+
progress: ((enrollment.completedLessons.length + 1) / course.lessons.length) * 100,
|
|
945
|
+
lastAccessedAt: new Date().toISOString()
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
enrollments.set(
|
|
949
|
+
allEnrollments.map(e =>
|
|
950
|
+
e.userId === userId && e.courseId === courseId
|
|
951
|
+
? updatedEnrollment
|
|
952
|
+
: e
|
|
953
|
+
)
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// UI Components
|
|
958
|
+
import { useStore } from '@nanostores/react';
|
|
959
|
+
|
|
960
|
+
export function CourseCatalog() {
|
|
961
|
+
const $courses = useStore(courses);
|
|
962
|
+
|
|
963
|
+
return (
|
|
964
|
+
<div className="grid grid-cols-3 gap-6">
|
|
965
|
+
{$courses.map(course => (
|
|
966
|
+
<div key={course.id} className="border rounded p-4">
|
|
967
|
+
<h3 className="text-xl font-bold">{course.name}</h3>
|
|
968
|
+
<p className="text-gray-600">{course.instructor}</p>
|
|
969
|
+
<p className="text-sm">{course.lessons.length} lessons</p>
|
|
970
|
+
<p className="text-lg font-bold">${course.price}</p>
|
|
971
|
+
<button
|
|
972
|
+
onClick={() => enrollInCourse(course.id, currentUserId)}
|
|
973
|
+
className="mt-4 px-4 py-2 bg-blue-500 text-white rounded"
|
|
974
|
+
>
|
|
975
|
+
Enroll Now
|
|
976
|
+
</button>
|
|
977
|
+
</div>
|
|
978
|
+
))}
|
|
979
|
+
</div>
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
export function ProgressDashboard({ userId }: { userId: string }) {
|
|
984
|
+
const $enrollments = useStore(enrollments);
|
|
985
|
+
const userEnrollments = $enrollments.filter(e => e.userId === userId);
|
|
986
|
+
|
|
987
|
+
return (
|
|
988
|
+
<div className="space-y-4">
|
|
989
|
+
{userEnrollments.map(enrollment => (
|
|
990
|
+
<div key={enrollment.courseId} className="border rounded p-4">
|
|
991
|
+
<h3>Course Progress</h3>
|
|
992
|
+
<div className="w-full bg-gray-200 rounded">
|
|
993
|
+
<div
|
|
994
|
+
className="bg-green-500 h-4 rounded"
|
|
995
|
+
style={{ width: `${enrollment.progress}%` }}
|
|
996
|
+
/>
|
|
997
|
+
</div>
|
|
998
|
+
<p>{enrollment.progress.toFixed(0)}% complete</p>
|
|
999
|
+
</div>
|
|
1000
|
+
))}
|
|
1001
|
+
</div>
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
**What you build (PURE FRONTEND):**
|
|
1007
|
+
- ✅ Course catalog (`src/pages/courses/index.astro`)
|
|
1008
|
+
- ✅ Course detail page (`src/pages/courses/[id].astro`)
|
|
1009
|
+
- ✅ Lesson viewer (`src/components/LessonViewer.tsx`)
|
|
1010
|
+
- ✅ Progress dashboard (`src/pages/dashboard.astro`)
|
|
1011
|
+
- ✅ Certificate generator
|
|
1012
|
+
- ✅ Local progress tracking
|
|
1013
|
+
|
|
1014
|
+
**What you DON'T build:**
|
|
1015
|
+
- ❌ ANY backend code
|
|
1016
|
+
- ❌ NO API calls
|
|
1017
|
+
- ❌ NO database operations
|
|
1018
|
+
|
|
1019
|
+
## Pattern 3: Team Collaboration Tool (Pure Frontend)
|
|
1020
|
+
|
|
1021
|
+
**Example: Project Management App**
|
|
1022
|
+
|
|
1023
|
+
```typescript
|
|
1024
|
+
// ✅ PURE FRONTEND - NO BACKEND CODE
|
|
1025
|
+
|
|
1026
|
+
interface Project {
|
|
1027
|
+
id: string;
|
|
1028
|
+
name: string;
|
|
1029
|
+
description: string;
|
|
1030
|
+
status: 'planning' | 'in_progress' | 'review' | 'completed';
|
|
1031
|
+
deadline: string;
|
|
1032
|
+
teamId: string;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
interface Task {
|
|
1036
|
+
id: string;
|
|
1037
|
+
projectId: string;
|
|
1038
|
+
title: string;
|
|
1039
|
+
description: string;
|
|
1040
|
+
assignedTo: string; // user ID
|
|
1041
|
+
status: 'todo' | 'in_progress' | 'done';
|
|
1042
|
+
priority: 'low' | 'medium' | 'high';
|
|
1043
|
+
createdAt: string;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
interface Team {
|
|
1047
|
+
id: string;
|
|
1048
|
+
name: string;
|
|
1049
|
+
members: string[]; // user IDs
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// State management with nanostores
|
|
1053
|
+
// src/stores/projects.ts
|
|
1054
|
+
import { persistentAtom } from '@nanostores/persistent';
|
|
1055
|
+
|
|
1056
|
+
export const teams = persistentAtom<Team[]>('teams', [], {
|
|
1057
|
+
encode: JSON.stringify,
|
|
1058
|
+
decode: JSON.parse,
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
export const projects = persistentAtom<Project[]>('projects', [], {
|
|
1062
|
+
encode: JSON.stringify,
|
|
1063
|
+
decode: JSON.parse,
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
export const tasks = persistentAtom<Task[]>('tasks', [], {
|
|
1067
|
+
encode: JSON.stringify,
|
|
1068
|
+
decode: JSON.parse,
|
|
1069
|
+
});
|
|
1070
|
+
|
|
1071
|
+
// Actions
|
|
1072
|
+
export function createTask(task: Omit<Task, 'id' | 'createdAt'>) {
|
|
1073
|
+
const newTask: Task = {
|
|
1074
|
+
...task,
|
|
1075
|
+
id: crypto.randomUUID(),
|
|
1076
|
+
createdAt: new Date().toISOString()
|
|
1077
|
+
};
|
|
1078
|
+
tasks.set([...tasks.get(), newTask]);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
export function updateTaskStatus(taskId: string, status: Task['status']) {
|
|
1082
|
+
tasks.set(
|
|
1083
|
+
tasks.get().map(t =>
|
|
1084
|
+
t.id === taskId ? { ...t, status } : t
|
|
1085
|
+
)
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
export function assignTask(taskId: string, userId: string) {
|
|
1090
|
+
tasks.set(
|
|
1091
|
+
tasks.get().map(t =>
|
|
1092
|
+
t.id === taskId ? { ...t, assignedTo: userId } : t
|
|
1093
|
+
)
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// UI Components
|
|
1098
|
+
import { useStore } from '@nanostores/react';
|
|
1099
|
+
|
|
1100
|
+
export function KanbanBoard({ projectId }: { projectId: string }) {
|
|
1101
|
+
const $tasks = useStore(tasks);
|
|
1102
|
+
const projectTasks = $tasks.filter(t => t.projectId === projectId);
|
|
1103
|
+
|
|
1104
|
+
const columns = {
|
|
1105
|
+
todo: projectTasks.filter(t => t.status === 'todo'),
|
|
1106
|
+
in_progress: projectTasks.filter(t => t.status === 'in_progress'),
|
|
1107
|
+
done: projectTasks.filter(t => t.status === 'done')
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
return (
|
|
1111
|
+
<div className="grid grid-cols-3 gap-4">
|
|
1112
|
+
{Object.entries(columns).map(([status, columnTasks]) => (
|
|
1113
|
+
<div key={status} className="bg-gray-100 p-4 rounded">
|
|
1114
|
+
<h3 className="font-bold mb-4">{status.replace('_', ' ').toUpperCase()}</h3>
|
|
1115
|
+
<div className="space-y-2">
|
|
1116
|
+
{columnTasks.map(task => (
|
|
1117
|
+
<div
|
|
1118
|
+
key={task.id}
|
|
1119
|
+
className="bg-white p-3 rounded shadow cursor-move"
|
|
1120
|
+
draggable
|
|
1121
|
+
onDragEnd={(e) => {
|
|
1122
|
+
// Handle drag and drop to change status
|
|
1123
|
+
}}
|
|
1124
|
+
>
|
|
1125
|
+
<h4 className="font-semibold">{task.title}</h4>
|
|
1126
|
+
<p className="text-sm text-gray-600">{task.description}</p>
|
|
1127
|
+
<span className={`text-xs px-2 py-1 rounded ${
|
|
1128
|
+
task.priority === 'high' ? 'bg-red-100' :
|
|
1129
|
+
task.priority === 'medium' ? 'bg-yellow-100' :
|
|
1130
|
+
'bg-green-100'
|
|
1131
|
+
}`}>
|
|
1132
|
+
{task.priority}
|
|
1133
|
+
</span>
|
|
1134
|
+
</div>
|
|
1135
|
+
))}
|
|
1136
|
+
</div>
|
|
1137
|
+
</div>
|
|
1138
|
+
))}
|
|
1139
|
+
</div>
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
**What you build (PURE FRONTEND):**
|
|
1145
|
+
- ✅ Team dashboard
|
|
1146
|
+
- ✅ Project kanban board
|
|
1147
|
+
- ✅ Task list with filters
|
|
1148
|
+
- ✅ Team member directory
|
|
1149
|
+
- ✅ Activity feed
|
|
1150
|
+
- ✅ Drag-and-drop task management
|
|
1151
|
+
|
|
1152
|
+
**What you DON'T build:**
|
|
1153
|
+
- ❌ ANY backend code
|
|
1154
|
+
- ❌ NO API calls
|
|
1155
|
+
- ❌ NO database operations
|
|
1156
|
+
```
|
|
1157
|
+
|
|
1158
|
+
### Phase 3: Update Documentation
|
|
1159
|
+
|
|
1160
|
+
1. **`one/knowledge/quick-start.md`** - Add "Building Your First Feature (Frontend-Only)" section
|
|
1161
|
+
2. **`one/connections/workflow.md`** - Update Phase 4 to emphasize frontend-first
|
|
1162
|
+
3. **`web/AGENTS.md`** - Add "When to Use Backend vs Frontend" decision tree
|
|
1163
|
+
4. **`README.md`** - Update examples to show frontend-only patterns
|
|
1164
|
+
|
|
1165
|
+
### Phase 4: Add Guardrails
|
|
1166
|
+
|
|
1167
|
+
Create `.claude/hooks/check-backend-request.py`:
|
|
1168
|
+
|
|
1169
|
+
```python
|
|
1170
|
+
#!/usr/bin/env python3
|
|
1171
|
+
"""
|
|
1172
|
+
Hook: Warn when backend development starts without explicit request
|
|
1173
|
+
"""
|
|
1174
|
+
|
|
1175
|
+
import sys
|
|
1176
|
+
import json
|
|
1177
|
+
|
|
1178
|
+
def check_backend_intent(user_message):
|
|
1179
|
+
"""Check if user explicitly requested backend work"""
|
|
1180
|
+
|
|
1181
|
+
backend_keywords = [
|
|
1182
|
+
"backend", "database", "schema", "mutation", "query",
|
|
1183
|
+
"convex function", "business logic", "custom backend"
|
|
1184
|
+
]
|
|
1185
|
+
|
|
1186
|
+
# If message contains backend keywords, allow
|
|
1187
|
+
for keyword in backend_keywords:
|
|
1188
|
+
if keyword.lower() in user_message.lower():
|
|
1189
|
+
return True
|
|
1190
|
+
|
|
1191
|
+
return False
|
|
1192
|
+
|
|
1193
|
+
if __name__ == "__main__":
|
|
1194
|
+
# Read user input
|
|
1195
|
+
user_message = sys.argv[1] if len(sys.argv) > 1 else ""
|
|
1196
|
+
|
|
1197
|
+
# Check if backend work is justified
|
|
1198
|
+
if not check_backend_intent(user_message):
|
|
1199
|
+
print("⚠️ TIP: Consider building frontend-only using existing backend services.")
|
|
1200
|
+
print("The ONE Platform backend already provides:")
|
|
1201
|
+
print(" • 66+ entity types (things)")
|
|
1202
|
+
print(" • 25+ connection types")
|
|
1203
|
+
print(" • 67+ event types")
|
|
1204
|
+
print("")
|
|
1205
|
+
print("Only create backend code if you need:")
|
|
1206
|
+
print(" • New entity/connection/event types")
|
|
1207
|
+
print(" • Complex business logic")
|
|
1208
|
+
print(" • External integrations")
|
|
1209
|
+
print("")
|
|
1210
|
+
print("Check backend/convex/schema.ts for available types.")
|
|
1211
|
+
print("")
|
|
1212
|
+
|
|
1213
|
+
sys.exit(0) # Always allow, just warn
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
## Success Metrics
|
|
1217
|
+
|
|
1218
|
+
**After implementation, we should see:**
|
|
1219
|
+
|
|
1220
|
+
1. **98%+ of apps built with NO backend** - Ecommerce, LMS, SaaS all work client-side
|
|
1221
|
+
2. **Production-ready in minutes** - Deploy to Vercel/Netlify immediately
|
|
1222
|
+
3. **Real payments working** - Stripe/PayPal integrated client-side
|
|
1223
|
+
4. **Zero backend knowledge needed** - Users build and ship without Convex
|
|
1224
|
+
5. **Backend only for auth + sync** - Added explicitly when requested
|
|
1225
|
+
|
|
1226
|
+
## Migration Path
|
|
1227
|
+
|
|
1228
|
+
**For existing users:**
|
|
1229
|
+
|
|
1230
|
+
1. **Announcement** - "The backend is complete. Focus on frontend."
|
|
1231
|
+
2. **Examples** - Show 10 common features built frontend-only
|
|
1232
|
+
3. **Documentation** - Update all guides to frontend-first approach
|
|
1233
|
+
4. **Support** - Help migrate any in-progress backend work to frontend
|
|
1234
|
+
|
|
1235
|
+
**For new users:**
|
|
1236
|
+
|
|
1237
|
+
1. **Onboarding** - "You're building on a complete backend"
|
|
1238
|
+
2. **Quick start** - First feature is frontend-only
|
|
1239
|
+
3. **Examples** - All tutorials show frontend-only patterns
|
|
1240
|
+
4. **Backend docs** - Marked "Advanced" and "Usually not needed"
|
|
1241
|
+
|
|
1242
|
+
## FAQ
|
|
1243
|
+
|
|
1244
|
+
**Q: Can I really accept payments without a backend?**
|
|
1245
|
+
A: YES! Stripe.js and PayPal SDK handle payments client-side. No backend needed. Thousands of businesses use this.
|
|
1246
|
+
|
|
1247
|
+
**Q: What about storing user data?**
|
|
1248
|
+
A: nanostores + localStorage gives you up to 10MB per domain. That's enough for most apps. IndexedDB for larger datasets.
|
|
1249
|
+
|
|
1250
|
+
**Q: How do I handle user authentication?**
|
|
1251
|
+
A: For single-device: Just store auth state in nanostores. For multi-device: Use Clerk or Auth0 (client-side) or add backend later.
|
|
1252
|
+
|
|
1253
|
+
**Q: Can I build a real business on this?**
|
|
1254
|
+
A: Absolutely! Many successful businesses run on client-side only. Examples: landing pages with Stripe, course platforms, productivity tools.
|
|
1255
|
+
|
|
1256
|
+
**Q: What about SEO?**
|
|
1257
|
+
A: Astro provides SSR and static generation. Full SEO support without backend.
|
|
1258
|
+
|
|
1259
|
+
**Q: When should I add the ONE Platform backend?**
|
|
1260
|
+
A: When you want: (1) Groups/multi-tenant, (2) Multi-user with roles, (3) Activity tracking/events, (4) Connections/relationships, (5) Knowledge/RAG, (6) Real-time sync. Start frontend-first, integrate backend later via `/web/src/services` and `/web/src/providers`.
|
|
1261
|
+
|
|
1262
|
+
**Q: How hard is it to integrate the backend?**
|
|
1263
|
+
A: Super easy! Just import services and providers. Your frontend code mostly stays the same - you're just swapping nanostores for backend services. Check `/web/src/services` and `/web/src/providers` for examples.
|
|
1264
|
+
|
|
1265
|
+
**Q: What does the backend give me?**
|
|
1266
|
+
A: The full 6-dimension ontology: Groups (multi-tenant), People (multi-user + roles), Things (66+ entity types), Connections (25+ relationship types), Events (67+ event types), Knowledge (RAG/embeddings). It's a complete platform, not just auth + sync.
|
|
1267
|
+
|
|
1268
|
+
## Next Steps
|
|
1269
|
+
|
|
1270
|
+
### Phase 1: Update ALL Agents to Default Frontend-Only
|
|
1271
|
+
|
|
1272
|
+
**🚨 CRITICAL: Every agent must default to frontend-only unless user says "use backend" 🚨**
|
|
1273
|
+
|
|
1274
|
+
1. ✅ Create this plan document
|
|
1275
|
+
2. ⏳ Update `.claude/agents/agent-director.md` - Route frontend-only by default (99% of requests)
|
|
1276
|
+
3. ⏳ Update `.claude/agents/agent-frontend.md` - ONLY build frontend, NEVER touch backend
|
|
1277
|
+
4. ⏳ Update `.claude/agents/agent-backend.md` - Help integrate services, DON'T build new backend
|
|
1278
|
+
5. ⏳ Update `.claude/agents/agent-builder.md` - Default to frontend-only
|
|
1279
|
+
6. ⏳ Update `.claude/agents/agent-designer.md` - Design for frontend-only apps
|
|
1280
|
+
7. ⏳ Update `.claude/agents/agent-quality.md` - Test frontend-only apps
|
|
1281
|
+
8. ⏳ Update `CLAUDE.md` - Add "Frontend-First Development" section
|
|
1282
|
+
9. ⏳ Create frontend-only examples (ecommerce + Stripe, LMS, SaaS)
|
|
1283
|
+
|
|
1284
|
+
### Phase 2: Test and Verify
|
|
1285
|
+
|
|
1286
|
+
10. ⏳ Test: "Build an ecommerce store" → Should produce ONLY frontend code (nanostores + Stripe.js)
|
|
1287
|
+
11. ⏳ Test: "Build an LMS" → Should produce ONLY frontend code (nanostores)
|
|
1288
|
+
12. ⏳ Test: "Build an ecommerce store with backend" → Should integrate services from /web/src/services
|
|
1289
|
+
13. ⏳ Verify NO Convex imports unless explicitly requested
|
|
1290
|
+
|
|
1291
|
+
### Phase 3: Deploy and Monitor
|
|
1292
|
+
|
|
1293
|
+
14. ⏳ Deploy updated agents
|
|
1294
|
+
15. ⏳ Monitor success metrics (target: 98%+ frontend-only)
|
|
1295
|
+
|
|
1296
|
+
---
|
|
1297
|
+
|
|
1298
|
+
## Final Word
|
|
1299
|
+
|
|
1300
|
+
**🚨 ALL AGENTS DEFAULT TO FRONTEND-ONLY 🚨**
|
|
1301
|
+
|
|
1302
|
+
**UNLESS USER EXPLICITLY SAYS "USE BACKEND":**
|
|
1303
|
+
|
|
1304
|
+
**What agents build (99% of requests):**
|
|
1305
|
+
- ✅ Pure frontend with nanostores
|
|
1306
|
+
- ✅ Stripe.js for payments (client-side)
|
|
1307
|
+
- ✅ React + Astro UI components
|
|
1308
|
+
- ✅ NO backend code
|
|
1309
|
+
- ✅ NO Convex imports
|
|
1310
|
+
- ✅ Deploy to Vercel/Netlify TODAY
|
|
1311
|
+
|
|
1312
|
+
**What agents DON'T build (unless requested):**
|
|
1313
|
+
- ❌ Backend code
|
|
1314
|
+
- ❌ Convex mutations/queries
|
|
1315
|
+
- ❌ Database schema
|
|
1316
|
+
- ❌ API endpoints
|
|
1317
|
+
|
|
1318
|
+
**Only when user says "use backend" or "add groups/multi-user":**
|
|
1319
|
+
- Then help integrate existing services from `/web/src/services`
|
|
1320
|
+
- Then help add providers from `/web/src/providers`
|
|
1321
|
+
- DON'T build new backend code, just integrate existing
|
|
1322
|
+
|
|
1323
|
+
**Every agent updated:**
|
|
1324
|
+
- agent-director → Routes frontend-only by default
|
|
1325
|
+
- agent-frontend → NEVER touches backend
|
|
1326
|
+
- agent-backend → Integrates services (doesn't build new)
|
|
1327
|
+
- agent-builder → Defaults to frontend-only
|
|
1328
|
+
- agent-designer → Designs for frontend-only
|
|
1329
|
+
- agent-quality → Tests frontend-only
|
|
1330
|
+
|
|
1331
|
+
**DEFAULT = FRONTEND-ONLY. Backend integration is OPTIONAL and EXPLICIT.**
|