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