oneie 2.0.3 → 2.0.5
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.md +220 -29
- package/LICENSE.md +84 -0
- package/README.md +489 -931
- package/folders.yaml +78 -17
- package/one/.obsidian/workspace.json +6 -6
- package/one/events/CASCADE-2-BACKEND-AGNOSTIC.md +412 -0
- package/one/events/FEATURE-2-4-COMPLETE.md +302 -0
- package/one/events/FEATURE_2_3_COMPLETE.md +575 -0
- package/one/events/GROUPS-MIGRATION.md +625 -0
- package/one/events/INSTALL-TESTS.md +293 -0
- package/one/events/INTEGRATION-ARCHITECTURE.md +561 -0
- package/one/events/INTEGRATION-CHECKLIST.md +1234 -0
- package/one/events/INTEGRATION-ORCHESTRATION.md +2623 -0
- package/one/events/INTEGRATION-SUMMARY.md +653 -0
- package/one/events/MIGRATION-REPORT.md +435 -0
- package/one/events/MIGRATION.md +69 -0
- package/one/events/README-archived.md +519 -0
- package/one/events/TEST-SUMMARY.md +393 -0
- package/one/events/TESTS-QUICK-REF.md +262 -0
- package/one/groups/groups.md +543 -0
- package/one/knowledge/CLOUDFLARE_ENV_SETUP.md +49 -0
- package/one/knowledge/architecture-any-backend.md +1366 -0
- package/one/knowledge/docs/flow.md +0 -0
- package/one/knowledge/ontology-documentation.md +18 -18
- package/one/knowledge/ontology.md +154 -143
- package/one/knowledge/ontology.md.backup +2822 -0
- package/one/knowledge/ontology.yaml +87 -87
- package/one/knowledge/provider-creation-guide.md +1064 -0
- package/one/knowledge/todo.md +251 -0
- package/one/license.md +84 -0
- package/one/things/CHECKLIST.md +356 -0
- package/one/things/ONE.md +510 -0
- package/one/things/{cli.md → cli/cli.md} +27 -4
- package/one/things/features/2-1-dataprovider-interface.md +2358 -0
- package/one/things/features/2-2-config-system.md +3075 -0
- package/one/things/features/2-3-effectts-services.md +1498 -0
- package/one/things/features/2-4-react-hooks.md +2120 -0
- package/one/things/features/2-5-auth-migration.md +2046 -0
- package/one/things/features/2-6-dashboard-migration.md +1985 -0
- package/one/things/features/2-7-alternative-providers.md +2505 -0
- package/one/things/features/2-7-implementation-report.md +680 -0
- package/one/things/features/2-cli.md +39 -39
- package/one/things/features/2-design.md +1738 -0
- package/one/things/features/2-tests.md +520 -0
- package/one/things/features/AUTH_HOOKS_IMPLEMENTATION.md +521 -0
- package/one/things/features/DECOUPLING.md +272 -0
- package/one/things/features/DEPLOYMENT.md +452 -0
- package/one/things/features/IMPLEMENTATION_SUMMARY.md +316 -0
- package/one/things/features/dataprovider-interface/1-tests.md +1522 -0
- package/one/things/features/improve.md +843 -0
- package/one/things/features/remove-convex-deps.md +45 -0
- package/one/things/features/top-features.md +79 -0
- package/one/things/ideas/2-backend-agnostic-frontend.md +384 -0
- package/one/things/plans/2-backend-agnostic-frontend.md +543 -0
- package/one/things/plans/3-groups.md +502 -0
- package/one/things/plans/backend-agnostic-frontend.md +323 -0
- package/one/things/plans/deploy-to-cloudflare.md +581 -0
- package/one/things/plans/organizations-to-groups.md +705 -0
- package/one/things/plans/release.md +432 -0
- package/one/things/products/ontology.md +1 -1
- package/one/things/system.md +600 -0
- package/one/things/tests/2-1-dataprovider-interface.md +1144 -0
- package/one/things/tests/2-1-test-analysis.md +496 -0
- package/one/things/vision/elegant-interface.md +214 -0
- package/package.json +1 -1
- package/one/organisation/organisation.md +0 -438
- package/one/repomix-output.md +0 -92634
- /package/one/{things → connections}/agentkit.md +0 -0
- /package/one/{things → connections}/copilotkit.md +0 -0
- /package/one/{organisation → groups}/one.md +0 -0
- /package/one/{organisation → groups}/revenue.md +0 -0
- /package/one/{organisation → groups}/strategy.md +0 -0
- /package/one/{organisation → groups}/vision.md +0 -0
- /package/one/things/{cli-code.md → cli/cli-code.md} +0 -0
- /package/one/things/{cli-compiler-code.md → cli/cli-compiler-code.md} +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# Frontend/Backend Decoupling Pattern
|
|
2
|
+
|
|
3
|
+
**Status:** ✅ Fully Implemented
|
|
4
|
+
|
|
5
|
+
This document explains the proper architecture for a fully decoupled frontend that can connect to ANY backend (not just our Convex deployment).
|
|
6
|
+
|
|
7
|
+
## Architecture Layers
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌──────────────────────────────────────────────────┐
|
|
11
|
+
│ Components (React/Astro) │
|
|
12
|
+
│ Use domain hooks │
|
|
13
|
+
└────────────────┬─────────────────────────────────┘
|
|
14
|
+
│
|
|
15
|
+
↓
|
|
16
|
+
┌──────────────────────────────────────────────────┐
|
|
17
|
+
│ src/hooks/* (Domain Hooks) │
|
|
18
|
+
│ useGroups, useThings, useConnections │
|
|
19
|
+
│ TanStack Query + Effect.ts │
|
|
20
|
+
└────────────────┬─────────────────────────────────┘
|
|
21
|
+
│
|
|
22
|
+
↓
|
|
23
|
+
┌──────────────────────────────────────────────────┐
|
|
24
|
+
│ src/providers/DataProvider (Interface) │
|
|
25
|
+
│ Backend-agnostic contract │
|
|
26
|
+
└────────────────┬─────────────────────────────────┘
|
|
27
|
+
│
|
|
28
|
+
↓
|
|
29
|
+
┌──────────────────────────────────────────────────┐
|
|
30
|
+
│ src/providers/convex/ConvexProvider (Impl) │
|
|
31
|
+
│ Convex-specific implementation │
|
|
32
|
+
└────────────────┬─────────────────────────────────┘
|
|
33
|
+
│
|
|
34
|
+
↓
|
|
35
|
+
┌──────────────────────────────────────────────────┐
|
|
36
|
+
│ ANY Backend via PUBLIC_CONVEX_URL │
|
|
37
|
+
│ - Our backend (shocking-falcon-870.convex.cloud)│
|
|
38
|
+
│ - api.one.ie (shared platform backend) │
|
|
39
|
+
│ - Customer's own Convex deployment │
|
|
40
|
+
└──────────────────────────────────────────────────┘
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ❌ Don't Do This (Coupled)
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// ❌ BAD: Direct Convex imports
|
|
47
|
+
import { useQuery } from 'convex/react';
|
|
48
|
+
import { api } from 'convex/_generated/api';
|
|
49
|
+
|
|
50
|
+
function MyComponent() {
|
|
51
|
+
const data = useQuery(api.queries.things.list);
|
|
52
|
+
// Tightly coupled to Convex
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## ✅ Do This (Decoupled)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// ✅ GOOD: Domain hooks
|
|
60
|
+
import { useThings } from '@/hooks/useThings';
|
|
61
|
+
|
|
62
|
+
function MyComponent() {
|
|
63
|
+
const { data, loading, error } = useThings({ type: 'course' });
|
|
64
|
+
// Works with ANY backend
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Available Domain Hooks
|
|
69
|
+
|
|
70
|
+
### Core Ontology Hooks
|
|
71
|
+
|
|
72
|
+
- `useThings(filter?, options?)` - List/query things (entities)
|
|
73
|
+
- `useThing(id, options?)` - Get single thing by ID
|
|
74
|
+
- `useConnections(filter?, options?)` - List relationships
|
|
75
|
+
- `useConnection(id, options?)` - Get single connection
|
|
76
|
+
- `useEvents(filter?, options?)` - List events (actions/logs)
|
|
77
|
+
- `useKnowledge(filter?, options?)` - RAG/vector search
|
|
78
|
+
|
|
79
|
+
### Specialized Hooks
|
|
80
|
+
|
|
81
|
+
- `useGroups(filter?, options?)` - Hierarchical groups
|
|
82
|
+
- `useGroup(id, options?)` - Single group
|
|
83
|
+
- `useGroupBySlug(slug, options?)` - Group by slug
|
|
84
|
+
- `useGroupStats(groupId, options?)` - Group statistics
|
|
85
|
+
- `useOrganizations(filter?, options?)` - Multi-tenant orgs
|
|
86
|
+
- `usePeople(filter?, options?)` - Users/creators/customers
|
|
87
|
+
|
|
88
|
+
### Mutations
|
|
89
|
+
|
|
90
|
+
- `useCreateGroup(options?)` - Create new group
|
|
91
|
+
- `useUpdateGroup(groupId, options?)` - Update group
|
|
92
|
+
- `useDeleteGroup(groupId, options?)` - Delete group
|
|
93
|
+
|
|
94
|
+
## Example: GroupCard Component
|
|
95
|
+
|
|
96
|
+
**Before (Coupled):**
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { useQuery } from "convex/react";
|
|
100
|
+
import { api } from "convex/_generated/api";
|
|
101
|
+
|
|
102
|
+
export function GroupCard({ groupId }: { groupId: string }) {
|
|
103
|
+
const group = useQuery(api.queries.groups.getById, { groupId });
|
|
104
|
+
const stats = useQuery(api.queries.groups.getStats, { groupId });
|
|
105
|
+
|
|
106
|
+
if (group === undefined) return <Skeleton />;
|
|
107
|
+
|
|
108
|
+
return <Card>{group.name}</Card>;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**After (Decoupled):**
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { useGroup, useGroupStats } from "@/hooks/useGroups";
|
|
116
|
+
|
|
117
|
+
export function GroupCard({ groupId }: { groupId: string }) {
|
|
118
|
+
const { data: group, loading } = useGroup(groupId);
|
|
119
|
+
const { data: stats } = useGroupStats(groupId);
|
|
120
|
+
|
|
121
|
+
if (loading) return <Skeleton />;
|
|
122
|
+
|
|
123
|
+
return <Card>{group?.name}</Card>;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Hook Usage Patterns
|
|
128
|
+
|
|
129
|
+
### Query Hook
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const { data, loading, error, refetch, refetching } = useGroups(
|
|
133
|
+
{
|
|
134
|
+
type: 'community',
|
|
135
|
+
status: 'active',
|
|
136
|
+
visibility: 'public',
|
|
137
|
+
limit: 50,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
enabled: true, // Conditional fetching
|
|
141
|
+
staleTime: 5000, // Cache freshness
|
|
142
|
+
refetchInterval: 10000, // Polling
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Mutation Hook
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const createGroup = useCreateGroup({
|
|
151
|
+
onSuccess: () => {
|
|
152
|
+
toast.success('Group created!');
|
|
153
|
+
},
|
|
154
|
+
onError: (error) => {
|
|
155
|
+
toast.error(error.message);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const handleCreate = async () => {
|
|
160
|
+
const { data, error } = await createGroup.mutate({
|
|
161
|
+
name: 'My Group',
|
|
162
|
+
slug: 'my-group',
|
|
163
|
+
type: 'community',
|
|
164
|
+
settings: {
|
|
165
|
+
visibility: 'public',
|
|
166
|
+
joinPolicy: 'open',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (error) {
|
|
171
|
+
console.error('Failed:', error);
|
|
172
|
+
} else {
|
|
173
|
+
console.log('Created:', data);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Benefits of This Architecture
|
|
179
|
+
|
|
180
|
+
### 1. Backend Flexibility
|
|
181
|
+
|
|
182
|
+
- Switch from Convex to REST API without changing components
|
|
183
|
+
- Connect to different backend deployments via env var
|
|
184
|
+
- Support multiple backends simultaneously
|
|
185
|
+
|
|
186
|
+
### 2. Type Safety
|
|
187
|
+
|
|
188
|
+
- TypeScript interfaces throughout
|
|
189
|
+
- Effect.ts for typed errors
|
|
190
|
+
- TanStack Query for predictable state
|
|
191
|
+
|
|
192
|
+
### 3. Testability
|
|
193
|
+
|
|
194
|
+
- Mock DataProvider for unit tests
|
|
195
|
+
- Test hooks independently
|
|
196
|
+
- No Convex-specific test setup needed
|
|
197
|
+
|
|
198
|
+
### 4. Performance
|
|
199
|
+
|
|
200
|
+
- TanStack Query caching
|
|
201
|
+
- Automatic request deduplication
|
|
202
|
+
- Background refetching
|
|
203
|
+
|
|
204
|
+
### 5. Developer Experience
|
|
205
|
+
|
|
206
|
+
- Domain-focused APIs (`useGroups` not `useQuery`)
|
|
207
|
+
- Consistent error handling
|
|
208
|
+
- Loading states built-in
|
|
209
|
+
|
|
210
|
+
## Environment Configuration
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# .env.local
|
|
214
|
+
PUBLIC_CONVEX_URL=https://shocking-falcon-870.convex.cloud
|
|
215
|
+
|
|
216
|
+
# Or connect to shared platform
|
|
217
|
+
PUBLIC_CONVEX_URL=https://api.one.ie
|
|
218
|
+
|
|
219
|
+
# Or customer's own deployment
|
|
220
|
+
PUBLIC_CONVEX_URL=https://customer.convex.cloud
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Creating New Hooks
|
|
224
|
+
|
|
225
|
+
Follow the established pattern in `src/hooks/useGroups.tsx`:
|
|
226
|
+
|
|
227
|
+
1. Define TypeScript types
|
|
228
|
+
2. Create query hooks using `useDataProvider()`
|
|
229
|
+
3. Create mutation hooks with cache invalidation
|
|
230
|
+
4. Export everything for easy importing
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// src/hooks/useCourses.tsx
|
|
234
|
+
export function useCourses(filter?, options?) {
|
|
235
|
+
const provider = useDataProvider();
|
|
236
|
+
|
|
237
|
+
const queryFn = async () => {
|
|
238
|
+
const effect = provider.things.list({
|
|
239
|
+
type: 'course',
|
|
240
|
+
...filter,
|
|
241
|
+
});
|
|
242
|
+
return await Effect.runPromise(effect);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return useQuery({
|
|
246
|
+
queryKey: ['courses', filter],
|
|
247
|
+
queryFn,
|
|
248
|
+
...options,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Migration Guide
|
|
254
|
+
|
|
255
|
+
To migrate from Convex hooks to domain hooks:
|
|
256
|
+
|
|
257
|
+
1. Find: `import { useQuery } from "convex/react"`
|
|
258
|
+
2. Replace with appropriate domain hook
|
|
259
|
+
3. Update data access patterns (no `undefined` checks needed)
|
|
260
|
+
4. Test with different backend URLs
|
|
261
|
+
|
|
262
|
+
## Summary
|
|
263
|
+
|
|
264
|
+
**Never import from `convex/react` or `convex/_generated/api` in components.**
|
|
265
|
+
|
|
266
|
+
Always use:
|
|
267
|
+
|
|
268
|
+
- `@/hooks/*` for data fetching
|
|
269
|
+
- `@/providers/*` for backend abstraction
|
|
270
|
+
- `@/types/*` for shared types
|
|
271
|
+
|
|
272
|
+
This keeps the frontend **100% decoupled** from the backend implementation.
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
# 🚀 Deployment Guide - ONE Web Platform
|
|
2
|
+
|
|
3
|
+
**Status:** ✅ Production Ready
|
|
4
|
+
|
|
5
|
+
This guide covers deploying the ONE web platform to Cloudflare Pages with React 19 SSR.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📊 Build Stats
|
|
10
|
+
|
|
11
|
+
- **Build Output:** 20MB
|
|
12
|
+
- **TypeScript Errors:** 0
|
|
13
|
+
- **Runtime:** Cloudflare Workers (Edge)
|
|
14
|
+
- **Framework:** Astro 5 + React 19
|
|
15
|
+
- **Backend:** Decoupled via `PUBLIC_CONVEX_URL`
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🎯 Pre-Deployment Checklist
|
|
20
|
+
|
|
21
|
+
### ✅ Required
|
|
22
|
+
|
|
23
|
+
- [ ] Backend deployed to Convex (URL ready)
|
|
24
|
+
- [ ] Environment variables configured
|
|
25
|
+
- [ ] Build completes without errors (`bun run build`)
|
|
26
|
+
- [ ] Cloudflare account with Pages access
|
|
27
|
+
- [ ] Domain configured (optional)
|
|
28
|
+
|
|
29
|
+
### ✅ Recommended
|
|
30
|
+
|
|
31
|
+
- [ ] Test locally with `bun run preview`
|
|
32
|
+
- [ ] Review `wrangler.toml` configuration
|
|
33
|
+
- [ ] KV namespace created for sessions
|
|
34
|
+
- [ ] Analytics configured
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🔧 Environment Variables
|
|
39
|
+
|
|
40
|
+
### Production Environment
|
|
41
|
+
|
|
42
|
+
Create `.env.production` or configure in Cloudflare Pages dashboard:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Backend Connection
|
|
46
|
+
PUBLIC_CONVEX_URL=https://shocking-falcon-870.convex.cloud
|
|
47
|
+
CONVEX_DEPLOYMENT=prod:shocking-falcon-870
|
|
48
|
+
|
|
49
|
+
# Authentication
|
|
50
|
+
BETTER_AUTH_SECRET=your-production-secret-key-min-32-chars
|
|
51
|
+
BETTER_AUTH_URL=https://yourdomain.com
|
|
52
|
+
|
|
53
|
+
# OAuth Providers (optional)
|
|
54
|
+
GITHUB_CLIENT_ID=your_github_client_id
|
|
55
|
+
GITHUB_CLIENT_SECRET=your_github_client_secret
|
|
56
|
+
GOOGLE_CLIENT_ID=your_google_client_id
|
|
57
|
+
GOOGLE_CLIENT_SECRET=your_google_client_secret
|
|
58
|
+
|
|
59
|
+
# Email (via backend)
|
|
60
|
+
# Configured in backend deployment
|
|
61
|
+
|
|
62
|
+
# Analytics (optional)
|
|
63
|
+
# Add your analytics IDs here
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Important Notes
|
|
67
|
+
|
|
68
|
+
- `BETTER_AUTH_SECRET`: Must be at least 32 characters
|
|
69
|
+
- `BETTER_AUTH_URL`: Must match your production domain
|
|
70
|
+
- OAuth redirects must be configured for production URLs
|
|
71
|
+
- All `PUBLIC_` prefixed vars are exposed to browser
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 📦 Deployment Methods
|
|
76
|
+
|
|
77
|
+
### Method 1: Cloudflare Pages Dashboard (Recommended)
|
|
78
|
+
|
|
79
|
+
**Step 1: Connect Repository**
|
|
80
|
+
|
|
81
|
+
1. Go to [Cloudflare Pages Dashboard](https://dash.cloudflare.com/pages)
|
|
82
|
+
2. Click "Create a project"
|
|
83
|
+
3. Connect your Git repository
|
|
84
|
+
4. Select the `web` directory as root
|
|
85
|
+
|
|
86
|
+
**Step 2: Configure Build**
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
Build command: bun run build
|
|
90
|
+
Build output directory: dist
|
|
91
|
+
Root directory: web
|
|
92
|
+
Node version: 20
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Step 3: Environment Variables**
|
|
96
|
+
|
|
97
|
+
Add all production environment variables in the dashboard under:
|
|
98
|
+
Settings → Environment Variables → Production
|
|
99
|
+
|
|
100
|
+
**Step 4: Deploy**
|
|
101
|
+
|
|
102
|
+
- Click "Save and Deploy"
|
|
103
|
+
- First build takes 2-3 minutes
|
|
104
|
+
- Subsequent builds: ~1 minute
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
### Method 2: Wrangler CLI
|
|
109
|
+
|
|
110
|
+
**Install Wrangler:**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install -g wrangler
|
|
114
|
+
# or
|
|
115
|
+
bun add -g wrangler
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Login:**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
wrangler login
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Deploy:**
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
cd web
|
|
128
|
+
bun run build
|
|
129
|
+
wrangler pages deploy dist --project-name=web
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Set Environment Variables:**
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
wrangler pages secret put BETTER_AUTH_SECRET --project-name=web
|
|
136
|
+
wrangler pages secret put PUBLIC_CONVEX_URL --project-name=web
|
|
137
|
+
# ... repeat for all secrets
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
### Method 3: CI/CD with GitHub Actions
|
|
143
|
+
|
|
144
|
+
Create `.github/workflows/deploy.yml`:
|
|
145
|
+
|
|
146
|
+
```yaml
|
|
147
|
+
name: Deploy to Cloudflare Pages
|
|
148
|
+
|
|
149
|
+
on:
|
|
150
|
+
push:
|
|
151
|
+
branches: [main]
|
|
152
|
+
paths:
|
|
153
|
+
- 'web/**'
|
|
154
|
+
|
|
155
|
+
jobs:
|
|
156
|
+
deploy:
|
|
157
|
+
runs-on: ubuntu-latest
|
|
158
|
+
steps:
|
|
159
|
+
- uses: actions/checkout@v4
|
|
160
|
+
|
|
161
|
+
- uses: oven-sh/setup-bun@v1
|
|
162
|
+
|
|
163
|
+
- name: Install dependencies
|
|
164
|
+
working-directory: ./web
|
|
165
|
+
run: bun install
|
|
166
|
+
|
|
167
|
+
- name: Build
|
|
168
|
+
working-directory: ./web
|
|
169
|
+
run: bun run build
|
|
170
|
+
env:
|
|
171
|
+
PUBLIC_CONVEX_URL: ${{ secrets.PUBLIC_CONVEX_URL }}
|
|
172
|
+
# Add other env vars
|
|
173
|
+
|
|
174
|
+
- name: Deploy to Cloudflare Pages
|
|
175
|
+
uses: cloudflare/pages-action@v1
|
|
176
|
+
with:
|
|
177
|
+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
178
|
+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
179
|
+
projectName: one-platform
|
|
180
|
+
directory: web/dist
|
|
181
|
+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 🗄️ Cloudflare KV Setup (Sessions)
|
|
187
|
+
|
|
188
|
+
**Create KV Namespace:**
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
wrangler kv:namespace create SESSION
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Add to `wrangler.toml`:**
|
|
195
|
+
|
|
196
|
+
```toml
|
|
197
|
+
[[kv_namespaces]]
|
|
198
|
+
binding = "SESSION"
|
|
199
|
+
id = "your-kv-namespace-id"
|
|
200
|
+
preview_id = "your-preview-kv-namespace-id"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Or configure in dashboard:**
|
|
204
|
+
|
|
205
|
+
Settings → Functions → KV Namespace Bindings
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 🌐 Custom Domain
|
|
210
|
+
|
|
211
|
+
**Method 1: Cloudflare Pages Dashboard**
|
|
212
|
+
|
|
213
|
+
1. Go to your project in Pages dashboard
|
|
214
|
+
2. Click "Custom domains"
|
|
215
|
+
3. Add your domain
|
|
216
|
+
4. Update DNS records as instructed
|
|
217
|
+
|
|
218
|
+
**Method 2: Wrangler CLI**
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
wrangler pages domain add web.one.ie --project-name=web
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**SSL/TLS:**
|
|
225
|
+
|
|
226
|
+
- Automatically provisioned by Cloudflare
|
|
227
|
+
- Free SSL certificates
|
|
228
|
+
- HTTP/3 enabled by default
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🔍 Post-Deployment Verification
|
|
233
|
+
|
|
234
|
+
### Health Checks
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
# Check homepage
|
|
238
|
+
curl -I https://web.one.ie
|
|
239
|
+
|
|
240
|
+
# Check API health
|
|
241
|
+
curl https://web.one.ie/api/health
|
|
242
|
+
|
|
243
|
+
# Check auth endpoints
|
|
244
|
+
curl https://web.one.ie/api/auth/get-session
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Monitoring
|
|
248
|
+
|
|
249
|
+
**Cloudflare Analytics:**
|
|
250
|
+
|
|
251
|
+
- Dashboard → Analytics
|
|
252
|
+
- Real-time visitors
|
|
253
|
+
- Performance metrics
|
|
254
|
+
- Error rates
|
|
255
|
+
|
|
256
|
+
**Custom Monitoring:**
|
|
257
|
+
|
|
258
|
+
- Set up alerts for 4xx/5xx errors
|
|
259
|
+
- Monitor worker invocations
|
|
260
|
+
- Track KV read/write operations
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 🐛 Troubleshooting
|
|
265
|
+
|
|
266
|
+
### Build Fails
|
|
267
|
+
|
|
268
|
+
**Error: TypeScript errors**
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Run locally
|
|
272
|
+
bun run build
|
|
273
|
+
|
|
274
|
+
# Check specific errors
|
|
275
|
+
bunx astro check
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Error: Missing dependencies**
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# Clear cache and reinstall
|
|
282
|
+
rm -rf node_modules bun.lockb
|
|
283
|
+
bun install
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Runtime Errors
|
|
287
|
+
|
|
288
|
+
**Error: Cannot connect to backend**
|
|
289
|
+
|
|
290
|
+
- Verify `PUBLIC_CONVEX_URL` is correct
|
|
291
|
+
- Check backend is deployed and accessible
|
|
292
|
+
- Test backend URL directly
|
|
293
|
+
|
|
294
|
+
**Error: Authentication not working**
|
|
295
|
+
|
|
296
|
+
- Verify `BETTER_AUTH_SECRET` matches backend
|
|
297
|
+
- Check `BETTER_AUTH_URL` matches production domain
|
|
298
|
+
- Verify OAuth redirect URLs are configured
|
|
299
|
+
|
|
300
|
+
**Error: KV Session binding**
|
|
301
|
+
|
|
302
|
+
- Create KV namespace in Cloudflare
|
|
303
|
+
- Add binding to `wrangler.toml`
|
|
304
|
+
- Redeploy
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## 📈 Performance Optimization
|
|
309
|
+
|
|
310
|
+
### Edge Rendering
|
|
311
|
+
|
|
312
|
+
- ✅ React 19 SSR on Cloudflare Edge
|
|
313
|
+
- ✅ `react-dom/server.edge` configured
|
|
314
|
+
- ✅ Streaming HTML responses
|
|
315
|
+
- ✅ 330+ global locations
|
|
316
|
+
|
|
317
|
+
### Caching Strategy
|
|
318
|
+
|
|
319
|
+
```javascript
|
|
320
|
+
// pages/_middleware.ts
|
|
321
|
+
export const onRequest = async (context) => {
|
|
322
|
+
const response = await context.next();
|
|
323
|
+
|
|
324
|
+
// Cache static assets
|
|
325
|
+
if (context.url.pathname.startsWith('/_astro/')) {
|
|
326
|
+
response.headers.set(
|
|
327
|
+
'Cache-Control',
|
|
328
|
+
'public, max-age=31536000, immutable'
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return response;
|
|
333
|
+
};
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Asset Optimization
|
|
337
|
+
|
|
338
|
+
- Images optimized at build time
|
|
339
|
+
- CSS minified and purged
|
|
340
|
+
- JavaScript bundled and tree-shaken
|
|
341
|
+
- Fonts preloaded
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 🔄 Rollback Strategy
|
|
346
|
+
|
|
347
|
+
**Cloudflare Pages keeps deployment history:**
|
|
348
|
+
|
|
349
|
+
1. Go to project → Deployments
|
|
350
|
+
2. Find previous working deployment
|
|
351
|
+
3. Click "Promote to production"
|
|
352
|
+
4. Instant rollback (< 30 seconds)
|
|
353
|
+
|
|
354
|
+
**Or via CLI:**
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
wrangler pages deployment list --project-name=web
|
|
358
|
+
wrangler pages deployment promote <deployment-id> --project-name=web
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## 📊 Deployment Metrics
|
|
364
|
+
|
|
365
|
+
### Target Performance
|
|
366
|
+
|
|
367
|
+
- **TTFB:** < 100ms (Edge locations)
|
|
368
|
+
- **FCP:** < 1.0s
|
|
369
|
+
- **LCP:** < 2.5s
|
|
370
|
+
- **TTI:** < 3.0s
|
|
371
|
+
- **CLS:** < 0.1
|
|
372
|
+
|
|
373
|
+
### Monitoring
|
|
374
|
+
|
|
375
|
+
- Cloudflare Web Analytics (free)
|
|
376
|
+
- Real User Monitoring (RUM)
|
|
377
|
+
- Core Web Vitals tracking
|
|
378
|
+
- Error tracking with Sentry (optional)
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## 🔐 Security Checklist
|
|
383
|
+
|
|
384
|
+
### Pre-Deployment
|
|
385
|
+
|
|
386
|
+
- [ ] Environment secrets secured
|
|
387
|
+
- [ ] OAuth redirects whitelisted
|
|
388
|
+
- [ ] CORS configured properly
|
|
389
|
+
- [ ] Rate limiting enabled (via backend)
|
|
390
|
+
- [ ] Content Security Policy set
|
|
391
|
+
|
|
392
|
+
### Post-Deployment
|
|
393
|
+
|
|
394
|
+
- [ ] Force HTTPS enabled
|
|
395
|
+
- [ ] Security headers configured
|
|
396
|
+
- [ ] DDoS protection active (Cloudflare)
|
|
397
|
+
- [ ] Bot protection enabled
|
|
398
|
+
- [ ] Regular security audits
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## 🎉 Success Criteria
|
|
403
|
+
|
|
404
|
+
**Deployment is successful when:**
|
|
405
|
+
|
|
406
|
+
✅ Build completes with 0 errors
|
|
407
|
+
✅ Site loads at production URL
|
|
408
|
+
✅ Auth flows work (signin, signup, magic link)
|
|
409
|
+
✅ Backend connectivity confirmed
|
|
410
|
+
✅ All pages render without errors
|
|
411
|
+
✅ Performance metrics meet targets
|
|
412
|
+
✅ Analytics reporting data
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## 📞 Support & Resources
|
|
417
|
+
|
|
418
|
+
**Documentation:**
|
|
419
|
+
|
|
420
|
+
- Cloudflare Pages: https://developers.cloudflare.com/pages
|
|
421
|
+
- Astro SSR: https://docs.astro.build/en/guides/server-side-rendering/
|
|
422
|
+
- Better Auth: https://better-auth.com/docs
|
|
423
|
+
|
|
424
|
+
**Getting Help:**
|
|
425
|
+
|
|
426
|
+
- GitHub Issues: Report bugs and feature requests
|
|
427
|
+
- Cloudflare Community: https://community.cloudflare.com
|
|
428
|
+
- Astro Discord: https://astro.build/chat
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
## 🚀 Quick Deploy (Production)
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
# 1. Build
|
|
436
|
+
cd web
|
|
437
|
+
bun run build
|
|
438
|
+
|
|
439
|
+
# 2. Deploy
|
|
440
|
+
wrangler pages deploy dist --project-name=one-platform
|
|
441
|
+
|
|
442
|
+
# 3. Verify
|
|
443
|
+
curl -I https://web.one.ie
|
|
444
|
+
|
|
445
|
+
# 4. Done! 🎉
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
**Last Updated:** October 14, 2025
|
|
451
|
+
**Build Version:** Production Ready
|
|
452
|
+
**Status:** ✅ Deployment Ready
|