@cubocicloide/stack-react-fastapi 13.0.6
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/LICENSE +33 -0
- package/README.md +66 -0
- package/dist/commands/lint/checks/BE/001.d.ts +6 -0
- package/dist/commands/lint/checks/BE/001.js +95 -0
- package/dist/commands/lint/checks/BE/001.js.map +1 -0
- package/dist/commands/lint/checks/BE/002.d.ts +6 -0
- package/dist/commands/lint/checks/BE/002.js +30 -0
- package/dist/commands/lint/checks/BE/002.js.map +1 -0
- package/dist/commands/lint/checks/BE/003.d.ts +11 -0
- package/dist/commands/lint/checks/BE/003.js +46 -0
- package/dist/commands/lint/checks/BE/003.js.map +1 -0
- package/dist/commands/lint/checks/BE/004.d.ts +6 -0
- package/dist/commands/lint/checks/BE/004.js +27 -0
- package/dist/commands/lint/checks/BE/004.js.map +1 -0
- package/dist/commands/lint/checks/BE/005.d.ts +6 -0
- package/dist/commands/lint/checks/BE/005.js +107 -0
- package/dist/commands/lint/checks/BE/005.js.map +1 -0
- package/dist/commands/lint/checks/BE/006.d.ts +6 -0
- package/dist/commands/lint/checks/BE/006.js +27 -0
- package/dist/commands/lint/checks/BE/006.js.map +1 -0
- package/dist/commands/lint/checks/BE/007.d.ts +31 -0
- package/dist/commands/lint/checks/BE/007.js +109 -0
- package/dist/commands/lint/checks/BE/007.js.map +1 -0
- package/dist/commands/lint/checks/BE/008.d.ts +12 -0
- package/dist/commands/lint/checks/BE/008.js +57 -0
- package/dist/commands/lint/checks/BE/008.js.map +1 -0
- package/dist/commands/lint/checks/BE/009.d.ts +12 -0
- package/dist/commands/lint/checks/BE/009.js +104 -0
- package/dist/commands/lint/checks/BE/009.js.map +1 -0
- package/dist/commands/lint/checks/BE/010.d.ts +12 -0
- package/dist/commands/lint/checks/BE/010.js +54 -0
- package/dist/commands/lint/checks/BE/010.js.map +1 -0
- package/dist/commands/lint/checks/BE/011.d.ts +16 -0
- package/dist/commands/lint/checks/BE/011.js +46 -0
- package/dist/commands/lint/checks/BE/011.js.map +1 -0
- package/dist/commands/lint/checks/E2E/001.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/001.js +35 -0
- package/dist/commands/lint/checks/E2E/001.js.map +1 -0
- package/dist/commands/lint/checks/E2E/002.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/002.js +37 -0
- package/dist/commands/lint/checks/E2E/002.js.map +1 -0
- package/dist/commands/lint/checks/E2E/003.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/003.js +42 -0
- package/dist/commands/lint/checks/E2E/003.js.map +1 -0
- package/dist/commands/lint/checks/E2E/004.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/004.js +37 -0
- package/dist/commands/lint/checks/E2E/004.js.map +1 -0
- package/dist/commands/lint/checks/E2E/005.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/005.js +47 -0
- package/dist/commands/lint/checks/E2E/005.js.map +1 -0
- package/dist/commands/lint/checks/E2E/006.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/006.js +28 -0
- package/dist/commands/lint/checks/E2E/006.js.map +1 -0
- package/dist/commands/lint/checks/E2E/007.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/007.js +47 -0
- package/dist/commands/lint/checks/E2E/007.js.map +1 -0
- package/dist/commands/lint/checks/FE/001.d.ts +6 -0
- package/dist/commands/lint/checks/FE/001.js +56 -0
- package/dist/commands/lint/checks/FE/001.js.map +1 -0
- package/dist/commands/lint/checks/FE/002.d.ts +6 -0
- package/dist/commands/lint/checks/FE/002.js +80 -0
- package/dist/commands/lint/checks/FE/002.js.map +1 -0
- package/dist/commands/lint/checks/FE/003.d.ts +6 -0
- package/dist/commands/lint/checks/FE/003.js +65 -0
- package/dist/commands/lint/checks/FE/003.js.map +1 -0
- package/dist/commands/lint/checks/FE/004.d.ts +6 -0
- package/dist/commands/lint/checks/FE/004.js +72 -0
- package/dist/commands/lint/checks/FE/004.js.map +1 -0
- package/dist/commands/lint/checks/FE/005.d.ts +6 -0
- package/dist/commands/lint/checks/FE/005.js +103 -0
- package/dist/commands/lint/checks/FE/005.js.map +1 -0
- package/dist/commands/lint/checks/FE/006.d.ts +6 -0
- package/dist/commands/lint/checks/FE/006.js +102 -0
- package/dist/commands/lint/checks/FE/006.js.map +1 -0
- package/dist/commands/lint/checks/FE/007.d.ts +6 -0
- package/dist/commands/lint/checks/FE/007.js +60 -0
- package/dist/commands/lint/checks/FE/007.js.map +1 -0
- package/dist/commands/lint/checks/FE/008.d.ts +6 -0
- package/dist/commands/lint/checks/FE/008.js +115 -0
- package/dist/commands/lint/checks/FE/008.js.map +1 -0
- package/dist/commands/lint/checks/FE/009.d.ts +6 -0
- package/dist/commands/lint/checks/FE/009.js +83 -0
- package/dist/commands/lint/checks/FE/009.js.map +1 -0
- package/dist/commands/lint/checks/FE/010.d.ts +6 -0
- package/dist/commands/lint/checks/FE/010.js +105 -0
- package/dist/commands/lint/checks/FE/010.js.map +1 -0
- package/dist/commands/lint/checks/FE/011.d.ts +6 -0
- package/dist/commands/lint/checks/FE/011.js +43 -0
- package/dist/commands/lint/checks/FE/011.js.map +1 -0
- package/dist/commands/lint/checks/FE/012.d.ts +6 -0
- package/dist/commands/lint/checks/FE/012.js +150 -0
- package/dist/commands/lint/checks/FE/012.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3491 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +7 -0
- package/package.json +43 -0
- package/templates/aws-eks/backend/Dockerfile.prod.hbs +22 -0
- package/templates/aws-eks/docs/docs/deploy.md.hbs +159 -0
- package/templates/aws-eks/frontend/Dockerfile.prod +28 -0
- package/templates/aws-eks/frontend/nginx.conf +19 -0
- package/templates/aws-eks/iac/README.md.hbs +311 -0
- package/templates/aws-eks/iac/_gitignore +24 -0
- package/templates/aws-eks/iac/helm/app/.helmignore +7 -0
- package/templates/aws-eks/iac/helm/app/Chart.yaml.hbs +6 -0
- package/templates/aws-eks/iac/helm/app/templates/NOTES.txt +23 -0
- package/templates/aws-eks/iac/helm/app/templates/backend-deployment.yaml +44 -0
- package/templates/aws-eks/iac/helm/app/templates/backend-service.yaml +16 -0
- package/templates/aws-eks/iac/helm/app/templates/celery-beat-deployment.yaml +34 -0
- package/templates/aws-eks/iac/helm/app/templates/celery-worker-deployment.yaml +31 -0
- package/templates/aws-eks/iac/helm/app/templates/configmap.yaml +15 -0
- package/templates/aws-eks/iac/helm/app/templates/flower-deployment.yaml +28 -0
- package/templates/aws-eks/iac/helm/app/templates/flower-service.yaml +19 -0
- package/templates/aws-eks/iac/helm/app/templates/frontend-deployment.yaml +34 -0
- package/templates/aws-eks/iac/helm/app/templates/frontend-service.yaml +16 -0
- package/templates/aws-eks/iac/helm/app/templates/helpers.tpl +90 -0
- package/templates/aws-eks/iac/helm/app/templates/hpa.yaml +23 -0
- package/templates/aws-eks/iac/helm/app/templates/ingress.yaml +30 -0
- package/templates/aws-eks/iac/helm/app/templates/migration-job.yaml +38 -0
- package/templates/aws-eks/iac/helm/app/templates/redis-deployment.yaml +33 -0
- package/templates/aws-eks/iac/helm/app/templates/redis-service.yaml +18 -0
- package/templates/aws-eks/iac/helm/app/templates/secret.yaml +17 -0
- package/templates/aws-eks/iac/helm/app/templates/serviceaccount.yaml +12 -0
- package/templates/aws-eks/iac/helm/app/values-dev.yaml.hbs +35 -0
- package/templates/aws-eks/iac/helm/app/values.yaml.hbs +130 -0
- package/templates/aws-eks/iac/runner/Dockerfile +53 -0
- package/templates/aws-eks/iac/terraform/bootstrap/main.tf.hbs +101 -0
- package/templates/aws-eks/iac/terraform/bootstrap/outputs.tf +19 -0
- package/templates/aws-eks/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-eks/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-eks/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
- package/templates/aws-eks/iac/terraform/main.tf.hbs +305 -0
- package/templates/aws-eks/iac/terraform/outputs.tf.hbs +52 -0
- package/templates/aws-eks/iac/terraform/providers.tf +47 -0
- package/templates/aws-eks/iac/terraform/variables.tf.hbs +181 -0
- package/templates/aws-eks/iac/terraform/versions.tf +27 -0
- package/templates/base/.claude/agents/issue-fixer.md +190 -0
- package/templates/base/.claude/agents/security-fixer.md +250 -0
- package/templates/base/.claude/rules/BE/001.md +25 -0
- package/templates/base/.claude/rules/BE/002.md +15 -0
- package/templates/base/.claude/rules/BE/003.md +18 -0
- package/templates/base/.claude/rules/BE/004.md +14 -0
- package/templates/base/.claude/rules/BE/005.md +15 -0
- package/templates/base/.claude/rules/BE/006.md +17 -0
- package/templates/base/.claude/rules/BE/007.md +21 -0
- package/templates/base/.claude/rules/BE/008.md +19 -0
- package/templates/base/.claude/rules/BE/009.md +27 -0
- package/templates/base/.claude/rules/BE/010.md +16 -0
- package/templates/base/.claude/rules/BE/011.md +15 -0
- package/templates/base/.claude/rules/E2E/001.md +13 -0
- package/templates/base/.claude/rules/E2E/002.md +14 -0
- package/templates/base/.claude/rules/E2E/003.md +10 -0
- package/templates/base/.claude/rules/E2E/004.md +23 -0
- package/templates/base/.claude/rules/E2E/005.md +15 -0
- package/templates/base/.claude/rules/E2E/006.md +13 -0
- package/templates/base/.claude/rules/E2E/007.md +18 -0
- package/templates/base/.claude/rules/FE/001.md +22 -0
- package/templates/base/.claude/rules/FE/002.md +39 -0
- package/templates/base/.claude/rules/FE/003.md +19 -0
- package/templates/base/.claude/rules/FE/004.md +21 -0
- package/templates/base/.claude/rules/FE/005.md +33 -0
- package/templates/base/.claude/rules/FE/006.md +24 -0
- package/templates/base/.claude/rules/FE/007.md +19 -0
- package/templates/base/.claude/rules/FE/008.md +26 -0
- package/templates/base/.claude/rules/FE/009.md +30 -0
- package/templates/base/.claude/rules/FE/010.md +25 -0
- package/templates/base/.claude/rules/FE/011.md +22 -0
- package/templates/base/.claude/rules/FE/012.md +32 -0
- package/templates/base/.claude/settings.json +53 -0
- package/templates/base/.claude/skills/clean-branches/SKILL.md +100 -0
- package/templates/base/.claude/skills/create/SKILL.md +47 -0
- package/templates/base/.claude/skills/create-jira-issue/SKILL.md +174 -0
- package/templates/base/.claude/skills/create-page/SKILL.md +195 -0
- package/templates/base/.claude/skills/create-route/SKILL.md +199 -0
- package/templates/base/.claude/skills/draft-email/SKILL.md +104 -0
- package/templates/base/.claude/skills/fix-issues/SKILL.md +238 -0
- package/templates/base/.claude/skills/security-scan/SKILL.md +297 -0
- package/templates/base/.claude/skills/verify-security-fixes/SKILL.md +180 -0
- package/templates/base/.dude/commands/README.md +85 -0
- package/templates/base/.dude/commands/hello.ts +34 -0
- package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
- package/templates/base/.dude/lint/checks/README.md +69 -0
- package/templates/base/.vscode/tasks.json +44 -0
- package/templates/base/.worktreeinclude +2 -0
- package/templates/base/CLAUDE.md.hbs +364 -0
- package/templates/base/README.md.hbs +187 -0
- package/templates/base/_env.example.hbs +29 -0
- package/templates/base/_env.hbs +25 -0
- package/templates/base/_gitignore +31 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/backend/Dockerfile.hbs +22 -0
- package/templates/base/backend/README.md.hbs +74 -0
- package/templates/base/backend/_dockerignore +11 -0
- package/templates/base/backend/app/__init__.py +1 -0
- package/templates/base/backend/app/core/__init__.py +0 -0
- package/templates/base/backend/app/core/config.py.hbs +23 -0
- package/templates/base/backend/app/fixtures/__init__.py +0 -0
- package/templates/base/backend/app/main.py.hbs +41 -0
- package/templates/base/backend/app/management/__init__.py +0 -0
- package/templates/base/backend/app/models/__init__.py +0 -0
- package/templates/base/backend/app/queries/__init__.py +0 -0
- package/templates/base/backend/app/routers/__init__.py +0 -0
- package/templates/base/backend/app/routers/health.py +13 -0
- package/templates/base/backend/app/schemas/__init__.py +0 -0
- package/templates/base/backend/app/schemas/health.py +7 -0
- package/templates/base/backend/app/tasks/__init__.py +1 -0
- package/templates/base/backend/app/tests/__init__.py +0 -0
- package/templates/base/backend/app/tests/conftest.py +13 -0
- package/templates/base/backend/app/tests/models/__init__.py +0 -0
- package/templates/base/backend/app/tests/queries/__init__.py +0 -0
- package/templates/base/backend/app/tests/routers/__init__.py +0 -0
- package/templates/base/backend/app/tests/routers/test_health.py +10 -0
- package/templates/base/backend/app/tests/tasks/__init__.py +1 -0
- package/templates/base/backend/app/tests/utils/__init__.py +0 -0
- package/templates/base/backend/app/utils/__init__.py +0 -0
- package/templates/base/backend/pyproject.toml.hbs +40 -0
- package/templates/base/docker-compose.yml.hbs +128 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +316 -0
- package/templates/base/docs/docs/index.md.hbs +100 -0
- package/templates/base/docs/docs/mkdocs.md +238 -0
- package/templates/base/docs/mkdocs.yml.hbs +52 -0
- package/templates/base/e2e/.prettierrc.json +1 -0
- package/templates/base/e2e/_prettierignore +3 -0
- package/templates/base/e2e/cucumber.js +21 -0
- package/templates/base/e2e/eslint.config.mjs +14 -0
- package/templates/base/e2e/features/example.feature +13 -0
- package/templates/base/e2e/package.json.hbs +30 -0
- package/templates/base/e2e/pages/ExamplePage.ts +16 -0
- package/templates/base/e2e/playwright.config.ts +27 -0
- package/templates/base/e2e/steps/common.steps.ts +32 -0
- package/templates/base/e2e/steps/example.steps.ts +4 -0
- package/templates/base/e2e/support/hooks.ts +72 -0
- package/templates/base/e2e/support/world.ts +24 -0
- package/templates/base/e2e/tsconfig.json +22 -0
- package/templates/base/frontend/.prettierrc.json +6 -0
- package/templates/base/frontend/Dockerfile +10 -0
- package/templates/base/frontend/_dockerignore +4 -0
- package/templates/base/frontend/eslint.config.js +32 -0
- package/templates/base/frontend/index.html.hbs +13 -0
- package/templates/base/frontend/package.json.hbs +38 -0
- package/templates/base/frontend/public/favicon.svg +5 -0
- package/templates/base/frontend/src/$components/Layout/$assets/logo.svg +5 -0
- package/templates/base/frontend/src/$components/Layout/constants.tsx.hbs +10 -0
- package/templates/base/frontend/src/$components/Layout/index.tsx +80 -0
- package/templates/base/frontend/src/$components/Layout/types.tsx +9 -0
- package/templates/base/frontend/src/$components/index.tsx +1 -0
- package/templates/base/frontend/src/$hooks/index.tsx +2 -0
- package/templates/base/frontend/src/$hooks/useCounterStore/index.tsx +28 -0
- package/templates/base/frontend/src/$hooks/useCounterStore/types.tsx +7 -0
- package/templates/base/frontend/src/$hooks/usePageTitle/index.tsx +21 -0
- package/templates/base/frontend/src/$types/vite-env.d.ts +10 -0
- package/templates/base/frontend/src/App.tsx.hbs +40 -0
- package/templates/base/frontend/src/main.tsx +10 -0
- package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +28 -0
- package/templates/base/frontend/src/pages/constants.tsx +31 -0
- package/templates/base/frontend/src/pages/index.tsx +192 -0
- package/templates/base/frontend/src/pages/types.tsx +6 -0
- package/templates/base/frontend/src/styles.module.css +7 -0
- package/templates/base/frontend/src/utils/constants.tsx +11 -0
- package/templates/base/frontend/src/utils/formatters/index.tsx +49 -0
- package/templates/base/frontend/src/utils/functions.tsx +70 -0
- package/templates/base/frontend/src/utils/index.tsx +3 -0
- package/templates/base/frontend/tsconfig.json +24 -0
- package/templates/base/frontend/vite.config.ts +20 -0
- package/templates/base/package.json.hbs +11 -0
- package/templates/base/security/baseline.json +4 -0
- package/templates/celery/backend/app/tasks/__init__.py +1 -0
- package/templates/celery/backend/app/tasks/example.py +21 -0
- package/templates/celery/backend/app/tests/tasks/test_example.py +7 -0
- package/templates/celery/backend/app/worker.py.hbs +33 -0
- package/templates/celerybeat/backend/app/tasks/scheduled.py +16 -0
- package/templates/celerybeat/backend/app/tests/tasks/test_scheduled.py +7 -0
- package/templates/postgres/.dude/commands/reset.ts +76 -0
- package/templates/postgres/backend/alembic/env.py +55 -0
- package/templates/postgres/backend/alembic/script.py.mako +27 -0
- package/templates/postgres/backend/alembic/versions/0001_create_user_table.py +38 -0
- package/templates/postgres/backend/alembic.ini +42 -0
- package/templates/postgres/backend/app/core/database.py +15 -0
- package/templates/postgres/backend/app/models/__init__.py +5 -0
- package/templates/postgres/backend/app/models/user.py +15 -0
- package/templates/postgres/backend/app/queries/__init__.py +5 -0
- package/templates/postgres/backend/app/queries/users.py +18 -0
- package/templates/postgres/backend/app/routers/users.py +19 -0
- package/templates/postgres/backend/app/routers/users__id.py +20 -0
- package/templates/postgres/backend/app/tests/conftest.py +33 -0
- package/templates/postgres/backend/app/tests/models/test_user.py +12 -0
- package/templates/postgres/backend/app/tests/queries/test_users.py +12 -0
- package/templates/postgres/backend/app/tests/routers/test_users.py +10 -0
- package/templates/postgres/backend/app/tests/routers/test_users__id.py +9 -0
- package/templates/postgres/backend/start.sh +32 -0
- package/templates/postgres/frontend/src/openapi/utils/openapi.yaml.hbs +138 -0
- package/templates/postgres/frontend/src/pages/users/[id]/index.tsx +51 -0
- package/templates/postgres/frontend/src/pages/users/index.tsx +54 -0
- package/templates/postgres/frontend/src/pages/users/types.tsx +4 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
openapi: 3.1.0
|
|
2
|
+
info:
|
|
3
|
+
title: {{projectName}} backend
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
paths:
|
|
6
|
+
/api/health:
|
|
7
|
+
get:
|
|
8
|
+
summary: Get Health
|
|
9
|
+
description: Health-check endpoint.
|
|
10
|
+
operationId: get_health_api_health_get
|
|
11
|
+
responses:
|
|
12
|
+
"200":
|
|
13
|
+
description: Successful Response
|
|
14
|
+
content:
|
|
15
|
+
application/json:
|
|
16
|
+
schema:
|
|
17
|
+
$ref: "#/components/schemas/HealthResponse"
|
|
18
|
+
components:
|
|
19
|
+
schemas:
|
|
20
|
+
HealthResponse:
|
|
21
|
+
properties:
|
|
22
|
+
status:
|
|
23
|
+
type: string
|
|
24
|
+
title: Status
|
|
25
|
+
type: object
|
|
26
|
+
required:
|
|
27
|
+
- status
|
|
28
|
+
title: HealthResponse
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Command } from './types'
|
|
2
|
+
|
|
3
|
+
export const COMMANDS: Command[] = [
|
|
4
|
+
// Infrastructure
|
|
5
|
+
{ group: 'Infrastructure', cmd: 'dude up --build', desc: 'Build images and start all services' },
|
|
6
|
+
{ group: 'Infrastructure', cmd: 'dude up', desc: 'Start all services (detached)' },
|
|
7
|
+
{ group: 'Infrastructure', cmd: 'dude down', desc: 'Stop and remove containers' },
|
|
8
|
+
{ group: 'Infrastructure', cmd: 'dude logs [service]', desc: 'Follow logs; omit service to follow all' },
|
|
9
|
+
{ group: 'Infrastructure', cmd: 'dude shell <service>', desc: 'Open a shell inside a running container' },
|
|
10
|
+
// Quality
|
|
11
|
+
{ group: 'Code quality', cmd: 'dude lint', desc: 'Structural lint checks (naming, layout)' },
|
|
12
|
+
{ group: 'Code quality', cmd: 'dude format', desc: 'Format code — ruff (backend) + prettier (frontend)' },
|
|
13
|
+
{ group: 'Code quality', cmd: 'dude review', desc: 'Lint + ESLint + API contract review in one pass' },
|
|
14
|
+
// API
|
|
15
|
+
{ group: 'API contract', cmd: 'dude api sync', desc: 'Fetch OpenAPI spec → regenerate the typed client' },
|
|
16
|
+
{ group: 'API contract', cmd: 'dude api review', desc: 'Validate frontend/src/openapi/ against the spec' },
|
|
17
|
+
// Testing
|
|
18
|
+
{ group: 'Testing', cmd: 'dude test', desc: 'Run all test suites (backend + e2e)' },
|
|
19
|
+
{ group: 'Testing', cmd: 'dude test --backend', desc: 'pytest only' },
|
|
20
|
+
{ group: 'Testing', cmd: 'dude test --e2e', desc: 'Playwright + Cucumber only' },
|
|
21
|
+
// Security
|
|
22
|
+
{ group: 'Security', cmd: 'dude security scan', desc: 'Run all SAST scanners; exit 1 on new HIGH+ findings' },
|
|
23
|
+
{ group: 'Security', cmd: 'dude security accept', desc: 'Absorb all findings into the baseline' },
|
|
24
|
+
{ group: 'Security', cmd: 'dude security verify --rule-id <id>', desc: 'Confirm a specific finding is fixed' },
|
|
25
|
+
// Docs
|
|
26
|
+
{ group: 'Documentation', cmd: 'dude docs', desc: 'Serve MkDocs at http://localhost:8001 (live-reload)' },
|
|
27
|
+
// Help
|
|
28
|
+
{ group: 'Help', cmd: 'dude help', desc: 'Show all available commands and flags' },
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
export const GROUPS = [...new Set(COMMANDS.map((c) => c.group))]
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { Alert, Badge, Button, Card, Col, Row, Space, Typography } from 'antd'
|
|
3
|
+
import {
|
|
4
|
+
CheckCircleOutlined,
|
|
5
|
+
CodeOutlined,
|
|
6
|
+
MinusOutlined,
|
|
7
|
+
PlusOutlined,
|
|
8
|
+
RocketOutlined,
|
|
9
|
+
} from '@ant-design/icons'
|
|
10
|
+
import { $get as getHealth } from '@/openapi/api/health'
|
|
11
|
+
import { useCounterStore } from '@/$hooks'
|
|
12
|
+
import { COMMANDS, GROUPS } from './constants'
|
|
13
|
+
|
|
14
|
+
const { Title, Paragraph, Text, Link } = Typography
|
|
15
|
+
|
|
16
|
+
export default function HomePage() {
|
|
17
|
+
const { data, isLoading, isError } = useQuery({
|
|
18
|
+
queryKey: ['health'],
|
|
19
|
+
queryFn: getHealth,
|
|
20
|
+
refetchInterval: 30_000,
|
|
21
|
+
})
|
|
22
|
+
const { count, increment, decrement, reset } = useCounterStore()
|
|
23
|
+
|
|
24
|
+
const statusText = isLoading
|
|
25
|
+
? 'checking…'
|
|
26
|
+
: isError
|
|
27
|
+
? 'unreachable'
|
|
28
|
+
: (data?.status ?? 'unknown')
|
|
29
|
+
const statusOk = !isLoading && !isError && data?.status === 'ok'
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Space direction="vertical" size="large" style={{ width: '100%' }}>
|
|
33
|
+
{/* Hero */}
|
|
34
|
+
<Card>
|
|
35
|
+
<Space align="start" size="large">
|
|
36
|
+
<RocketOutlined style={{ fontSize: 48, color: '#1677ff' }} />
|
|
37
|
+
<div>
|
|
38
|
+
<Title level={2} style={{ margin: 0 }}>
|
|
39
|
+
Welcome to your dude project
|
|
40
|
+
</Title>
|
|
41
|
+
<Paragraph style={{ margin: '8px 0 0' }}>
|
|
42
|
+
This app was scaffolded with{' '}
|
|
43
|
+
<Link href="https://github.com/cubocicloide/dude" target="_blank">
|
|
44
|
+
dude
|
|
45
|
+
</Link>{' '}
|
|
46
|
+
using the <Text code>react-fastapi</Text> stack — React 19 + Vite + FastAPI + Docker
|
|
47
|
+
Compose. Delete this page and start building your application.
|
|
48
|
+
</Paragraph>
|
|
49
|
+
</div>
|
|
50
|
+
</Space>
|
|
51
|
+
</Card>
|
|
52
|
+
|
|
53
|
+
<Row gutter={[16, 16]}>
|
|
54
|
+
{/* Backend health */}
|
|
55
|
+
<Col xs={24} md={8}>
|
|
56
|
+
<Card title="Backend health" loading={isLoading} style={{ height: '100%' }}>
|
|
57
|
+
{statusOk ? (
|
|
58
|
+
<Badge
|
|
59
|
+
status="success"
|
|
60
|
+
text={
|
|
61
|
+
<Text>
|
|
62
|
+
API is <Text strong>online</Text> — {statusText}
|
|
63
|
+
</Text>
|
|
64
|
+
}
|
|
65
|
+
/>
|
|
66
|
+
) : (
|
|
67
|
+
<Badge status={isLoading ? 'processing' : 'error'} text={statusText} />
|
|
68
|
+
)}
|
|
69
|
+
</Card>
|
|
70
|
+
</Col>
|
|
71
|
+
|
|
72
|
+
{/* Zustand store demo */}
|
|
73
|
+
<Col xs={24} md={8}>
|
|
74
|
+
<Card title="Zustand store" style={{ height: '100%' }}>
|
|
75
|
+
<Space>
|
|
76
|
+
<Button icon={<MinusOutlined />} onClick={decrement} aria-label="decrement" />
|
|
77
|
+
<Text strong style={{ fontSize: 18, minWidth: 32, display: 'inline-block', textAlign: 'center' }}>
|
|
78
|
+
{count}
|
|
79
|
+
</Text>
|
|
80
|
+
<Button icon={<PlusOutlined />} onClick={increment} aria-label="increment" />
|
|
81
|
+
<Button onClick={reset}>Reset</Button>
|
|
82
|
+
</Space>
|
|
83
|
+
<Paragraph type="secondary" style={{ margin: '12px 0 0' }}>
|
|
84
|
+
Global state from <Text code>$hooks/useCounterStore</Text> — devtools enabled in dev.
|
|
85
|
+
</Paragraph>
|
|
86
|
+
</Card>
|
|
87
|
+
</Col>
|
|
88
|
+
|
|
89
|
+
{/* Quick links */}
|
|
90
|
+
<Col xs={24} md={8}>
|
|
91
|
+
<Card title={<><CodeOutlined /> Quick links</>} style={{ height: '100%' }}>
|
|
92
|
+
<Space wrap size="middle">
|
|
93
|
+
<Link href="/api/docs" target="_blank">
|
|
94
|
+
API docs (Swagger)
|
|
95
|
+
</Link>
|
|
96
|
+
<Link href="/api/redoc" target="_blank">
|
|
97
|
+
ReDoc
|
|
98
|
+
</Link>
|
|
99
|
+
<Link href="http://localhost:8001" target="_blank">
|
|
100
|
+
Project docs (MkDocs)
|
|
101
|
+
</Link>
|
|
102
|
+
</Space>
|
|
103
|
+
</Card>
|
|
104
|
+
</Col>
|
|
105
|
+
</Row>
|
|
106
|
+
|
|
107
|
+
{/* Getting started */}
|
|
108
|
+
<Card title={<><CheckCircleOutlined /> Getting started</>}>
|
|
109
|
+
<ol style={{ paddingLeft: 20, margin: 0, lineHeight: 2.2 }}>
|
|
110
|
+
<li>
|
|
111
|
+
<Text strong>Start the stack</Text> —{' '}
|
|
112
|
+
<Text code>dude up --build</Text> from the project root
|
|
113
|
+
</li>
|
|
114
|
+
<li>
|
|
115
|
+
<Text strong>Open the app</Text> —{' '}
|
|
116
|
+
<Link href="http://localhost:5173" target="_blank">http://localhost:5173</Link> (frontend) ·{' '}
|
|
117
|
+
<Link href="http://localhost:8000/api/docs" target="_blank">http://localhost:8000/api/docs</Link>{' '}
|
|
118
|
+
(API)
|
|
119
|
+
</li>
|
|
120
|
+
<li>
|
|
121
|
+
<Text strong>Make changes</Text> — edit{' '}
|
|
122
|
+
<Text code>backend/</Text> or <Text code>frontend/src/</Text>; hot-reload is enabled
|
|
123
|
+
</li>
|
|
124
|
+
<li>
|
|
125
|
+
<Text strong>Sync the API client</Text> — run{' '}
|
|
126
|
+
<Text code>dude api sync</Text> after changing backend routes
|
|
127
|
+
</li>
|
|
128
|
+
<li>
|
|
129
|
+
<Text strong>Run tests</Text> —{' '}
|
|
130
|
+
<Text code>dude test</Text> covers pytest (backend) and Playwright (e2e)
|
|
131
|
+
</li>
|
|
132
|
+
<li>
|
|
133
|
+
<Text strong>Check security</Text> —{' '}
|
|
134
|
+
<Text code>dude security scan</Text> — no extra tools needed, runs in Docker
|
|
135
|
+
</li>
|
|
136
|
+
<li>
|
|
137
|
+
<Text strong>Read the docs</Text> —{' '}
|
|
138
|
+
<Text code>dude docs</Text> to serve the MkDocs site locally
|
|
139
|
+
</li>
|
|
140
|
+
</ol>
|
|
141
|
+
</Card>
|
|
142
|
+
|
|
143
|
+
{/* Commands reference */}
|
|
144
|
+
<Card title="dude CLI reference">
|
|
145
|
+
<Space direction="vertical" size="large" style={{ width: '100%' }}>
|
|
146
|
+
{GROUPS.map((group) => (
|
|
147
|
+
<div key={group}>
|
|
148
|
+
<Text
|
|
149
|
+
strong
|
|
150
|
+
style={{
|
|
151
|
+
display: 'block',
|
|
152
|
+
marginBottom: 6,
|
|
153
|
+
color: '#1677ff',
|
|
154
|
+
textTransform: 'uppercase',
|
|
155
|
+
fontSize: 11,
|
|
156
|
+
letterSpacing: 1,
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
{group}
|
|
160
|
+
</Text>
|
|
161
|
+
<Space direction="vertical" size={4} style={{ width: '100%' }}>
|
|
162
|
+
{COMMANDS.filter((c) => c.group === group).map(({ cmd, desc }) => (
|
|
163
|
+
<Row key={cmd} gutter={8} align="middle" wrap>
|
|
164
|
+
<Col xs={24} md={10}>
|
|
165
|
+
<Text code style={{ whiteSpace: 'nowrap' }}>
|
|
166
|
+
{cmd}
|
|
167
|
+
</Text>
|
|
168
|
+
</Col>
|
|
169
|
+
<Col xs={24} md={14}>
|
|
170
|
+
<Text type="secondary">{desc}</Text>
|
|
171
|
+
</Col>
|
|
172
|
+
</Row>
|
|
173
|
+
))}
|
|
174
|
+
</Space>
|
|
175
|
+
</div>
|
|
176
|
+
))}
|
|
177
|
+
</Space>
|
|
178
|
+
<Alert
|
|
179
|
+
style={{ marginTop: 16 }}
|
|
180
|
+
type="info"
|
|
181
|
+
showIcon
|
|
182
|
+
message={
|
|
183
|
+
<Text>
|
|
184
|
+
Run <Text code>dude help</Text> for a live, always-up-to-date overview, or{' '}
|
|
185
|
+
<Text code>dude help <command></Text> for flags.
|
|
186
|
+
</Text>
|
|
187
|
+
}
|
|
188
|
+
/>
|
|
189
|
+
</Card>
|
|
190
|
+
</Space>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Base path for all API requests (proxied by Vite dev server and Docker). */
|
|
2
|
+
export const API_BASE_URL = '/api'
|
|
3
|
+
|
|
4
|
+
/** Application title sourced from the Vite environment. */
|
|
5
|
+
export const APP_TITLE = import.meta.env.VITE_APP_TITLE as string
|
|
6
|
+
|
|
7
|
+
/** BCP 47 locale tag used for date/number formatting across the app. */
|
|
8
|
+
export const DEFAULT_LOCALE = 'en-US'
|
|
9
|
+
|
|
10
|
+
/** Default page size for paginated tables and lists. */
|
|
11
|
+
export const DEFAULT_PAGE_SIZE = 20
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DEFAULT_LOCALE } from '../constants'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Formats an ISO date string or Date object as a short date.
|
|
5
|
+
* @example formatDate('2026-01-15') → "Jan 15, 2026"
|
|
6
|
+
*/
|
|
7
|
+
export function formatDate(value: string | Date | null | undefined): string {
|
|
8
|
+
if (!value) return '—'
|
|
9
|
+
return new Date(value).toLocaleDateString(DEFAULT_LOCALE, {
|
|
10
|
+
year: 'numeric',
|
|
11
|
+
month: 'short',
|
|
12
|
+
day: 'numeric',
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Formats an ISO date string or Date object as a short datetime.
|
|
18
|
+
* @example formatDateTime('2026-01-15T14:30:00Z') → "Jan 15, 2026, 14:30"
|
|
19
|
+
*/
|
|
20
|
+
export function formatDateTime(value: string | Date | null | undefined): string {
|
|
21
|
+
if (!value) return '—'
|
|
22
|
+
return new Date(value).toLocaleString(DEFAULT_LOCALE, {
|
|
23
|
+
year: 'numeric',
|
|
24
|
+
month: 'short',
|
|
25
|
+
day: 'numeric',
|
|
26
|
+
hour: '2-digit',
|
|
27
|
+
minute: '2-digit',
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Formats a number with thousands separators.
|
|
33
|
+
* @example formatNumber(1000000) → "1,000,000"
|
|
34
|
+
*/
|
|
35
|
+
export function formatNumber(value: number | null | undefined): string {
|
|
36
|
+
if (value == null) return '—'
|
|
37
|
+
return value.toLocaleString(DEFAULT_LOCALE)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Formats a byte count as a human-readable size string.
|
|
42
|
+
* @example formatBytes(1536) → "1.5 KB"
|
|
43
|
+
*/
|
|
44
|
+
export function formatBytes(bytes: number): string {
|
|
45
|
+
if (bytes === 0) return '0 B'
|
|
46
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
47
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024))
|
|
48
|
+
return `${(bytes / 1024 ** i).toFixed(1)} ${units[i]}`
|
|
49
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a debounced version of `fn` that fires only after `delay` ms of
|
|
3
|
+
* inactivity. Useful for search inputs and resize handlers.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const debouncedSearch = debounce(handleSearch, 300)
|
|
7
|
+
*/
|
|
8
|
+
export function debounce<T extends (...args: Parameters<T>) => void>(
|
|
9
|
+
fn: T,
|
|
10
|
+
delay: number,
|
|
11
|
+
): (...args: Parameters<T>) => void {
|
|
12
|
+
let timer: ReturnType<typeof setTimeout>
|
|
13
|
+
return (...args: Parameters<T>) => {
|
|
14
|
+
clearTimeout(timer)
|
|
15
|
+
timer = setTimeout(() => fn(...args), delay)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object containing only the specified keys.
|
|
21
|
+
*
|
|
22
|
+
* @example pick({ a: 1, b: 2, c: 3 }, ['a', 'c']) → { a: 1, c: 3 }
|
|
23
|
+
*/
|
|
24
|
+
export function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {
|
|
25
|
+
return keys.reduce((acc, key) => ({ ...acc, [key]: obj[key] }), {} as Pick<T, K>)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new object without the specified keys.
|
|
30
|
+
*
|
|
31
|
+
* @example omit({ a: 1, b: 2, c: 3 }, ['b']) → { a: 1, c: 3 }
|
|
32
|
+
*/
|
|
33
|
+
export function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
|
|
34
|
+
const result = { ...obj }
|
|
35
|
+
for (const key of keys) delete result[key]
|
|
36
|
+
return result as Omit<T, K>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Groups an array into a record keyed by the return value of `key`.
|
|
41
|
+
*
|
|
42
|
+
* @example groupBy(users, (u) => u.role) → { admin: [...], viewer: [...] }
|
|
43
|
+
*/
|
|
44
|
+
export function groupBy<T>(arr: T[], key: (item: T) => string): Record<string, T[]> {
|
|
45
|
+
return arr.reduce<Record<string, T[]>>((acc, item) => {
|
|
46
|
+
const k = key(item)
|
|
47
|
+
;(acc[k] ??= []).push(item)
|
|
48
|
+
return acc
|
|
49
|
+
}, {})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generates a cryptographically-safe random UUID v4.
|
|
54
|
+
* Uses the Web Crypto API — available in all modern browsers and Node ≥ 19.
|
|
55
|
+
*/
|
|
56
|
+
export function uuid(): string {
|
|
57
|
+
return crypto.randomUUID()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Type-safe assertion that a value is non-null and non-undefined.
|
|
62
|
+
* Throws at runtime if the invariant is violated.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const el = assertDefined(document.getElementById('root'), '#root not found')
|
|
66
|
+
*/
|
|
67
|
+
export function assertDefined<T>(value: T | null | undefined, message: string): T {
|
|
68
|
+
if (value == null) throw new Error(message)
|
|
69
|
+
return value
|
|
70
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "Bundler",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"noUnusedParameters": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"esModuleInterop": true,
|
|
18
|
+
"baseUrl": ".",
|
|
19
|
+
"paths": {
|
|
20
|
+
"@/*": ["./src/*"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"include": ["src"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import { fileURLToPath, URL } from 'node:url'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
envDir: '..', // read .env from project root (also used by docker-compose)
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: {
|
|
10
|
+
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
server: {
|
|
14
|
+
host: true,
|
|
15
|
+
port: 5173,
|
|
16
|
+
proxy: {
|
|
17
|
+
'/api': process.env.BACKEND_URL ?? 'http://localhost:8000',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Tasks package."""
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Example Celery tasks."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from app.worker import celery_app
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@celery_app.task
|
|
11
|
+
def add(x: int, y: int) -> int:
|
|
12
|
+
"""Add two numbers asynchronously.
|
|
13
|
+
|
|
14
|
+
Usage::
|
|
15
|
+
|
|
16
|
+
from app.tasks.example import add
|
|
17
|
+
result = add.delay(3, 4)
|
|
18
|
+
print(result.get()) # 7
|
|
19
|
+
"""
|
|
20
|
+
logger.info("add(%s, %s)", x, y)
|
|
21
|
+
return x + y
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Celery application."""
|
|
2
|
+
|
|
3
|
+
from app.core.config import settings
|
|
4
|
+
from celery import Celery
|
|
5
|
+
|
|
6
|
+
celery_app = Celery(
|
|
7
|
+
"worker",
|
|
8
|
+
broker=settings.CELERY_BROKER_URL,
|
|
9
|
+
backend=settings.CELERY_RESULT_BACKEND,
|
|
10
|
+
include=[
|
|
11
|
+
"app.tasks.example",
|
|
12
|
+
{{#if withCeleryBeat}}
|
|
13
|
+
"app.tasks.scheduled",
|
|
14
|
+
{{/if}}
|
|
15
|
+
],
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
celery_app.conf.update(
|
|
19
|
+
task_serializer="json",
|
|
20
|
+
accept_content=["json"],
|
|
21
|
+
result_serializer="json",
|
|
22
|
+
timezone="UTC",
|
|
23
|
+
enable_utc=True,
|
|
24
|
+
)
|
|
25
|
+
{{#if withCeleryBeat}}
|
|
26
|
+
|
|
27
|
+
celery_app.conf.beat_schedule = {
|
|
28
|
+
"heartbeat-every-minute": {
|
|
29
|
+
"task": "app.tasks.scheduled.heartbeat",
|
|
30
|
+
"schedule": 60.0,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
{{/if}}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Scheduled (periodic) Celery tasks — run by Celery Beat."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from app.worker import celery_app
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@celery_app.task
|
|
11
|
+
def heartbeat() -> None:
|
|
12
|
+
"""Periodic heartbeat — fires every minute.
|
|
13
|
+
|
|
14
|
+
Adjust the schedule in ``app/worker.py`` via ``beat_schedule``.
|
|
15
|
+
"""
|
|
16
|
+
logger.info("Heartbeat tick")
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { defineCommand } from '@cubocicloide/dude'
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
function exec(cmd: string, args: string[], cwd: string): void {
|
|
5
|
+
const result = spawnSync(cmd, args, { cwd, stdio: 'inherit' })
|
|
6
|
+
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function waitForBackend(url: string, retries = 30, intervalMs = 2000): Promise<void> {
|
|
10
|
+
for (let i = 0; i < retries; i++) {
|
|
11
|
+
try {
|
|
12
|
+
const res = await fetch(url)
|
|
13
|
+
if (res.ok) return
|
|
14
|
+
} catch {
|
|
15
|
+
// not ready yet
|
|
16
|
+
}
|
|
17
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs))
|
|
18
|
+
}
|
|
19
|
+
process.stderr.write(
|
|
20
|
+
`error: backend did not become healthy after ${(retries * intervalMs) / 1000}s\n`,
|
|
21
|
+
)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const SEED_SCRIPT = `
|
|
26
|
+
from sqlmodel import Session, select, SQLModel
|
|
27
|
+
from app.core.database import engine
|
|
28
|
+
from app.models.user import User
|
|
29
|
+
|
|
30
|
+
SQLModel.metadata.create_all(engine)
|
|
31
|
+
|
|
32
|
+
users = [
|
|
33
|
+
User(email="admin@example.com", full_name="Admin User"),
|
|
34
|
+
User(email="alice@example.com", full_name="Alice Smith"),
|
|
35
|
+
User(email="bob@example.com", full_name="Bob Jones"),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
with Session(engine) as session:
|
|
39
|
+
added = 0
|
|
40
|
+
for u in users:
|
|
41
|
+
if not session.exec(select(User).where(User.email == u.email)).first():
|
|
42
|
+
session.add(u)
|
|
43
|
+
added += 1
|
|
44
|
+
session.commit()
|
|
45
|
+
print(f"Seeded {added} user(s).")
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
export default defineCommand({
|
|
49
|
+
description: 'Drop the database, re-apply all migrations, and seed demo data.',
|
|
50
|
+
async run({ projectRoot }) {
|
|
51
|
+
process.stdout.write('Dropping all containers and volumes...\n')
|
|
52
|
+
exec('docker', ['compose', 'down', '--volumes'], projectRoot)
|
|
53
|
+
|
|
54
|
+
process.stdout.write('Starting services...\n')
|
|
55
|
+
exec('docker', ['compose', 'up', '--detach'], projectRoot)
|
|
56
|
+
|
|
57
|
+
process.stdout.write('Waiting for backend to be ready...\n')
|
|
58
|
+
await waitForBackend('http://localhost:8000/api/health')
|
|
59
|
+
|
|
60
|
+
process.stdout.write('Running migrations...\n')
|
|
61
|
+
exec(
|
|
62
|
+
'docker',
|
|
63
|
+
['compose', 'exec', 'backend', 'uv', 'run', 'alembic', 'upgrade', 'head'],
|
|
64
|
+
projectRoot,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
process.stdout.write('Seeding demo data...\n')
|
|
68
|
+
exec(
|
|
69
|
+
'docker',
|
|
70
|
+
['compose', 'exec', 'backend', 'uv', 'run', 'python', '-c', SEED_SCRIPT],
|
|
71
|
+
projectRoot,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
process.stdout.write('Reset complete.\n')
|
|
75
|
+
},
|
|
76
|
+
})
|