create-lego-one 2.0.10 → 2.0.13
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/dist/index.cjs +179 -0
- package/dist/index.cjs.map +1 -1
- package/package.json +5 -3
- package/template/.cursor/rules/rules.mdc +639 -0
- package/template/.dockerignore +58 -0
- package/template/.env.example +18 -0
- package/template/.eslintignore +5 -0
- package/template/.eslintrc.js +28 -0
- package/template/.prettierignore +6 -0
- package/template/.prettierrc +11 -0
- package/template/CLAUDE.md +634 -0
- package/template/Dockerfile +67 -0
- package/template/PROMPT.md +457 -0
- package/template/README.md +325 -0
- package/template/docker-compose.yml +48 -0
- package/template/docker-entrypoint.sh +23 -0
- package/template/docs/checkpoints/.template.md +64 -0
- package/template/docs/checkpoints/framework/01-infrastructure-setup.md +132 -0
- package/template/docs/checkpoints/framework/02-pocketbase-setup.md +155 -0
- package/template/docs/checkpoints/framework/03-host-kernel.md +170 -0
- package/template/docs/checkpoints/framework/04-auth-system.md +163 -0
- package/template/docs/checkpoints/framework/phase-05-multitenancy-rbac.md +223 -0
- package/template/docs/checkpoints/framework/phase-06-ui-components.md +260 -0
- package/template/docs/checkpoints/framework/phase-07-communication-system.md +276 -0
- package/template/docs/checkpoints/framework/phase-08-plugin-system.md +91 -0
- package/template/docs/checkpoints/framework/phase-09-dashboard-plugin.md +111 -0
- package/template/docs/checkpoints/framework/phase-10-todo-plugin.md +169 -0
- package/template/docs/checkpoints/framework/phase-11-testing.md +264 -0
- package/template/docs/checkpoints/framework/phase-12-deployment.md +294 -0
- package/template/docs/checkpoints/framework/phase-13-documentation.md +312 -0
- package/template/docs/framework/plans/00-index.md +164 -0
- package/template/docs/framework/plans/01-infrastructure-setup.md +855 -0
- package/template/docs/framework/plans/02-pocketbase-setup.md +1374 -0
- package/template/docs/framework/plans/03-host-kernel.md +1518 -0
- package/template/docs/framework/plans/04-auth-system.md +1466 -0
- package/template/docs/framework/plans/05-multitenancy-rbac.md +1527 -0
- package/template/docs/framework/plans/06-ui-components.md +1478 -0
- package/template/docs/framework/plans/07-communication-system.md +1106 -0
- package/template/docs/framework/plans/08-plugin-system.md +1179 -0
- package/template/docs/framework/plans/09-dashboard-plugin.md +1137 -0
- package/template/docs/framework/plans/10-todo-plugin.md +1343 -0
- package/template/docs/framework/plans/11-testing.md +935 -0
- package/template/docs/framework/plans/12-deployment.md +896 -0
- package/template/docs/framework/prompts/0-boilerplate-modernjs.md +151 -0
- package/template/docs/framework/research/00-modernjs-audit.md +488 -0
- package/template/docs/framework/research/01-system-blueprint.md +721 -0
- package/template/docs/framework/research/02-data-migration-protocol.md +699 -0
- package/template/docs/framework/research/03-host-setup.md +714 -0
- package/template/docs/framework/research/04-plugin-architecture.md +645 -0
- package/template/docs/framework/research/05-slot-injection-pattern.md +671 -0
- package/template/docs/framework/research/06-cli-strategy.md +615 -0
- package/template/docs/framework/research/07-deployment.md +629 -0
- package/template/docs/framework/research/README.md +282 -0
- package/template/docs/framework/setup/00-index.md +210 -0
- package/template/docs/framework/setup/01-framework-structure.md +308 -0
- package/template/docs/framework/setup/02-development-workflow.md +405 -0
- package/template/docs/framework/setup/03-environment-setup.md +215 -0
- package/template/docs/framework/setup/04-kernel-architecture.md +499 -0
- package/template/docs/framework/setup/05-plugin-system.md +620 -0
- package/template/docs/framework/setup/06-communication-patterns.md +451 -0
- package/template/docs/framework/setup/07-plugin-development.md +582 -0
- package/template/docs/framework/setup/08-component-library.md +658 -0
- package/template/docs/framework/setup/09-data-integration.md +609 -0
- package/template/docs/framework/setup/10-auth-rbac.md +497 -0
- package/template/docs/framework/setup/11-hooks-api.md +393 -0
- package/template/docs/framework/setup/12-components-api.md +665 -0
- package/template/docs/framework/setup/13-deployment-guide.md +566 -0
- package/template/docs/framework/setup/README.md +548 -0
- package/template/host/e2e/auth.spec.ts +38 -0
- package/template/host/e2e/layout.spec.ts +38 -0
- package/template/host/modern.config.ts +19 -0
- package/template/host/package.json +71 -0
- package/template/host/playwright.config.ts +34 -0
- package/template/host/postcss.config.mjs +6 -0
- package/template/host/src/App.tsx +6 -0
- package/template/host/src/bootstrap.tsx +74 -0
- package/template/host/src/global.css +59 -0
- package/template/host/src/index.ts +2 -0
- package/template/host/src/kernel/__tests__/lib-utils.test.ts +32 -0
- package/template/host/src/kernel/__tests__/rbac-hooks.test.tsx +114 -0
- package/template/host/src/kernel/__tests__/rbac-utils.test.ts +108 -0
- package/template/host/src/kernel/auth/ProtectedRoute.tsx +41 -0
- package/template/host/src/kernel/auth/components/LoginForm.tsx +97 -0
- package/template/host/src/kernel/auth/components/LogoutButton.tsx +79 -0
- package/template/host/src/kernel/auth/hooks.ts +174 -0
- package/template/host/src/kernel/auth/index.ts +5 -0
- package/template/host/src/kernel/auth/schemas.ts +27 -0
- package/template/host/src/kernel/auth/service.ts +197 -0
- package/template/host/src/kernel/auth/types.ts +36 -0
- package/template/host/src/kernel/channels/ChannelBus.ts +181 -0
- package/template/host/src/kernel/channels/ChannelProvider.tsx +57 -0
- package/template/host/src/kernel/channels/events.ts +27 -0
- package/template/host/src/kernel/channels/hooks.ts +168 -0
- package/template/host/src/kernel/channels/index.ts +6 -0
- package/template/host/src/kernel/channels/integrations/ToastIntegration.tsx +60 -0
- package/template/host/src/kernel/channels/plugin-hooks.ts +72 -0
- package/template/host/src/kernel/channels/types.ts +112 -0
- package/template/host/src/kernel/components/__tests__/Badge.test.tsx +35 -0
- package/template/host/src/kernel/components/__tests__/Button.test.tsx +63 -0
- package/template/host/src/kernel/components/__tests__/Input.test.tsx +64 -0
- package/template/host/src/kernel/components/index.ts +32 -0
- package/template/host/src/kernel/components/ui/alert.tsx +58 -0
- package/template/host/src/kernel/components/ui/avatar.tsx +47 -0
- package/template/host/src/kernel/components/ui/badge.tsx +35 -0
- package/template/host/src/kernel/components/ui/button.tsx +50 -0
- package/template/host/src/kernel/components/ui/card.tsx +78 -0
- package/template/host/src/kernel/components/ui/dialog.tsx +116 -0
- package/template/host/src/kernel/components/ui/dropdown-menu.tsx +192 -0
- package/template/host/src/kernel/components/ui/index.ts +7 -0
- package/template/host/src/kernel/components/ui/input.tsx +24 -0
- package/template/host/src/kernel/components/ui/label.tsx +21 -0
- package/template/host/src/kernel/components/ui/popover.tsx +28 -0
- package/template/host/src/kernel/components/ui/progress.tsx +25 -0
- package/template/host/src/kernel/components/ui/scroll-area.tsx +45 -0
- package/template/host/src/kernel/components/ui/select.tsx +155 -0
- package/template/host/src/kernel/components/ui/separator.tsx +28 -0
- package/template/host/src/kernel/components/ui/skeleton.tsx +15 -0
- package/template/host/src/kernel/components/ui/switch.tsx +26 -0
- package/template/host/src/kernel/components/ui/table.tsx +116 -0
- package/template/host/src/kernel/components/ui/tabs.tsx +52 -0
- package/template/host/src/kernel/components/ui/toast.tsx +126 -0
- package/template/host/src/kernel/components/ui/toaster.tsx +34 -0
- package/template/host/src/kernel/components/ui/tooltip.tsx +27 -0
- package/template/host/src/kernel/components/ui/use-toast.ts +183 -0
- package/template/host/src/kernel/index.ts +48 -0
- package/template/host/src/kernel/lib/cn.ts +1 -0
- package/template/host/src/kernel/lib/utils.ts +36 -0
- package/template/host/src/kernel/plugins/Slot.tsx +41 -0
- package/template/host/src/kernel/plugins/SlotProvider.tsx +88 -0
- package/template/host/src/kernel/plugins/index.ts +23 -0
- package/template/host/src/kernel/plugins/loader.ts +122 -0
- package/template/host/src/kernel/plugins/schemas.ts +54 -0
- package/template/host/src/kernel/plugins/store.ts +185 -0
- package/template/host/src/kernel/plugins/types.ts +103 -0
- package/template/host/src/kernel/providers/PocketBaseProvider.tsx +70 -0
- package/template/host/src/kernel/providers/QueryProvider.tsx +28 -0
- package/template/host/src/kernel/providers/ThemeProvider.tsx +25 -0
- package/template/host/src/kernel/providers/index.ts +3 -0
- package/template/host/src/kernel/rbac/components/OrganizationSelector.tsx +69 -0
- package/template/host/src/kernel/rbac/components/PermissionGate.tsx +43 -0
- package/template/host/src/kernel/rbac/hooks.ts +379 -0
- package/template/host/src/kernel/rbac/index.ts +6 -0
- package/template/host/src/kernel/rbac/service.ts +504 -0
- package/template/host/src/kernel/rbac/types.ts +164 -0
- package/template/host/src/kernel/rbac/utils.ts +34 -0
- package/template/host/src/kernel/shared-state/bridge.ts +31 -0
- package/template/host/src/kernel/shared-state/index.ts +3 -0
- package/template/host/src/kernel/shared-state/store.ts +62 -0
- package/template/host/src/kernel/shared-state/types.ts +60 -0
- package/template/host/src/kernel/use-migrations.ts +72 -0
- package/template/host/src/layout/MobileMenu.tsx +61 -0
- package/template/host/src/layout/Shell.tsx +42 -0
- package/template/host/src/layout/Sidebar.tsx +178 -0
- package/template/host/src/layout/Topbar.tsx +50 -0
- package/template/host/src/layout/index.ts +4 -0
- package/template/host/src/lib/pocketbase/client.ts +38 -0
- package/template/host/src/lib/pocketbase/collections/audit_logs.ts +87 -0
- package/template/host/src/lib/pocketbase/collections/index.ts +19 -0
- package/template/host/src/lib/pocketbase/collections/organizations.ts +63 -0
- package/template/host/src/lib/pocketbase/collections/permissions.ts +57 -0
- package/template/host/src/lib/pocketbase/collections/roles.ts +55 -0
- package/template/host/src/lib/pocketbase/collections/todos.ts +74 -0
- package/template/host/src/lib/pocketbase/collections/user_roles.ts +57 -0
- package/template/host/src/lib/pocketbase/collections/users.ts +43 -0
- package/template/host/src/lib/pocketbase/index.ts +5 -0
- package/template/host/src/lib/pocketbase/migrations.ts +44 -0
- package/template/host/src/lib/pocketbase/seed/permissions.ts +8 -0
- package/template/host/src/lib/pocketbase/seed/roles.ts +22 -0
- package/template/host/src/lib/pocketbase/seed.ts +113 -0
- package/template/host/src/lib/pocketbase/types.ts +102 -0
- package/template/host/src/modern.runtime.ts +26 -0
- package/template/host/src/plugins.d.ts +9 -0
- package/template/host/src/providers/PocketBaseProvider.tsx +30 -0
- package/template/host/src/routes/_.tsx +6 -0
- package/template/host/src/routes/dashboard._.tsx +41 -0
- package/template/host/src/routes/index.tsx +93 -0
- package/template/host/src/routes/login.tsx +36 -0
- package/template/host/src/saas.config.ts +52 -0
- package/template/host/src/test/setup.ts +65 -0
- package/template/host/src/test/utils.tsx +69 -0
- package/template/host/src/test/vitest-globals.d.ts +19 -0
- package/template/host/src/vite-env.d.ts +16 -0
- package/template/host/tailwind.config.ts +77 -0
- package/template/host/tsconfig.json +19 -0
- package/template/host/vitest.config.ts +30 -0
- package/template/nginx.conf +72 -0
- package/template/package.json +44 -0
- package/template/packages/plugins/@lego/plugin-dashboard/modern.config.ts +19 -0
- package/template/packages/plugins/@lego/plugin-dashboard/package.json +35 -0
- package/template/packages/plugins/@lego/plugin-dashboard/postcss.config.mjs +6 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/App.tsx +27 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/ActivityFeed.tsx +63 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/QuickActionSlot.tsx +11 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/QuickActions.tsx +68 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/SidebarWidget.tsx +35 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/StatCard.tsx +47 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/global.css +24 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/useChannelIntegration.ts +43 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/useDashboardStats.ts +65 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/usePocketBase.ts +47 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/useRecentActivity.ts +55 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/lib/utils.ts +6 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/pages/DashboardPage.tsx +105 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/plugin.config.ts +121 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/plugin.ts +18 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/vite-env.d.ts +32 -0
- package/template/packages/plugins/@lego/plugin-dashboard/tailwind.config.ts +35 -0
- package/template/packages/plugins/@lego/plugin-dashboard/tsconfig.json +18 -0
- package/template/packages/plugins/@lego/plugin-todo/modern.config.ts +18 -0
- package/template/packages/plugins/@lego/plugin-todo/package.json +41 -0
- package/template/packages/plugins/@lego/plugin-todo/postcss.config.mjs +6 -0
- package/template/packages/plugins/@lego/plugin-todo/src/App.tsx +12 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/SidebarWidget.tsx +16 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoDialog.tsx +55 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoFilters.tsx +79 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoForm.tsx +94 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoItem.tsx +121 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoList.tsx +41 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/index.ts +6 -0
- package/template/packages/plugins/@lego/plugin-todo/src/global.css +59 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useCreateTodo.ts +62 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useDeleteTodo.ts +46 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/usePocketBase.ts +38 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useTodos.ts +64 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useUpdateTodo.ts +35 -0
- package/template/packages/plugins/@lego/plugin-todo/src/index.tsx +5 -0
- package/template/packages/plugins/@lego/plugin-todo/src/lib/utils.ts +20 -0
- package/template/packages/plugins/@lego/plugin-todo/src/pages/TodoPage.tsx +89 -0
- package/template/packages/plugins/@lego/plugin-todo/src/plugin.config.ts +104 -0
- package/template/packages/plugins/@lego/plugin-todo/src/plugin.ts +13 -0
- package/template/packages/plugins/@lego/plugin-todo/src/schemas.ts +37 -0
- package/template/packages/plugins/@lego/plugin-todo/src/types.ts +42 -0
- package/template/packages/plugins/@lego/plugin-todo/src/vite-env.d.ts +31 -0
- package/template/packages/plugins/@lego/plugin-todo/tailwind.config.ts +51 -0
- package/template/packages/plugins/@lego/plugin-todo/tsconfig.json +18 -0
- package/template/pnpm-workspace.yaml +4 -0
- package/template/pocketbase/CHANGELOG.md +911 -0
- package/template/pocketbase/LICENSE.md +17 -0
- package/template/scripts/create-plugin.js +221 -0
- package/template/scripts/deploy.sh +56 -0
- package/template/tsconfig.base.json +26 -0
- package/template/tsconfig.json +8 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
# AI Workflow for Lego-One Development
|
|
2
|
+
|
|
3
|
+
> **Lego-One**: Modular SaaS boilerplate with microkernel architecture using Modern.js + Garfish + PocketBase
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## AUTOMATIC CONTEXT INGESTION
|
|
8
|
+
|
|
9
|
+
**WHEN THIS SESSION STARTS:**
|
|
10
|
+
|
|
11
|
+
You MUST automatically read and ingest the following files in order:
|
|
12
|
+
|
|
13
|
+
1. **`CLAUDE.md`** (this file) - Core workflow and architecture rules
|
|
14
|
+
2. **`PROMPT.md`** (if provided by user) - Session-specific task context
|
|
15
|
+
3. **`/docs/framework/setup/00-index.md`** - AI documentation index
|
|
16
|
+
4. **Relevant documentation files** based on task type
|
|
17
|
+
|
|
18
|
+
**DO NOT START CODING** until you have read these files.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## CRITICAL RULES
|
|
23
|
+
|
|
24
|
+
### 0. UPDATE README.md WHEN CODE CHANGES ⚠️
|
|
25
|
+
|
|
26
|
+
**IMPORTANT:** When making any code changes that affect:
|
|
27
|
+
- Project structure or file locations
|
|
28
|
+
- New features or capabilities
|
|
29
|
+
- API changes or new endpoints
|
|
30
|
+
- Configuration changes
|
|
31
|
+
- New commands or scripts
|
|
32
|
+
- Documentation paths or locations
|
|
33
|
+
- Any user-facing functionality
|
|
34
|
+
|
|
35
|
+
**YOU MUST UPDATE THE README.md FILE** to reflect these changes. The README.md is the primary source of information for users, and it must stay current with the actual codebase.
|
|
36
|
+
|
|
37
|
+
**Before completing any task:**
|
|
38
|
+
1. Review what changed in the codebase
|
|
39
|
+
2. Check if README.md needs updates
|
|
40
|
+
3. Update README.md sections that are affected
|
|
41
|
+
4. Ensure examples, paths, and instructions are accurate
|
|
42
|
+
|
|
43
|
+
**DO NOT** leave README.md outdated - users rely on it for accurate information.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
### 1. MICROKERNEL ARCHITECTURE ENFORCEMENT ⚠️
|
|
48
|
+
|
|
49
|
+
**STRICT SEPARATION BETWEEN KERNEL AND APPLICATION:**
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
53
|
+
│ HOST/FRAMEWORK (KERNEL) │
|
|
54
|
+
│ Core System: host/src/kernel/ │
|
|
55
|
+
│ - Authentication, RBAC, State Management │
|
|
56
|
+
│ - Plugin Loader, Slot Injection System │
|
|
57
|
+
│ - Shared UI Components, Layout │
|
|
58
|
+
│ - Window Bridge, Channel Bus │
|
|
59
|
+
└─────────────────────────────────────────────────────────────┘
|
|
60
|
+
│
|
|
61
|
+
══════════════════════════
|
|
62
|
+
PLUGIN BOUNDARY (Garfish)
|
|
63
|
+
══════════════════════════
|
|
64
|
+
│
|
|
65
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
66
|
+
│ APPLICATION PLUGINS │
|
|
67
|
+
│ Feature Modules: packages/plugins/@lego/ │
|
|
68
|
+
│ - Dashboard, Todo, Custom Features │
|
|
69
|
+
│ - Plugin-specific UI, Logic, Data │
|
|
70
|
+
└─────────────────────────────────────────────────────────────┘
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**RULES YOU MUST FOLLOW:**
|
|
74
|
+
|
|
75
|
+
| Scenario | Action |
|
|
76
|
+
|----------|--------|
|
|
77
|
+
| **Working on Application Plugin** | Implement ALL logic within the plugin. Use window bridge for kernel communication. |
|
|
78
|
+
| **Task Requires Kernel Modification** | **STOP IMMEDIATELY**. Follow "Framework Change Protocol" below. |
|
|
79
|
+
| **Uncertain Where Code Belongs** | Ask user for clarification before proceeding. |
|
|
80
|
+
|
|
81
|
+
**FRAMEWORK CHANGE PROTOCOL:**
|
|
82
|
+
|
|
83
|
+
When a task CANNOT be achieved without modifying the core Framework/Kernel:
|
|
84
|
+
|
|
85
|
+
1. **STOP IMMEDIATELY** - Do not write any kernel code
|
|
86
|
+
2. **INFORM THE USER** with this message:
|
|
87
|
+
> "⚠️ This task requires changes to the core Framework/Kernel. Modifying the kernel directly is not recommended as it may affect future framework updates."
|
|
88
|
+
3. **REQUEST PERMISSION** - Ask: "Do you want me to proceed with kernel modifications?"
|
|
89
|
+
4. **IF PERMISSION GRANTED:**
|
|
90
|
+
- Make kernel changes first
|
|
91
|
+
- Document the changes in a checkpoint
|
|
92
|
+
- Inform user they should update framework and run `pnpm update` in dependent applications
|
|
93
|
+
5. **IF PERMISSION DENIED:**
|
|
94
|
+
- Suggest alternative approaches using existing kernel features
|
|
95
|
+
- Implement feature within plugin constraints only
|
|
96
|
+
|
|
97
|
+
**WHAT CONSTITUTES A KERNEL CHANGE:**
|
|
98
|
+
|
|
99
|
+
- ❌ Modifying files in `host/src/kernel/`
|
|
100
|
+
- ❌ Adding new shared dependencies
|
|
101
|
+
- ❌ Changing the slot injection system
|
|
102
|
+
- ❌ Modifying window bridge structure
|
|
103
|
+
- ❌ Changing authentication/RBAC core logic
|
|
104
|
+
|
|
105
|
+
**WHAT DOES NOT REQUIRE KERNEL CHANGES:**
|
|
106
|
+
|
|
107
|
+
- ✅ Creating new plugins
|
|
108
|
+
- ✅ Adding features within existing plugins
|
|
109
|
+
- ✅ Using existing slots for UI injection
|
|
110
|
+
- ✅ Using window bridge to read kernel state
|
|
111
|
+
- ✅ Using channel bus for events
|
|
112
|
+
- ✅ Creating PocketBase collections (application-level)
|
|
113
|
+
|
|
114
|
+
**ENFORCEMENT:**
|
|
115
|
+
|
|
116
|
+
Before making ANY changes to `host/src/kernel/`, ask yourself:
|
|
117
|
+
|
|
118
|
+
1. Is this change absolutely necessary?
|
|
119
|
+
2. Can this be achieved through plugin configuration?
|
|
120
|
+
3. Can I use window bridge instead of direct imports?
|
|
121
|
+
4. Have I informed the user and received permission?
|
|
122
|
+
|
|
123
|
+
**IF ANSWER IS NO TO ANY QUESTION** - Do not proceed.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### 2. READ DOCUMENTATION FIRST
|
|
128
|
+
|
|
129
|
+
**Before starting ANY code:**
|
|
130
|
+
|
|
131
|
+
1. **ALWAYS read** `/docs/framework/setup/00-index.md` for the complete AI documentation index
|
|
132
|
+
2. **Read relevant files** based on your task type:
|
|
133
|
+
- Creating plugin → Read `07-plugin-development.md`
|
|
134
|
+
- Adding feature → Read relevant files from index
|
|
135
|
+
- Fixing bug → Read `02-development-workflow.md` troubleshooting section
|
|
136
|
+
3. **Follow established patterns** - Consistency is critical
|
|
137
|
+
|
|
138
|
+
**DO NOT skip documentation to "save time"** - This causes bugs and inconsistencies.
|
|
139
|
+
|
|
140
|
+
### 3. WRITE CHECKPOINTS FOR ALL WORK
|
|
141
|
+
|
|
142
|
+
**For EVERY task, bugfix, or feature:**
|
|
143
|
+
|
|
144
|
+
1. **Create a checkpoint file** in the appropriate directory:
|
|
145
|
+
- Bugfixes → `/docs/checkpoints/bugfixes/<title>.md`
|
|
146
|
+
- Features → `/docs/checkpoints/features/<title>.md`
|
|
147
|
+
- Enhancements → `/docs/checkpoints/enhancements/<title>.md`
|
|
148
|
+
|
|
149
|
+
2. **Use the template** from `/docs/checkpoints/.template.md`
|
|
150
|
+
|
|
151
|
+
3. **Update the checkpoint** as you progress:
|
|
152
|
+
- Document what you're doing
|
|
153
|
+
- List files modified/created
|
|
154
|
+
- Note issues encountered and solutions
|
|
155
|
+
- Mark status (In Progress → Completed)
|
|
156
|
+
|
|
157
|
+
4. **Mark complete** when the task is done
|
|
158
|
+
|
|
159
|
+
**Why checkpoints matter:**
|
|
160
|
+
- They track progress over time
|
|
161
|
+
- They help debug future issues
|
|
162
|
+
- They document what works and what doesn't
|
|
163
|
+
- They enable knowledge sharing
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Architecture Overview
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
171
|
+
│ HOST (KERNEL) │
|
|
172
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
173
|
+
│ │ Core Infrastructure │ │
|
|
174
|
+
│ │ - Authentication (PocketBase SDK) │ │
|
|
175
|
+
│ │ - Global Layout (Sidebar, Topbar, Toasts) │ │
|
|
176
|
+
│ │ - Router (React Router v6 via Modern.js) │ │
|
|
177
|
+
│ │ - State Bus (Zustand + Garfish Channel) │ │
|
|
178
|
+
│ │ - Plugin Loader (saas.config.ts reader) │ │
|
|
179
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
180
|
+
│ │
|
|
181
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
182
|
+
│ │ SHARED DEPENDENCIES (externals via Garfish) │ │
|
|
183
|
+
│ │ - React, ReactDOM - Zustand Store Bridge │ │
|
|
184
|
+
│ │ - UI Primitives (Radix, Shadcn) │ │
|
|
185
|
+
│ │ - TanStack Query v5 (shared QueryClient) │ │
|
|
186
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
187
|
+
└─────────────────────────────────────────────────────────────┘
|
|
188
|
+
│
|
|
189
|
+
Plugin Boundary (Garfish.loadApp)
|
|
190
|
+
│
|
|
191
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
192
|
+
│ PLUGINS (Feature Modules) │
|
|
193
|
+
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
|
194
|
+
│ │Dashboard │ │ Todo │ │ Billing │ │ Custom │ │
|
|
195
|
+
│ │ (:3001) │ │ (:3002) │ │ (:3003) │ │ (:3004) │ │
|
|
196
|
+
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
|
|
197
|
+
└─────────────────────────────────────────────────────────────┘
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Documentation Index
|
|
203
|
+
|
|
204
|
+
**PRIMARY: AI Documentation (Read Sequentially)**
|
|
205
|
+
|
|
206
|
+
| # | File | Purpose |
|
|
207
|
+
|---|------|---------|
|
|
208
|
+
| 00 | `docs/framework/setup/00-index.md` | **START HERE** - Complete AI documentation index |
|
|
209
|
+
| 01 | `docs/framework/setup/01-framework-structure.md` | Project structure and architecture |
|
|
210
|
+
| 02 | `docs/framework/setup/02-development-workflow.md` | How to work on this framework |
|
|
211
|
+
| 03 | `docs/framework/setup/03-environment-setup.md` | Environment setup and prerequisites |
|
|
212
|
+
| 04 | `docs/framework/setup/04-kernel-architecture.md` | Host/kernel system overview and architecture |
|
|
213
|
+
| 05 | `docs/framework/setup/05-plugin-system.md` | Plugin architecture, loading, and slot injection |
|
|
214
|
+
| 06 | `docs/framework/setup/06-communication-patterns.md` | Window bridge and channel bus for plugin-host communication |
|
|
215
|
+
| 07 | `docs/framework/setup/07-plugin-development.md` | Complete plugin creation guide |
|
|
216
|
+
| 08 | `docs/framework/setup/08-component-library.md` | UI components, styling, and design system |
|
|
217
|
+
| 09 | `docs/framework/setup/09-data-integration.md` | PocketBase, multi-tenancy, and data fetching patterns |
|
|
218
|
+
| 10 | `docs/framework/setup/10-auth-rbac.md` | Authentication, authorization, and permission management |
|
|
219
|
+
| 11 | `docs/framework/setup/11-hooks-api.md` | All kernel hooks documented |
|
|
220
|
+
| 12 | `docs/framework/setup/12-components-api.md` | UI component library API reference |
|
|
221
|
+
| 13 | `docs/framework/setup/13-deployment-guide.md` | Production deployment instructions |
|
|
222
|
+
|
|
223
|
+
**SUPPORTING: Implementation Plans**
|
|
224
|
+
|
|
225
|
+
| Phase | Document | Description |
|
|
226
|
+
|-------|----------|-------------|
|
|
227
|
+
| 1 | `docs/framework/plans/01-infrastructure-setup.md` | Monorepo, dependencies, tooling |
|
|
228
|
+
| 2 | `docs/framework/plans/02-pocketbase-setup.md` | PocketBase collections, API rules |
|
|
229
|
+
| 3 | `docs/framework/plans/03-host-kernel.md` | Host app, shared state, layout |
|
|
230
|
+
| 4 | `docs/framework/plans/04-auth-system.md` | Authentication, login/logout |
|
|
231
|
+
| 5 | `docs/framework/plans/05-multitenancy-rbac.md` | Organizations, users, roles |
|
|
232
|
+
| 6 | `docs/framework/plans/06-ui-components.md` | UI component library |
|
|
233
|
+
| 7 | `docs/framework/plans/07-communication-system.md` | Channel bus, toast system |
|
|
234
|
+
| 8 | `docs/framework/plans/08-plugin-system.md` | Plugin architecture, slots |
|
|
235
|
+
| 9 | `docs/framework/plans/09-dashboard-plugin.md` | Dashboard plugin |
|
|
236
|
+
| 10 | `docs/framework/plans/10-todo-plugin.md` | Todo plugin with CRUD |
|
|
237
|
+
| 11 | `docs/framework/plans/11-testing.md` | Unit, component, E2E tests |
|
|
238
|
+
| 12 | `docs/framework/plans/12-deployment.md` | Build, deploy, CI/CD |
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Key File Locations
|
|
243
|
+
|
|
244
|
+
| Purpose | Path |
|
|
245
|
+
|---------|------|
|
|
246
|
+
| **AI Documentation** | `docs/framework/setup/` |
|
|
247
|
+
| **Implementation Plans** | `docs/framework/plans/` |
|
|
248
|
+
| **Checkpoints** | `docs/checkpoints/` |
|
|
249
|
+
| Host Kernel | `host/src/kernel/` |
|
|
250
|
+
| Host Routes | `host/src/routes/` |
|
|
251
|
+
| Plugins | `packages/plugins/@lego/` |
|
|
252
|
+
| PocketBase Data | `pocketbase/pb_data/` |
|
|
253
|
+
| Plugin Config | `host/saas.config.ts` |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## 2. Follow Established Patterns
|
|
258
|
+
|
|
259
|
+
### When Working on HOST (Kernel):
|
|
260
|
+
|
|
261
|
+
**File Structure:**
|
|
262
|
+
```
|
|
263
|
+
host/src/
|
|
264
|
+
├── kernel/
|
|
265
|
+
│ ├── shared-state/ # Zustand store + window bridge
|
|
266
|
+
│ ├── providers/ # PocketBase, Query, Theme
|
|
267
|
+
│ ├── plugins/ # Plugin system, slots
|
|
268
|
+
│ ├── channels/ # Garfish channel bus
|
|
269
|
+
│ ├── auth/ # Authentication logic
|
|
270
|
+
│ ├── rbac/ # Multitenancy, permissions
|
|
271
|
+
│ ├── lib/ # Utilities (cn, formatDate)
|
|
272
|
+
│ └── components/ # Shared UI components
|
|
273
|
+
├── layout/ # Shell, Sidebar, Topbar
|
|
274
|
+
├── routes/ # File-based routing
|
|
275
|
+
├── bootstrap.tsx # App entry point
|
|
276
|
+
├── modern.runtime.ts # Garfish plugin config
|
|
277
|
+
└── saas.config.ts # Plugin enable/disable
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Key Patterns:**
|
|
281
|
+
- Use `window.__LEGO_KERNEL_STATE__` for shared state bridge
|
|
282
|
+
- Use Garfish channel for inter-plugin communication
|
|
283
|
+
- Slots in layout: `sidebar:nav`, `sidebar:top`, `sidebar:bottom`, `topbar:left`, `topbar:right`, `topbar:center`
|
|
284
|
+
- Always use `usePocketBase()` hook for API access
|
|
285
|
+
- Use `useGlobalKernelState()` for auth/user/org context
|
|
286
|
+
|
|
287
|
+
### When Creating PLUGINS:
|
|
288
|
+
|
|
289
|
+
**Standard Plugin Structure:**
|
|
290
|
+
```
|
|
291
|
+
packages/plugins/@lego/plugin-<name>/
|
|
292
|
+
├── package.json
|
|
293
|
+
├── tsconfig.json
|
|
294
|
+
├── modern.config.ts # Dev port, microFrontend: true
|
|
295
|
+
├── plugin.config.ts # Plugin manifest, slots, routes
|
|
296
|
+
├── tailwind.config.ts
|
|
297
|
+
└── src/
|
|
298
|
+
├── global.css
|
|
299
|
+
├── App.tsx # Plugin root
|
|
300
|
+
├── plugin.ts # Entry export
|
|
301
|
+
├── types.ts # TypeScript interfaces
|
|
302
|
+
├── schemas.ts # Zod validation
|
|
303
|
+
├── pages/ # Route components
|
|
304
|
+
├── components/ # UI components
|
|
305
|
+
│ └── slots/ # Slot injection components
|
|
306
|
+
└── hooks/ # Custom hooks
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Plugin Registration Checklist:**
|
|
310
|
+
1. Add to `host/src/modern.runtime.ts` (dev entry URL, prod dynamic import, activeWhen path)
|
|
311
|
+
2. Add to `host/saas.config.ts` (name, enabled: true)
|
|
312
|
+
3. Assign unique dev port (:3001, :3002, :3003, etc.)
|
|
313
|
+
4. Create `plugin.config.ts` with slots for sidebar navigation
|
|
314
|
+
5. Export `pluginConfig` and `App` from `plugin.ts`
|
|
315
|
+
|
|
316
|
+
### Slot Injection Pattern:
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
// In plugin.config.ts
|
|
320
|
+
export const pluginConfig: PluginConfig = {
|
|
321
|
+
manifest: {
|
|
322
|
+
name: '@lego/plugin-<name>',
|
|
323
|
+
version: '1.0.0',
|
|
324
|
+
displayName: '<Display Name>',
|
|
325
|
+
description: '<Description>',
|
|
326
|
+
},
|
|
327
|
+
enabled: true,
|
|
328
|
+
slots: [
|
|
329
|
+
{
|
|
330
|
+
slot: 'sidebar:nav',
|
|
331
|
+
component: () => import('./components/slots/SidebarWidget').then(m => m.default),
|
|
332
|
+
order: 100,
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
routes: [
|
|
336
|
+
{
|
|
337
|
+
path: '/<route>',
|
|
338
|
+
component: () => import('./pages/<Plugin>Page').then(m => m.default),
|
|
339
|
+
protected: true,
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
};
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 3. Development vs Production Mode
|
|
348
|
+
|
|
349
|
+
**CRITICAL DISTINCTION:**
|
|
350
|
+
|
|
351
|
+
| Mode | Plugin Entry | How it Works |
|
|
352
|
+
|------|--------------|--------------|
|
|
353
|
+
| **Development** | `'http://localhost:3001'` | Each plugin runs on separate dev server |
|
|
354
|
+
| **Production** | `() => import('@lego/plugin-dashboard')` | Plugins bundled into host dist |
|
|
355
|
+
|
|
356
|
+
**Development Workflow:**
|
|
357
|
+
```bash
|
|
358
|
+
# Terminal 1: Host
|
|
359
|
+
cd host && pnpm run dev # :8080
|
|
360
|
+
|
|
361
|
+
# Terminal 2: Plugin
|
|
362
|
+
cd packages/plugins/@lego/plugin-dashboard && pnpm run dev # :3001
|
|
363
|
+
|
|
364
|
+
# OR use root script:
|
|
365
|
+
pnpm run dev:all
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**Production Build:**
|
|
369
|
+
```bash
|
|
370
|
+
pnpm run build # Single bundle in host/dist/
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## 4. PocketBase Integration Patterns
|
|
376
|
+
|
|
377
|
+
### Multi-Tenancy API Rules Pattern:
|
|
378
|
+
|
|
379
|
+
All plugin collections MUST include:
|
|
380
|
+
```javascript
|
|
381
|
+
{
|
|
382
|
+
name: '<collection>',
|
|
383
|
+
fields: [
|
|
384
|
+
{ name: 'organizationId', type: 'relation', required: true },
|
|
385
|
+
{ name: 'ownerId', type: 'relation', required: true },
|
|
386
|
+
// ... your fields
|
|
387
|
+
],
|
|
388
|
+
// Multi-tenancy isolation
|
|
389
|
+
listRule: '@request.auth.id != "" && organizationId = @request.auth.membership.organizations',
|
|
390
|
+
viewRule: '@request.auth.id != "" && organizationId = @request.auth.membership.organizations',
|
|
391
|
+
createRule: '@request.auth.id != "" && organizationId = @request.auth.membership.organizations',
|
|
392
|
+
updateRule: '@request.auth.id != "" && organizationId = @request.auth.membership.organizations && ownerId = @request.auth.id',
|
|
393
|
+
deleteRule: '@request.auth.id != "" && organizationId = @request.auth.membership.organizations && ownerId = @request.auth.id',
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Data Fetching in Plugins:
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
export function useEntities() {
|
|
401
|
+
const pb = usePocketBase();
|
|
402
|
+
const kernelState = window.__LEGO_KERNEL_STATE__;
|
|
403
|
+
const orgId = kernelState?.useGlobalKernelState.getState().organization?.id;
|
|
404
|
+
|
|
405
|
+
return useQuery({
|
|
406
|
+
queryKey: ['entities', orgId],
|
|
407
|
+
queryFn: async () => {
|
|
408
|
+
if (!pb || !orgId) throw new Error('Not initialized');
|
|
409
|
+
|
|
410
|
+
const result = await pb.collection('entities').getList(1, 50, {
|
|
411
|
+
filter: `organizationId = "${orgId}"`,
|
|
412
|
+
sort: '-created',
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
return result.items;
|
|
416
|
+
},
|
|
417
|
+
enabled: !!pb && !!orgId,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## 5. Communication Between Apps
|
|
425
|
+
|
|
426
|
+
### Bus Events (Garfish Channel):
|
|
427
|
+
|
|
428
|
+
**Available Event Types:**
|
|
429
|
+
- `auth:login` - User logged in
|
|
430
|
+
- `auth:logout` - User logged out
|
|
431
|
+
- `toast:show` - Show toast notification
|
|
432
|
+
- `theme:change` - Theme changed
|
|
433
|
+
- `navigation:goto` - Navigate to path
|
|
434
|
+
|
|
435
|
+
**Emit from Plugin:**
|
|
436
|
+
```typescript
|
|
437
|
+
const bus = Garfish.channel;
|
|
438
|
+
bus.emit('toast:show', { message: 'Success!', variant: 'success' });
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**Listen in Plugin:**
|
|
442
|
+
```typescript
|
|
443
|
+
useEffect(() => {
|
|
444
|
+
const handler = (data) => console.log('Auth:', data);
|
|
445
|
+
Garfish.channel.on('auth:login', handler);
|
|
446
|
+
return () => Garfish.channel.off('auth:login', handler);
|
|
447
|
+
}, []);
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## 6. Component and Styling Guidelines
|
|
453
|
+
|
|
454
|
+
### UI Components:
|
|
455
|
+
- Use Shadcn UI components from `host/src/kernel/components/ui/`
|
|
456
|
+
- Import as `import { Button } from '@/components/ui/button'`
|
|
457
|
+
- For plugins, use `import { Button } from '@lego/kernel/components/ui/button'`
|
|
458
|
+
|
|
459
|
+
### Styling:
|
|
460
|
+
- Use Tailwind utility classes
|
|
461
|
+
- Use `cn()` helper for conditional classes
|
|
462
|
+
- Follow design tokens in `host/tailwind.config.ts`
|
|
463
|
+
- Dark mode: `dark:` prefix
|
|
464
|
+
|
|
465
|
+
### Icons:
|
|
466
|
+
- Use `lucide-react` for icons
|
|
467
|
+
- Import: `import { IconName } from 'lucide-react'`
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## 7. Error Handling and Edge Cases
|
|
472
|
+
|
|
473
|
+
### Plugin Loading Failures:
|
|
474
|
+
- Show user-friendly error message
|
|
475
|
+
- Log error to console with plugin name
|
|
476
|
+
- Allow plugin to be disabled via config
|
|
477
|
+
|
|
478
|
+
### Authentication Required:
|
|
479
|
+
- Check `isAuthenticated` from `useGlobalKernelState()`
|
|
480
|
+
- Redirect to `/login` if not authenticated
|
|
481
|
+
- Show loading state while checking auth
|
|
482
|
+
|
|
483
|
+
### PocketBase Errors:
|
|
484
|
+
- Handle 404 (not found) gracefully
|
|
485
|
+
- Handle 400 (validation) with field-level errors
|
|
486
|
+
- Handle 401/403 (auth/permissions) with redirect
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## 8. Testing Requirements
|
|
491
|
+
|
|
492
|
+
When implementing features, include:
|
|
493
|
+
|
|
494
|
+
**Unit Tests** (`*.test.ts`):
|
|
495
|
+
- Pure functions (utilities, validators)
|
|
496
|
+
- Custom hooks logic
|
|
497
|
+
- Component rendering
|
|
498
|
+
|
|
499
|
+
**Component Tests** (`*.component.test.tsx`):
|
|
500
|
+
- User interactions
|
|
501
|
+
- Form submissions
|
|
502
|
+
- Navigation
|
|
503
|
+
|
|
504
|
+
**E2E Tests** (`*.e2e.ts`):
|
|
505
|
+
- Critical user flows
|
|
506
|
+
- Cross-plugin interactions
|
|
507
|
+
- Auth flows
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
## 9. Common Tasks
|
|
512
|
+
|
|
513
|
+
### Create a New Plugin:
|
|
514
|
+
1. Read `docs/framework/setup/plugin-development.md`
|
|
515
|
+
2. Use existing plugins (Dashboard, Todo) as reference
|
|
516
|
+
3. Follow standard plugin structure
|
|
517
|
+
4. Register with host (`modern.runtime.ts`, `saas.config.ts`)
|
|
518
|
+
5. Assign unique dev port
|
|
519
|
+
6. Create PocketBase collections if needed
|
|
520
|
+
7. Test in both dev and production modes
|
|
521
|
+
|
|
522
|
+
### Add a New Collection to PocketBase:
|
|
523
|
+
1. Define in `pocketbase/migrations/` following `02-pocketbase-setup.md` pattern
|
|
524
|
+
2. Include `organizationId` and `ownerId` for multi-tenancy
|
|
525
|
+
3. Set API rules for organization isolation
|
|
526
|
+
4. Add index file with seed data if needed
|
|
527
|
+
|
|
528
|
+
### Add a New Slot Location:
|
|
529
|
+
1. Add enum to `host/src/kernel/plugins/types.ts`
|
|
530
|
+
2. Add `<Slot>` component in layout (`Sidebar.tsx`, `Topbar.tsx`)
|
|
531
|
+
3. Document in plugin development guide
|
|
532
|
+
|
|
533
|
+
### Debug Plugin Not Loading:
|
|
534
|
+
1. Check plugin dev server is running
|
|
535
|
+
2. Verify `activeWhen` matches route path
|
|
536
|
+
3. Check browser console for errors
|
|
537
|
+
4. Verify `deploy.microFrontend: true` in plugin config
|
|
538
|
+
5. Check `window.__LEGO_KERNEL_STATE__` exists
|
|
539
|
+
|
|
540
|
+
---
|
|
541
|
+
|
|
542
|
+
## 2. Learn and adapt when things fail
|
|
543
|
+
|
|
544
|
+
When you hit an error:
|
|
545
|
+
|
|
546
|
+
* Read the full error message and stack trace
|
|
547
|
+
* Check the implementation plan document for the section you're working on
|
|
548
|
+
* Verify all prerequisites are complete (each plan document lists them)
|
|
549
|
+
* Fix the code and retest
|
|
550
|
+
* Document what you learned in this workflow (Garfish quirks, PocketBase timing, slot injection gotchas)
|
|
551
|
+
* Example: You get a "module not found" error for a plugin, so you check that the dev server is running on the correct port, verify the entry URL in `modern.runtime.ts`, discover the activeWhen path needs to match exactly, fix it, verify it works, then note this in the workflow
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## 3. Keep workflows current
|
|
556
|
+
|
|
557
|
+
Workflows should evolve as you learn. When you find better methods, discover constraints, or encounter recurring issues, update this workflow. That said, don't create or overwrite workflows without asking unless I explicitly tell you to. These are your instructions and need to be preserved and refined, not tossed after one use.
|
|
558
|
+
|
|
559
|
+
**CRITICAL: Workflow File Synchronization**
|
|
560
|
+
|
|
561
|
+
This workflow file (`CLAUDE.md`) must stay **perfectly synchronized** with `.cursor/rules/rules.mdc`. When you update this file:
|
|
562
|
+
|
|
563
|
+
1. **ALWAYS update BOTH files** - `CLAUDE.md` AND `.cursor/rules/rules.mdc`
|
|
564
|
+
2. **Keep them identical** - Both files must contain the exact same content
|
|
565
|
+
3. **If updating CLAUDE.md** - Also update `.cursor/rules/rules.mdc` to match
|
|
566
|
+
4. **If updating rules.mdc** - Also update `CLAUDE.md` to match
|
|
567
|
+
|
|
568
|
+
This ensures both Cursor AI and Claude AI have the same instructions and improvements are shared across both AI assistants.
|
|
569
|
+
|
|
570
|
+
---
|
|
571
|
+
|
|
572
|
+
## The Self-Improvement Loop
|
|
573
|
+
|
|
574
|
+
Every failure is a chance to make the system stronger:
|
|
575
|
+
|
|
576
|
+
1. Identify what broke
|
|
577
|
+
2. Fix the bug
|
|
578
|
+
3. Verify the fix works
|
|
579
|
+
4. Update the workflow with the new approach - **MUST update BOTH `CLAUDE.md` AND `.cursor/rules/rules.mdc` to keep them synchronized**
|
|
580
|
+
5. Move on with a more robust system
|
|
581
|
+
|
|
582
|
+
This loop is how the framework improves over time.
|
|
583
|
+
|
|
584
|
+
**Remember:** When updating the workflow in step 4, you must update both workflow files to maintain synchronization between Cursor AI and Claude AI.
|
|
585
|
+
|
|
586
|
+
---
|
|
587
|
+
|
|
588
|
+
## Bottom Line
|
|
589
|
+
|
|
590
|
+
You sit between what I want (implementation plans in `docs/framework/plans/`) and what actually gets built (host kernel + plugins). Your job is to:
|
|
591
|
+
|
|
592
|
+
1. **Read the plan** - Each document in `docs/framework/plans/` contains exact file paths, code, and commands
|
|
593
|
+
2. **Follow the sequence** - Documents are numbered 01-12 for a reason
|
|
594
|
+
3. **Match existing patterns** - Look at Dashboard/Todo plugins for reference
|
|
595
|
+
4. **Use the slot system** - Plugins extend host via slot injection, not direct imports
|
|
596
|
+
5. **Respect dev vs prod** - Dev uses separate servers; prod bundles everything
|
|
597
|
+
6. **Recover from errors** - Fix, verify, document, continue
|
|
598
|
+
|
|
599
|
+
Stay pragmatic. Stay reliable. Keep learning.
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
## Quick Command Reference
|
|
604
|
+
|
|
605
|
+
```bash
|
|
606
|
+
# Development
|
|
607
|
+
pnpm run dev:all # Start host + all plugins
|
|
608
|
+
cd host && pnpm run dev # Start host only (:8080)
|
|
609
|
+
cd packages/plugins/@lego/plugin-<name> && pnpm run dev # Start plugin
|
|
610
|
+
|
|
611
|
+
# Building
|
|
612
|
+
pnpm run build # Build entire project
|
|
613
|
+
cd host && pnpm run build # Build host only
|
|
614
|
+
|
|
615
|
+
# PocketBase
|
|
616
|
+
cd pocketbase && ./pocketbase serve # Start PocketBase (:8090)
|
|
617
|
+
|
|
618
|
+
# Testing
|
|
619
|
+
pnpm run test # Run all tests
|
|
620
|
+
pnpm run test:e2e # Run E2E tests
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
---
|
|
624
|
+
|
|
625
|
+
## Documentation Reference
|
|
626
|
+
|
|
627
|
+
| Document | Purpose |
|
|
628
|
+
|----------|---------|
|
|
629
|
+
| `docs/framework/plans/00-index.md` | Implementation overview and order |
|
|
630
|
+
| `docs/framework/research/01-system-blueprint.md` | Architecture overview |
|
|
631
|
+
| `docs/framework/research/04-plugin-architecture.md` | Plugin patterns |
|
|
632
|
+
| `docs/framework/research/05-slot-injection-pattern.md` | Slot injection details |
|
|
633
|
+
| `docs/framework/setup/plugin-development.md` | Plugin creation guide |
|
|
634
|
+
| `docs/framework/setup/api-reference.md` | API documentation |
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Multi-stage build for Lego-One SaaS Boilerplate
|
|
2
|
+
|
|
3
|
+
# Stage 1: Build host application
|
|
4
|
+
FROM node:20-alpine AS host-builder
|
|
5
|
+
|
|
6
|
+
WORKDIR /app
|
|
7
|
+
|
|
8
|
+
# Install dependencies
|
|
9
|
+
COPY package.json pnpm-lock.yaml ./
|
|
10
|
+
RUN npm install -g pnpm@latest && pnpm install --frozen-lockfile
|
|
11
|
+
|
|
12
|
+
# Copy host application
|
|
13
|
+
COPY host ./host
|
|
14
|
+
COPY packages ./packages
|
|
15
|
+
|
|
16
|
+
# Build host
|
|
17
|
+
WORKDIR /app/host
|
|
18
|
+
RUN pnpm build
|
|
19
|
+
|
|
20
|
+
# Stage 2: Build plugins
|
|
21
|
+
FROM node:20-alpine AS plugin-builder
|
|
22
|
+
|
|
23
|
+
WORKDIR /app
|
|
24
|
+
|
|
25
|
+
# Install dependencies
|
|
26
|
+
COPY package.json pnpm-lock.yaml ./
|
|
27
|
+
RUN npm install -g pnpm@latest && pnpm install --frozen-lockfile
|
|
28
|
+
|
|
29
|
+
# Copy and build plugins
|
|
30
|
+
COPY packages ./packages
|
|
31
|
+
|
|
32
|
+
# Build dashboard plugin
|
|
33
|
+
WORKDIR /app/packages/plugins/@lego/plugin-dashboard
|
|
34
|
+
RUN pnpm build
|
|
35
|
+
|
|
36
|
+
# Build todo plugin
|
|
37
|
+
WORKDIR /app/packages/plugins/@lego/plugin-todo
|
|
38
|
+
RUN pnpm build
|
|
39
|
+
|
|
40
|
+
# Stage 3: Production image with Nginx
|
|
41
|
+
FROM nginx:alpine AS production
|
|
42
|
+
|
|
43
|
+
# Install PocketBase
|
|
44
|
+
RUN apk add --no-cache curl \
|
|
45
|
+
&& curl -L https://github.com/pocketbase/pocketbase/releases/download/v0.22.0/pocketbase_0.22.0_linux_amd64.zip -o /tmp/pb.zip \
|
|
46
|
+
&& unzip /tmp/pb.zip -d /usr/local/bin/ \
|
|
47
|
+
&& rm /tmp/pb.zip
|
|
48
|
+
|
|
49
|
+
# Copy built files
|
|
50
|
+
COPY --from=host-builder /app/host/dist /usr/share/nginx/html
|
|
51
|
+
COPY --from=plugin-builder /app/packages/plugins/@lego/plugin-dashboard/dist /usr/share/nginx/html/plugins/dashboard
|
|
52
|
+
COPY --from=plugin-builder /app/packages/plugins/@lego/plugin-todo/dist /usr/share/nginx/html/plugins/todo
|
|
53
|
+
|
|
54
|
+
# Copy nginx configuration
|
|
55
|
+
COPY nginx.conf /etc/nginx/nginx.conf
|
|
56
|
+
|
|
57
|
+
# Create PocketBase data directory
|
|
58
|
+
RUN mkdir -p /data/pb
|
|
59
|
+
|
|
60
|
+
# Expose ports
|
|
61
|
+
EXPOSE 80 8090
|
|
62
|
+
|
|
63
|
+
# Start script
|
|
64
|
+
COPY docker-entrypoint.sh /
|
|
65
|
+
RUN chmod +x /docker-entrypoint.sh
|
|
66
|
+
|
|
67
|
+
ENTRYPOINT ["/docker-entrypoint.sh"]
|