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,264 @@
|
|
|
1
|
+
# Phase 11: Testing - Complete
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Implemented a comprehensive testing setup for the Lego-One SaaS boilerplate with Vitest for unit testing and Playwright for E2E testing. Established test infrastructure, utilities, and baseline tests for key components.
|
|
6
|
+
|
|
7
|
+
## Test Statistics
|
|
8
|
+
|
|
9
|
+
- **Test Files:** 6
|
|
10
|
+
- **Total Tests:** 32
|
|
11
|
+
- **Passing:** 32 (100%)
|
|
12
|
+
- **Coverage:** 11.8% statements, 5.75% branches, 10% functions, 12.4% lines
|
|
13
|
+
|
|
14
|
+
## File Structure
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
host/
|
|
18
|
+
├── vitest.config.ts
|
|
19
|
+
├── playwright.config.ts
|
|
20
|
+
├── src/
|
|
21
|
+
│ ├── test/
|
|
22
|
+
│ │ ├── setup.ts
|
|
23
|
+
│ │ └── utils.tsx
|
|
24
|
+
│ ├── kernel/
|
|
25
|
+
│ │ └── __tests__/
|
|
26
|
+
│ │ ├── rbac-hooks.test.tsx
|
|
27
|
+
│ │ ├── rbac-utils.test.ts
|
|
28
|
+
│ │ └── lib-utils.test.ts
|
|
29
|
+
│ └── kernel/components/
|
|
30
|
+
│ └── __tests__/
|
|
31
|
+
│ ├── Button.test.tsx
|
|
32
|
+
│ ├── Input.test.tsx
|
|
33
|
+
│ └── Badge.test.tsx
|
|
34
|
+
└── e2e/
|
|
35
|
+
├── auth.spec.ts
|
|
36
|
+
└── layout.spec.ts
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Testing Stack
|
|
40
|
+
|
|
41
|
+
### Unit Testing
|
|
42
|
+
- **Vitest** v4.0.18 - Fast unit test framework
|
|
43
|
+
- **@testing-library/react** v16.3.2 - React component testing
|
|
44
|
+
- **@testing-library/user-event** v14.6.1 - User interaction simulation
|
|
45
|
+
- **@testing-library/jest-dom** v6.9.1 - Custom Jest matchers
|
|
46
|
+
- **@vitest/coverage-v8** v4.0.18 - Code coverage reporting
|
|
47
|
+
- **jsdom** v27.4.0 - DOM simulation
|
|
48
|
+
|
|
49
|
+
### E2E Testing
|
|
50
|
+
- **@playwright/test** v1.58.0 - Cross-browser E2E testing
|
|
51
|
+
- **Browsers:** Chromium, Firefox, WebKit
|
|
52
|
+
|
|
53
|
+
## Test Files Created
|
|
54
|
+
|
|
55
|
+
### Unit Tests
|
|
56
|
+
|
|
57
|
+
1. **rbac-hooks.test.tsx** (4 tests)
|
|
58
|
+
- useCurrentOrganization state management
|
|
59
|
+
- Query client clearing on organization change
|
|
60
|
+
- useUserPermissions authentication checks
|
|
61
|
+
|
|
62
|
+
2. **rbac-utils.test.ts** (4 tests)
|
|
63
|
+
- initializeFirstOrganization with existing org
|
|
64
|
+
- initializeFirstOrganization creates new org
|
|
65
|
+
- initializeFirstOrganization error handling
|
|
66
|
+
- initializeFirstOrganization edge cases (no email)
|
|
67
|
+
|
|
68
|
+
3. **lib-utils.test.ts** (7 tests)
|
|
69
|
+
- cn() class merging
|
|
70
|
+
- cn() with conditional classes
|
|
71
|
+
- cn() with undefined/null values
|
|
72
|
+
- cn() Tailwind conflict resolution
|
|
73
|
+
- cn() empty input handling
|
|
74
|
+
- cn() with arrays
|
|
75
|
+
- cn() with objects
|
|
76
|
+
|
|
77
|
+
4. **Button.test.tsx** (5 tests)
|
|
78
|
+
- Children rendering
|
|
79
|
+
- onClick handler
|
|
80
|
+
- Disabled state
|
|
81
|
+
- Variant classes (default, destructive, outline, ghost)
|
|
82
|
+
- Size classes (default, sm, lg, icon)
|
|
83
|
+
|
|
84
|
+
5. **Input.test.tsx** (6 tests)
|
|
85
|
+
- Element rendering
|
|
86
|
+
- Text input handling
|
|
87
|
+
- onChange callback
|
|
88
|
+
- Disabled state
|
|
89
|
+
- Custom className
|
|
90
|
+
- Standard input props
|
|
91
|
+
|
|
92
|
+
6. **Badge.test.tsx** (6 tests)
|
|
93
|
+
- Children rendering
|
|
94
|
+
- Default variant
|
|
95
|
+
- Secondary variant
|
|
96
|
+
- Destructive variant
|
|
97
|
+
- Outline variant
|
|
98
|
+
- Custom className
|
|
99
|
+
|
|
100
|
+
### E2E Tests
|
|
101
|
+
|
|
102
|
+
1. **auth.spec.ts** (4 tests)
|
|
103
|
+
- Sign in page visibility
|
|
104
|
+
- Sign in form elements
|
|
105
|
+
- Validation errors
|
|
106
|
+
- Password visibility toggle
|
|
107
|
+
|
|
108
|
+
2. **layout.spec.ts** (4 tests)
|
|
109
|
+
- Sidebar rendering
|
|
110
|
+
- Top bar rendering
|
|
111
|
+
- Navigation links
|
|
112
|
+
- Mobile responsiveness
|
|
113
|
+
|
|
114
|
+
## Configuration Files
|
|
115
|
+
|
|
116
|
+
### vitest.config.ts
|
|
117
|
+
```typescript
|
|
118
|
+
- jsdom environment
|
|
119
|
+
- Global test setup
|
|
120
|
+
- Coverage reporting with v8
|
|
121
|
+
- Path aliases (@ -> src)
|
|
122
|
+
- Custom test file pattern
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### playwright.config.ts
|
|
126
|
+
```typescript
|
|
127
|
+
- Multi-browser testing (Chromium, Firefox, WebKit)
|
|
128
|
+
- Automatic web server startup
|
|
129
|
+
- HTML reporter
|
|
130
|
+
- Trace on retry
|
|
131
|
+
- Reuse existing server in dev
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### test/setup.ts
|
|
135
|
+
```typescript
|
|
136
|
+
- @testing-library/jest-dom setup
|
|
137
|
+
- Auto cleanup after each test
|
|
138
|
+
- PocketBase mocking
|
|
139
|
+
- Window bridge mocking (__LEGO_KERNEL_STATE__, __LEGO_CHANNEL_BUS__)
|
|
140
|
+
- IntersectionObserver mocking
|
|
141
|
+
- ResizeObserver mocking
|
|
142
|
+
- matchMedia mocking
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### test/utils.tsx
|
|
146
|
+
```typescript
|
|
147
|
+
- Custom render() with QueryClient and Router providers
|
|
148
|
+
- Mock data generators (mockUser, mockOrganization, mockAuthState)
|
|
149
|
+
- setupMockState() and clearMockState() helpers
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## NPM Scripts
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"test": "vitest",
|
|
157
|
+
"test:ui": "vitest --ui",
|
|
158
|
+
"test:coverage": "vitest --coverage",
|
|
159
|
+
"test:e2e": "playwright test",
|
|
160
|
+
"test:e2e:ui": "playwright test --ui",
|
|
161
|
+
"test:e2e:debug": "playwright test --debug"
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Coverage Breakdown
|
|
166
|
+
|
|
167
|
+
### 100% Coverage
|
|
168
|
+
- `components/ui/badge.tsx`
|
|
169
|
+
- `components/ui/button.tsx`
|
|
170
|
+
- `components/ui/input.tsx`
|
|
171
|
+
- `rbac/utils.ts`
|
|
172
|
+
|
|
173
|
+
### Partial Coverage
|
|
174
|
+
- `rbac/hooks.ts` - 9.3% (only organization and permissions hooks tested)
|
|
175
|
+
- `lib/utils.ts` - 6.25% (only cn() function tested)
|
|
176
|
+
- `channels/ChannelBus.ts` - 7% (basic mocking in setup)
|
|
177
|
+
- `shared-state/store.ts` - 22.72% (Zustand store partially tested)
|
|
178
|
+
|
|
179
|
+
### No Coverage Yet
|
|
180
|
+
- `rbac/service.ts` - Complex PocketBase service layer
|
|
181
|
+
- `channels/plugin-hooks.ts` - Plugin channel hooks
|
|
182
|
+
- `auth/` modules - Authentication hooks and services
|
|
183
|
+
- `providers/` - React context providers
|
|
184
|
+
- `plugins/` - Plugin system components
|
|
185
|
+
|
|
186
|
+
## Testing Patterns
|
|
187
|
+
|
|
188
|
+
### Hook Testing
|
|
189
|
+
```typescript
|
|
190
|
+
- Use renderHook from @testing-library/react
|
|
191
|
+
- Mock PocketBase with vi.mock
|
|
192
|
+
- Create QueryClient for each test
|
|
193
|
+
- Test both success and error states
|
|
194
|
+
- Verify query invalidation
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Component Testing
|
|
198
|
+
```typescript
|
|
199
|
+
- Use render() from @testing-library/react
|
|
200
|
+
- Use userEvent for realistic interactions
|
|
201
|
+
- Test props (variant, size, disabled, etc.)
|
|
202
|
+
- Verify className application
|
|
203
|
+
- Test event handlers
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### E2E Testing
|
|
207
|
+
```typescript
|
|
208
|
+
- Use page.goto() for navigation
|
|
209
|
+
- Use locators for element selection
|
|
210
|
+
- Test user flows (sign in, navigation)
|
|
211
|
+
- Test responsive behavior
|
|
212
|
+
- Use filters for dynamic elements
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Next Steps for Coverage
|
|
216
|
+
|
|
217
|
+
### High Priority
|
|
218
|
+
1. **RBAC Service** - Test PocketBase CRUD operations
|
|
219
|
+
2. **Auth Hooks** - Test authentication flow hooks
|
|
220
|
+
3. **Plugin System** - Test plugin loader and slot injection
|
|
221
|
+
|
|
222
|
+
### Medium Priority
|
|
223
|
+
1. **Channel Hooks** - Test channel subscription/messaging
|
|
224
|
+
2. **Providers** - Test context provider behavior
|
|
225
|
+
3. **Layout Components** - Test Sidebar, Topbar, main layout
|
|
226
|
+
|
|
227
|
+
### Lower Priority
|
|
228
|
+
1. **UI Components** - Add tests for remaining components
|
|
229
|
+
2. **Pages** - Test page-level components and routing
|
|
230
|
+
|
|
231
|
+
## Notes
|
|
232
|
+
|
|
233
|
+
- Tests are fast (1.26s for 32 tests)
|
|
234
|
+
- UI component tests are slower due to React rendering
|
|
235
|
+
- Coverage baseline established for future development
|
|
236
|
+
- E2E tests require dev server to run
|
|
237
|
+
- Mock setup handles PocketBase and window bridge
|
|
238
|
+
- Tests use Vitest's watch mode for development
|
|
239
|
+
- Coverage report generated in `coverage/index.html`
|
|
240
|
+
|
|
241
|
+
## Running Tests
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Unit tests (watch mode)
|
|
245
|
+
pnpm test
|
|
246
|
+
|
|
247
|
+
# Unit tests (single run)
|
|
248
|
+
pnpm test --run
|
|
249
|
+
|
|
250
|
+
# Test UI
|
|
251
|
+
pnpm test:ui
|
|
252
|
+
|
|
253
|
+
# Coverage
|
|
254
|
+
pnpm test:coverage
|
|
255
|
+
|
|
256
|
+
# E2E tests (requires dev server)
|
|
257
|
+
pnpm test:e2e
|
|
258
|
+
|
|
259
|
+
# E2E UI
|
|
260
|
+
pnpm test:e2e:ui
|
|
261
|
+
|
|
262
|
+
# E2E debug
|
|
263
|
+
pnpm test:e2e:debug
|
|
264
|
+
```
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# Phase 12: Deployment - Complete
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Implemented comprehensive deployment configuration for the Lego-One SaaS boilerplate, including Docker containerization, production build configuration, and deployment automation.
|
|
6
|
+
|
|
7
|
+
## Build Statistics
|
|
8
|
+
|
|
9
|
+
- **Host Build Size:** 786.5 kB (244.5 kB gzipped)
|
|
10
|
+
- **Build Time:** 35.6s
|
|
11
|
+
- **Status:** ✅ Successful
|
|
12
|
+
|
|
13
|
+
## File Structure
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
lego-one/
|
|
17
|
+
├── .env.example # Environment variables template
|
|
18
|
+
├── .dockerignore # Docker ignore rules
|
|
19
|
+
├── Dockerfile # Multi-stage container build
|
|
20
|
+
├── docker-compose.yml # Local development stack
|
|
21
|
+
├── docker-entrypoint.sh # Container startup script
|
|
22
|
+
├── nginx.conf # Nginx configuration
|
|
23
|
+
└── scripts/
|
|
24
|
+
└── deploy.sh # Deployment automation script
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Docker Configuration
|
|
28
|
+
|
|
29
|
+
### Multi-Stage Build
|
|
30
|
+
|
|
31
|
+
**Stage 1: Host Builder**
|
|
32
|
+
- Base: `node:20-alpine`
|
|
33
|
+
- Installs dependencies with pnpm
|
|
34
|
+
- Builds host application
|
|
35
|
+
|
|
36
|
+
**Stage 2: Plugin Builder**
|
|
37
|
+
- Builds dashboard plugin
|
|
38
|
+
- Builds todo plugin
|
|
39
|
+
|
|
40
|
+
**Stage 3: Production**
|
|
41
|
+
- Base: `nginx:alpine`
|
|
42
|
+
- Installs PocketBase v0.22.0
|
|
43
|
+
- Serves static files with nginx
|
|
44
|
+
- Runs PocketBase on port 8090
|
|
45
|
+
|
|
46
|
+
### Exposed Ports
|
|
47
|
+
- **80** - Nginx (application)
|
|
48
|
+
- **8090** - PocketBase (API)
|
|
49
|
+
|
|
50
|
+
### Volumes
|
|
51
|
+
- `pb_data:/data/pb` - PocketBase SQLite data persistence
|
|
52
|
+
|
|
53
|
+
## Nginx Configuration
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
- **Static file serving** with gzip compression
|
|
57
|
+
- **SPA routing** via `try_files`
|
|
58
|
+
- **API proxy** to PocketBase at `/api/`
|
|
59
|
+
- **Cache headers** for static assets (1 year)
|
|
60
|
+
- **Security headers** (X-Frame-Options, X-Content-Type-Options, X-XSS-Protection)
|
|
61
|
+
|
|
62
|
+
### Compression
|
|
63
|
+
- Text files (text/plain, text/css, text/xml, application/json)
|
|
64
|
+
- JavaScript files
|
|
65
|
+
- Gzip enabled
|
|
66
|
+
|
|
67
|
+
### Caching
|
|
68
|
+
- Static assets: 1 year, immutable
|
|
69
|
+
- HTML pages: No cache
|
|
70
|
+
|
|
71
|
+
## Environment Variables
|
|
72
|
+
|
|
73
|
+
### Required
|
|
74
|
+
```bash
|
|
75
|
+
VITE_POCKETBASE_URL=http://127.0.0.1:8090
|
|
76
|
+
VITE_APP_NAME=Lego-One
|
|
77
|
+
VITE_APP_URL=http://localhost:8080
|
|
78
|
+
VITE_PLUGINS_ENABLED=true
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Optional
|
|
82
|
+
```bash
|
|
83
|
+
VITE_ENABLE_DEVTOOLS=false
|
|
84
|
+
VITE_ENABLE_ANALYTICS=false
|
|
85
|
+
VITE_SENTRY_DSN=<sentry-dsn>
|
|
86
|
+
VITE_GA_ID=<google-analytics-id>
|
|
87
|
+
VITE_STRIPE_PUBLIC_KEY=<stripe-key>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Deployment Scripts
|
|
91
|
+
|
|
92
|
+
### deploy.sh
|
|
93
|
+
```bash
|
|
94
|
+
./scripts/deploy.sh [environment]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Features:**
|
|
98
|
+
- Environment-specific loading
|
|
99
|
+
- Docker image building
|
|
100
|
+
- Container orchestration
|
|
101
|
+
- Health checks
|
|
102
|
+
- Rolling updates
|
|
103
|
+
|
|
104
|
+
**Usage:**
|
|
105
|
+
```bash
|
|
106
|
+
./scripts/deploy.sh production
|
|
107
|
+
./scripts/deploy.sh staging
|
|
108
|
+
./scripts/deploy.sh development
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Docker Compose
|
|
112
|
+
|
|
113
|
+
### Services
|
|
114
|
+
- **app** - Main application with embedded PocketBase
|
|
115
|
+
|
|
116
|
+
### Optional Services (commented out)
|
|
117
|
+
- **postgres** - PostgreSQL database for production
|
|
118
|
+
- **redis** - Redis for caching/sessions
|
|
119
|
+
|
|
120
|
+
### Health Check
|
|
121
|
+
```yaml
|
|
122
|
+
test: ["CMD", "wget", "-q", "--spider", "http://localhost/80"]
|
|
123
|
+
interval: 30s
|
|
124
|
+
timeout: 10s
|
|
125
|
+
retries: 3
|
|
126
|
+
start_period: 40s
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Container Entrypoint
|
|
130
|
+
|
|
131
|
+
The `docker-entrypoint.sh` script:
|
|
132
|
+
1. Starts PocketBase in background
|
|
133
|
+
2. Waits for PocketBase to initialize (5s)
|
|
134
|
+
3. Verifies PocketBase is running
|
|
135
|
+
4. Starts nginx in foreground
|
|
136
|
+
|
|
137
|
+
## TypeScript Configuration Updates
|
|
138
|
+
|
|
139
|
+
### Excluded from Production Build
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"exclude": [
|
|
143
|
+
"node_modules",
|
|
144
|
+
"dist",
|
|
145
|
+
"**/__tests__",
|
|
146
|
+
"**/*.test.ts",
|
|
147
|
+
"**/*.test.tsx",
|
|
148
|
+
"**/*.spec.ts",
|
|
149
|
+
"**/*.spec.tsx",
|
|
150
|
+
"src/test"
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Docker Ignore Patterns
|
|
156
|
+
|
|
157
|
+
Excluded from Docker build context:
|
|
158
|
+
- Dependencies (node_modules)
|
|
159
|
+
- Build outputs (dist, build, .next)
|
|
160
|
+
- Environment files (.env, .env.local)
|
|
161
|
+
- Test files and coverage
|
|
162
|
+
- IDE files (.vscode, .idea)
|
|
163
|
+
- Documentation
|
|
164
|
+
- CI/CD configs
|
|
165
|
+
|
|
166
|
+
## Deployment Commands
|
|
167
|
+
|
|
168
|
+
### Local Development
|
|
169
|
+
```bash
|
|
170
|
+
# Start containers
|
|
171
|
+
docker-compose up -d
|
|
172
|
+
|
|
173
|
+
# View logs
|
|
174
|
+
docker-compose logs -f
|
|
175
|
+
|
|
176
|
+
# Stop containers
|
|
177
|
+
docker-compose down
|
|
178
|
+
|
|
179
|
+
# Rebuild containers
|
|
180
|
+
docker-compose up -d --build
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Production Deployment
|
|
184
|
+
```bash
|
|
185
|
+
# Build and deploy
|
|
186
|
+
./scripts/deploy.sh production
|
|
187
|
+
|
|
188
|
+
# Manual Docker build
|
|
189
|
+
docker build -t lego-one:latest .
|
|
190
|
+
docker run -p 80:80 -p 8090:8090 -v pb_data:/data/pb lego-one:latest
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Container Management
|
|
194
|
+
```bash
|
|
195
|
+
# View running containers
|
|
196
|
+
docker ps
|
|
197
|
+
|
|
198
|
+
# View container logs
|
|
199
|
+
docker logs <container-id>
|
|
200
|
+
|
|
201
|
+
# Execute command in container
|
|
202
|
+
docker exec -it <container-id> sh
|
|
203
|
+
|
|
204
|
+
# Stop container
|
|
205
|
+
docker stop <container-id>
|
|
206
|
+
|
|
207
|
+
# Remove container
|
|
208
|
+
docker rm <container-id>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## PocketBase Data Persistence
|
|
212
|
+
|
|
213
|
+
### SQLite Location
|
|
214
|
+
- Container: `/data/pb/pb_data.db`
|
|
215
|
+
- Host volume: `pb_data` named volume
|
|
216
|
+
|
|
217
|
+
### Backup Commands
|
|
218
|
+
```bash
|
|
219
|
+
# Backup data
|
|
220
|
+
docker cp <container-id>:/data/pb ./backup/
|
|
221
|
+
|
|
222
|
+
# Restore data
|
|
223
|
+
docker cp ./backup/ <container-id>:/data/pb/
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Production Considerations
|
|
227
|
+
|
|
228
|
+
### Security
|
|
229
|
+
1. **Environment Variables** - Never commit .env files
|
|
230
|
+
2. **Database** - Use PostgreSQL in production (not SQLite)
|
|
231
|
+
3. **HTTPS** - Use reverse proxy (nginx, Traefik) with SSL
|
|
232
|
+
4. **Firewall** - Only expose necessary ports
|
|
233
|
+
5. **Secrets** - Use secret management (Docker secrets, AWS Secrets Manager)
|
|
234
|
+
|
|
235
|
+
### Scaling
|
|
236
|
+
1. **Horizontal Scaling** - Deploy multiple app instances behind load balancer
|
|
237
|
+
2. **Database** - External PostgreSQL instance
|
|
238
|
+
3. **Session Storage** - External Redis for sessions
|
|
239
|
+
4. **File Storage** - S3 or compatible for user uploads
|
|
240
|
+
5. **CDN** - CloudFront/Cloudflare for static assets
|
|
241
|
+
|
|
242
|
+
### Monitoring
|
|
243
|
+
1. **Logging** - Centralized logging (ELK, Loki)
|
|
244
|
+
2. **Metrics** - Prometheus + Grafana
|
|
245
|
+
3. **APM** - Sentry, DataDog, or New Relic
|
|
246
|
+
4. **Health Checks** - `/health` endpoint
|
|
247
|
+
5. **Uptime** - UptimeRobot, Pingdom
|
|
248
|
+
|
|
249
|
+
## Deployment Platforms
|
|
250
|
+
|
|
251
|
+
### Supported
|
|
252
|
+
- **Docker** - Self-hosted Docker/Docker Compose
|
|
253
|
+
- **Kubernetes** - Helm charts (to be created)
|
|
254
|
+
- **Cloud Providers** - AWS, GCP, Azure (via container registries)
|
|
255
|
+
|
|
256
|
+
### Recommended
|
|
257
|
+
- **Vercel** - For frontend (host + plugins)
|
|
258
|
+
- **Railway** - For PocketBase + PostgreSQL
|
|
259
|
+
- **Render** - Full-stack deployment
|
|
260
|
+
- **DigitalOcean App Platform** - Simple PaaS
|
|
261
|
+
|
|
262
|
+
## Build Optimization
|
|
263
|
+
|
|
264
|
+
### Current Size Breakdown
|
|
265
|
+
- `lib-polyfill`: 246.2 kB (83.8 kB gzipped)
|
|
266
|
+
- `lib-react`: 140.0 kB (45.2 kB gzipped)
|
|
267
|
+
- Chunk `381`: 314.4 kB (93.8 kB gzipped)
|
|
268
|
+
- `main.js`: 30.2 kB (9.7 kB gzipped)
|
|
269
|
+
- `main.css`: 44.4 kB (7.2 kB gzipped)
|
|
270
|
+
|
|
271
|
+
### Future Optimizations
|
|
272
|
+
1. Code splitting by route
|
|
273
|
+
2. Dynamic imports for plugins
|
|
274
|
+
3. Tree shaking for unused dependencies
|
|
275
|
+
4. Bundle analysis (webpack-bundle-analyzer)
|
|
276
|
+
5. CSS purging (unused Tailwind classes)
|
|
277
|
+
|
|
278
|
+
## Next Steps
|
|
279
|
+
|
|
280
|
+
1. **CI/CD Pipeline** - GitHub Actions workflow
|
|
281
|
+
2. **Kubernetes** - Helm charts for K8s deployment
|
|
282
|
+
3. **Monitoring** - Prometheus + Grafana setup
|
|
283
|
+
4. **Backup Scripts** - Automated PocketBase backups
|
|
284
|
+
5. **SSL/TLS** - Let's Encrypt integration
|
|
285
|
+
6. **CDN** - CloudFront setup for static assets
|
|
286
|
+
|
|
287
|
+
## Notes
|
|
288
|
+
|
|
289
|
+
- Multi-stage Docker build reduces final image size
|
|
290
|
+
- Nginx serves static files efficiently
|
|
291
|
+
- PocketBase embedded in same container (simplifies deployment)
|
|
292
|
+
- For production, consider separate containers for app and database
|
|
293
|
+
- Docker volumes ensure data persistence across container restarts
|
|
294
|
+
- Health checks ensure container is running properly
|