@invictus-group-ai/orchestra 0.5.0
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 +21 -0
- package/LICENSING.md +49 -0
- package/README.md +507 -0
- package/assets/settings-template.json +99 -0
- package/bin/invi.js +6 -0
- package/content-dist/LICENSE +95 -0
- package/content-dist/PIPELINE.md +823 -0
- package/content-dist/README.md +128 -0
- package/content-dist/agents/README.md +135 -0
- package/content-dist/agents/mapping.json +476 -0
- package/content-dist/agents/stacks/backend-django.md +66 -0
- package/content-dist/agents/stacks/backend-dotnet.md +72 -0
- package/content-dist/agents/stacks/backend-fastapi.md +66 -0
- package/content-dist/agents/stacks/backend-laravel.md +66 -0
- package/content-dist/agents/stacks/backend-node.md +66 -0
- package/content-dist/agents/stacks/backend-spring.md +66 -0
- package/content-dist/agents/stacks/desktop-delphi.md +73 -0
- package/content-dist/agents/stacks/frontend-angular.md +65 -0
- package/content-dist/agents/stacks/frontend-react.md +67 -0
- package/content-dist/agents/stacks/frontend-svelte.md +67 -0
- package/content-dist/agents/stacks/frontend-vue.md +66 -0
- package/content-dist/agents/stacks/mobile-flutter.md +68 -0
- package/content-dist/agents/stacks/wordpress.md +66 -0
- package/content-dist/agents/universal/invi-qa.md +57 -0
- package/content-dist/agents/universal/invi-reviewer.md +61 -0
- package/content-dist/agents/universal/invi-security.md +55 -0
- package/content-dist/agents/universal/invi-tester.md +55 -0
- package/content-dist/agents/universal/invi-ui.md +85 -0
- package/content-dist/fragments/base.md +37 -0
- package/content-dist/fragments/domain/api-publica-rate-limiting.md +83 -0
- package/content-dist/fragments/domain/autenticacao-enterprise.md +86 -0
- package/content-dist/fragments/domain/busca-elasticsearch.md +86 -0
- package/content-dist/fragments/domain/dashboard-admin-rbac.md +80 -0
- package/content-dist/fragments/domain/design-system.md +71 -0
- package/content-dist/fragments/domain/ecommerce-completo.md +86 -0
- package/content-dist/fragments/domain/filas-jobs.md +80 -0
- package/content-dist/fragments/domain/integracao-crm-erp.md +82 -0
- package/content-dist/fragments/domain/lgpd.md +84 -0
- package/content-dist/fragments/domain/multi-tenancy.md +79 -0
- package/content-dist/fragments/domain/notificacoes-multicanal.md +81 -0
- package/content-dist/fragments/domain/pagamentos-brasil.md +85 -0
- package/content-dist/fragments/domain/plataforma-conteudo.md +77 -0
- package/content-dist/fragments/domain/realtime-websockets.md +92 -0
- package/content-dist/fragments/domain/relatorios-analytics.md +80 -0
- package/content-dist/fragments/domain/saas-stripe-billing.md +79 -0
- package/content-dist/fragments/domain/sistema-pagamentos.md +81 -0
- package/content-dist/fragments/domain/upload-midia.md +81 -0
- package/content-dist/fragments/domain/whatsapp-business.md +82 -0
- package/content-dist/fragments/index.json +1670 -0
- package/content-dist/fragments/references/angular-ngrx/app-config-and-testing.md +81 -0
- package/content-dist/fragments/references/angular-ngrx/store-pattern.md +155 -0
- package/content-dist/fragments/references/ansible-server-setup/layout-and-config.md +143 -0
- package/content-dist/fragments/references/ansible-server-setup/roles.md +238 -0
- package/content-dist/fragments/references/api-publica-rate-limiting/patterns.md +68 -0
- package/content-dist/fragments/references/astro-static/content-and-islands.md +117 -0
- package/content-dist/fragments/references/autenticacao-enterprise/pitfalls.md +70 -0
- package/content-dist/fragments/references/busca-elasticsearch/patterns.md +100 -0
- package/content-dist/fragments/references/chrome-extension-mv3/messaging-and-storage.md +109 -0
- package/content-dist/fragments/references/cli-typescript-commander/commands-and-config.md +136 -0
- package/content-dist/fragments/references/cloud-run-gcp/build-and-deploy.md +127 -0
- package/content-dist/fragments/references/cloud-run-gcp/iam-secrets-networking.md +65 -0
- package/content-dist/fragments/references/computer-vision-yolo/serving-and-export.md +182 -0
- package/content-dist/fragments/references/computer-vision-yolo/training-and-validation.md +131 -0
- package/content-dist/fragments/references/convex-react/functions.md +117 -0
- package/content-dist/fragments/references/convex-react/react-and-storage.md +109 -0
- package/content-dist/fragments/references/dashboard-admin-rbac/patterns.md +73 -0
- package/content-dist/fragments/references/data-pipeline-airflow/dag-patterns.md +149 -0
- package/content-dist/fragments/references/data-pipeline-airflow/operations.md +74 -0
- package/content-dist/fragments/references/delphi-object-pascal/legacy-extraction.md +175 -0
- package/content-dist/fragments/references/django-drf-celery/celery-tasks.md +47 -0
- package/content-dist/fragments/references/django-drf-celery/viewsets-and-serializers.md +92 -0
- package/content-dist/fragments/references/docker-compose-dev/compose-files.md +146 -0
- package/content-dist/fragments/references/docker-compose-dev/dockerfile-and-proxy.md +108 -0
- package/content-dist/fragments/references/dotnet-aspnet/data-and-di.md +90 -0
- package/content-dist/fragments/references/dotnet-aspnet/web-layer.md +88 -0
- package/content-dist/fragments/references/ecommerce-completo/patterns.md +76 -0
- package/content-dist/fragments/references/electron-app/ipc-bridge.md +123 -0
- package/content-dist/fragments/references/electron-app/security-and-packaging.md +134 -0
- package/content-dist/fragments/references/elixir-phoenix/context-and-web.md +112 -0
- package/content-dist/fragments/references/elixir-phoenix/processes.md +65 -0
- package/content-dist/fragments/references/filas-jobs/patterns.md +116 -0
- package/content-dist/fragments/references/fine-tuning-huggingface/data-and-export.md +114 -0
- package/content-dist/fragments/references/fine-tuning-huggingface/training-and-lora.md +123 -0
- package/content-dist/fragments/references/flutter/platform-channels-and-goldens.md +68 -0
- package/content-dist/fragments/references/flutter/state-and-widgets.md +95 -0
- package/content-dist/fragments/references/github-actions-cicd/workflows.md +235 -0
- package/content-dist/fragments/references/go-chi-gorm/http-layer.md +87 -0
- package/content-dist/fragments/references/go-chi-gorm/service-layer.md +58 -0
- package/content-dist/fragments/references/graphql-apollo/resolvers-and-loaders.md +128 -0
- package/content-dist/fragments/references/hono-bun/patterns.md +144 -0
- package/content-dist/fragments/references/integracao-crm-erp/patterns.md +100 -0
- package/content-dist/fragments/references/kubernetes-helm/chart-templates.md +162 -0
- package/content-dist/fragments/references/kubernetes-helm/secrets-storage-deploy.md +78 -0
- package/content-dist/fragments/references/langchain-python-agent/agent-and-cost.md +120 -0
- package/content-dist/fragments/references/langchain-python-agent/memory-and-resilience.md +76 -0
- package/content-dist/fragments/references/laravel/eloquent-and-queues.md +126 -0
- package/content-dist/fragments/references/laravel/http-layer.md +110 -0
- package/content-dist/fragments/references/lgpd/patterns.md +110 -0
- package/content-dist/fragments/references/llm-ops-production/routing-and-budget.md +118 -0
- package/content-dist/fragments/references/llm-ops-production/tracing-eval-ab.md +102 -0
- package/content-dist/fragments/references/microservices-docker/compose-and-gateway.md +93 -0
- package/content-dist/fragments/references/microservices-docker/events-and-correlation.md +88 -0
- package/content-dist/fragments/references/ml-fastapi-serving/metrics-drift-docker.md +97 -0
- package/content-dist/fragments/references/ml-fastapi-serving/serving-core.md +155 -0
- package/content-dist/fragments/references/ml-training-pipeline/dvc-pipeline.md +102 -0
- package/content-dist/fragments/references/ml-training-pipeline/mlflow-registry-ci.md +139 -0
- package/content-dist/fragments/references/monitoring-observability/alerts-and-config.md +169 -0
- package/content-dist/fragments/references/monitoring-observability/instrumentation-node.md +139 -0
- package/content-dist/fragments/references/multi-tenancy/patterns.md +85 -0
- package/content-dist/fragments/references/nestjs-typescript/guards-and-decorators.md +103 -0
- package/content-dist/fragments/references/nestjs-typescript/modules-dtos-setup.md +106 -0
- package/content-dist/fragments/references/nextjs-app-router/patterns.md +177 -0
- package/content-dist/fragments/references/nextjs-prisma-postgres/billing.md +167 -0
- package/content-dist/fragments/references/nextjs-trpc-drizzle/data-and-auth.md +121 -0
- package/content-dist/fragments/references/nextjs-trpc-drizzle/trpc-setup.md +62 -0
- package/content-dist/fragments/references/nodejs-express-typescript/config-and-tokens.md +48 -0
- package/content-dist/fragments/references/nodejs-express-typescript/middleware.md +108 -0
- package/content-dist/fragments/references/notificacoes-multicanal/patterns.md +78 -0
- package/content-dist/fragments/references/nuxt3-tailwind/server-routes.md +79 -0
- package/content-dist/fragments/references/nuxt3-tailwind/state-and-fetching.md +129 -0
- package/content-dist/fragments/references/openai-api-integration/calls.md +210 -0
- package/content-dist/fragments/references/openai-api-integration/client-and-cost.md +71 -0
- package/content-dist/fragments/references/pagamentos-brasil/gateways-reconciliation.md +92 -0
- package/content-dist/fragments/references/pagamentos-brasil/pix-boleto.md +115 -0
- package/content-dist/fragments/references/plataforma-conteudo/patterns.md +74 -0
- package/content-dist/fragments/references/python-fastapi/dependency-injection.md +99 -0
- package/content-dist/fragments/references/python-fastapi/settings-and-tasks.md +47 -0
- package/content-dist/fragments/references/rag-pipeline/ingestion.md +92 -0
- package/content-dist/fragments/references/rag-pipeline/retrieval-and-eval.md +148 -0
- package/content-dist/fragments/references/react-express-monolith/auth-and-client.md +110 -0
- package/content-dist/fragments/references/react-express-monolith/monorepo.md +71 -0
- package/content-dist/fragments/references/react-native-expo/native-patterns.md +103 -0
- package/content-dist/fragments/references/react-native-expo/navigation-and-auth.md +55 -0
- package/content-dist/fragments/references/react-ts-zustand-query/store-and-query.md +152 -0
- package/content-dist/fragments/references/react-typescript/feature-module.md +64 -0
- package/content-dist/fragments/references/react-typescript/forms-and-state.md +69 -0
- package/content-dist/fragments/references/react-typescript/recipes.md +37 -0
- package/content-dist/fragments/references/react-typescript/testing.md +40 -0
- package/content-dist/fragments/references/realtime-websockets/patterns.md +92 -0
- package/content-dist/fragments/references/relatorios-analytics/patterns.md +81 -0
- package/content-dist/fragments/references/remix-express-full/auth-and-uploads.md +88 -0
- package/content-dist/fragments/references/remix-express-full/express-server.md +54 -0
- package/content-dist/fragments/references/remix-typescript/auth-and-db.md +68 -0
- package/content-dist/fragments/references/remix-typescript/loaders-and-actions.md +98 -0
- package/content-dist/fragments/references/rust-axum/error-and-state.md +99 -0
- package/content-dist/fragments/references/rust-axum/handlers.md +87 -0
- package/content-dist/fragments/references/saas-stripe-billing/patterns.md +86 -0
- package/content-dist/fragments/references/serverless-lambda/handler-patterns.md +107 -0
- package/content-dist/fragments/references/sistema-pagamentos/pitfalls.md +54 -0
- package/content-dist/fragments/references/spring-boot/service-and-data.md +96 -0
- package/content-dist/fragments/references/spring-boot/web-layer.md +100 -0
- package/content-dist/fragments/references/supabase-nextjs/clients-and-middleware.md +102 -0
- package/content-dist/fragments/references/supabase-nextjs/rls-and-storage.md +86 -0
- package/content-dist/fragments/references/svelte-sveltekit/hooks-and-state.md +67 -0
- package/content-dist/fragments/references/svelte-sveltekit/load-and-actions.md +80 -0
- package/content-dist/fragments/references/t3-stack/routers-and-callers.md +75 -0
- package/content-dist/fragments/references/t3-stack/trpc-setup.md +60 -0
- package/content-dist/fragments/references/terraform-aws/modules-and-ci.md +114 -0
- package/content-dist/fragments/references/terraform-aws/state-and-workspaces.md +66 -0
- package/content-dist/fragments/references/turborepo-monorepo/pipeline-and-packages.md +84 -0
- package/content-dist/fragments/references/upload-midia/patterns.md +80 -0
- package/content-dist/fragments/references/vector-search-pinecone/client-and-upsert.md +98 -0
- package/content-dist/fragments/references/vector-search-pinecone/query-and-hybrid.md +81 -0
- package/content-dist/fragments/references/vps-deploy-producao/compose-prod.md +97 -0
- package/content-dist/fragments/references/vps-deploy-producao/proxy-and-operations.md +118 -0
- package/content-dist/fragments/references/vscode-extension/activation-and-tree.md +98 -0
- package/content-dist/fragments/references/vscode-extension/webview-csp.md +57 -0
- package/content-dist/fragments/references/vue3-pinia-vite/components-and-stores.md +73 -0
- package/content-dist/fragments/references/vue3-pinia-vite/queries-forms-testing.md +100 -0
- package/content-dist/fragments/references/whatsapp-business/patterns.md +107 -0
- package/content-dist/fragments/references/wordpress/hooks-and-security.md +92 -0
- package/content-dist/fragments/references/wordpress/wp-cli-gates.md +64 -0
- package/content-dist/fragments/stack/angular-ngrx.md +75 -0
- package/content-dist/fragments/stack/ansible-server-setup.md +69 -0
- package/content-dist/fragments/stack/astro-static.md +72 -0
- package/content-dist/fragments/stack/chrome-extension-mv3.md +66 -0
- package/content-dist/fragments/stack/cli-typescript-commander.md +66 -0
- package/content-dist/fragments/stack/cloud-run-gcp.md +63 -0
- package/content-dist/fragments/stack/computer-vision-yolo.md +62 -0
- package/content-dist/fragments/stack/convex-react.md +65 -0
- package/content-dist/fragments/stack/data-pipeline-airflow.md +64 -0
- package/content-dist/fragments/stack/delphi-object-pascal.md +63 -0
- package/content-dist/fragments/stack/django-drf-celery.md +63 -0
- package/content-dist/fragments/stack/docker-compose-dev.md +69 -0
- package/content-dist/fragments/stack/dotnet-aspnet.md +62 -0
- package/content-dist/fragments/stack/electron-app.md +70 -0
- package/content-dist/fragments/stack/elixir-phoenix.md +65 -0
- package/content-dist/fragments/stack/fine-tuning-huggingface.md +69 -0
- package/content-dist/fragments/stack/flutter.md +61 -0
- package/content-dist/fragments/stack/github-actions-cicd.md +73 -0
- package/content-dist/fragments/stack/go-chi-gorm.md +73 -0
- package/content-dist/fragments/stack/graphql-apollo.md +70 -0
- package/content-dist/fragments/stack/hono-bun.md +62 -0
- package/content-dist/fragments/stack/kubernetes-helm.md +67 -0
- package/content-dist/fragments/stack/langchain-python-agent.md +64 -0
- package/content-dist/fragments/stack/laravel.md +64 -0
- package/content-dist/fragments/stack/llm-ops-production.md +63 -0
- package/content-dist/fragments/stack/microservices-docker.md +70 -0
- package/content-dist/fragments/stack/ml-fastapi-serving.md +64 -0
- package/content-dist/fragments/stack/ml-training-pipeline.md +67 -0
- package/content-dist/fragments/stack/monitoring-observability.md +68 -0
- package/content-dist/fragments/stack/nestjs-typescript.md +68 -0
- package/content-dist/fragments/stack/nextjs-app-router.md +65 -0
- package/content-dist/fragments/stack/nextjs-prisma-postgres.md +61 -0
- package/content-dist/fragments/stack/nextjs-trpc-drizzle.md +63 -0
- package/content-dist/fragments/stack/nodejs-express-typescript.md +60 -0
- package/content-dist/fragments/stack/nuxt3-tailwind.md +62 -0
- package/content-dist/fragments/stack/openai-api-integration.md +58 -0
- package/content-dist/fragments/stack/python-fastapi.md +64 -0
- package/content-dist/fragments/stack/rag-pipeline.md +62 -0
- package/content-dist/fragments/stack/react-express-monolith.md +61 -0
- package/content-dist/fragments/stack/react-native-expo.md +68 -0
- package/content-dist/fragments/stack/react-ts-zustand-query.md +64 -0
- package/content-dist/fragments/stack/react-typescript.md +73 -0
- package/content-dist/fragments/stack/remix-express-full.md +63 -0
- package/content-dist/fragments/stack/remix-typescript.md +66 -0
- package/content-dist/fragments/stack/rust-axum.md +63 -0
- package/content-dist/fragments/stack/serverless-lambda.md +65 -0
- package/content-dist/fragments/stack/spring-boot.md +63 -0
- package/content-dist/fragments/stack/supabase-nextjs.md +64 -0
- package/content-dist/fragments/stack/svelte-sveltekit.md +67 -0
- package/content-dist/fragments/stack/t3-stack.md +63 -0
- package/content-dist/fragments/stack/terraform-aws.md +65 -0
- package/content-dist/fragments/stack/turborepo-monorepo.md +61 -0
- package/content-dist/fragments/stack/vector-search-pinecone.md +63 -0
- package/content-dist/fragments/stack/vps-deploy-producao.md +64 -0
- package/content-dist/fragments/stack/vscode-extension.md +64 -0
- package/content-dist/fragments/stack/vue3-pinia-vite.md +65 -0
- package/content-dist/fragments/stack/wordpress.md +63 -0
- package/content-dist/skills/invi-commit/SKILL.md +85 -0
- package/content-dist/skills/invi-journal/SKILL.md +67 -0
- package/content-dist/skills/invi-map/SKILL.md +118 -0
- package/content-dist/skills/invi-mode/SKILL.md +176 -0
- package/content-dist/skills/invi-pr/SKILL.md +142 -0
- package/content-dist/skills/invi-qa/SKILL.md +75 -0
- package/content-dist/skills/invi-refactor-legacy/SKILL.md +90 -0
- package/content-dist/skills/invi-review/SKILL.md +83 -0
- package/content-dist/skills/invi-security/SKILL.md +89 -0
- package/content-dist/skills/invi-status/SKILL.md +72 -0
- package/content-dist/skills/invi-task/SKILL.md +143 -0
- package/content-dist/skills/invi-test/SKILL.md +97 -0
- package/content-dist/skills/po-handoff/SKILL.md +130 -0
- package/content-dist/skills/po-intake/SKILL.md +115 -0
- package/content-dist/skills/po-lint/SKILL.md +82 -0
- package/content-dist/skills/po-spec/SKILL.md +138 -0
- package/content-dist/skills/po-status/SKILL.md +130 -0
- package/content-dist/skills/po-verify/SKILL.md +124 -0
- package/content-dist/templates/requirements/REQ-TEMPLATE.md +110 -0
- package/content-dist/templates/requirements/constitution-TEMPLATE.md +77 -0
- package/dist/baseline.d.ts +21 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +43 -0
- package/dist/baseline.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +345 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/doctor.d.ts +31 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +173 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/export.d.ts +49 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +95 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/gate.d.ts +42 -0
- package/dist/commands/gate.d.ts.map +1 -0
- package/dist/commands/gate.js +97 -0
- package/dist/commands/gate.js.map +1 -0
- package/dist/commands/init.d.ts +88 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +540 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/journalCmd.d.ts +47 -0
- package/dist/commands/journalCmd.d.ts.map +1 -0
- package/dist/commands/journalCmd.js +89 -0
- package/dist/commands/journalCmd.js.map +1 -0
- package/dist/commands/keys.d.ts +68 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +240 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/map.d.ts +123 -0
- package/dist/commands/map.d.ts.map +1 -0
- package/dist/commands/map.js +383 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/plan.d.ts +28 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +64 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/req.d.ts +92 -0
- package/dist/commands/req.d.ts.map +1 -0
- package/dist/commands/req.js +270 -0
- package/dist/commands/req.js.map +1 -0
- package/dist/commands/review.d.ts +40 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +101 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/run.d.ts +33 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +151 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/ship.d.ts +45 -0
- package/dist/commands/ship.d.ts.map +1 -0
- package/dist/commands/ship.js +252 -0
- package/dist/commands/ship.js.map +1 -0
- package/dist/commands/status.d.ts +36 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +152 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/sync.d.ts +91 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +331 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/syncCommits.d.ts +56 -0
- package/dist/commands/syncCommits.d.ts.map +1 -0
- package/dist/commands/syncCommits.js +97 -0
- package/dist/commands/syncCommits.js.map +1 -0
- package/dist/commands/task.d.ts +108 -0
- package/dist/commands/task.d.ts.map +1 -0
- package/dist/commands/task.js +217 -0
- package/dist/commands/task.js.map +1 -0
- package/dist/commands/update.d.ts +92 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +541 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/verifyTask.d.ts +50 -0
- package/dist/commands/verifyTask.d.ts.map +1 -0
- package/dist/commands/verifyTask.js +172 -0
- package/dist/commands/verifyTask.js.map +1 -0
- package/dist/content.d.ts +128 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +177 -0
- package/dist/content.js.map +1 -0
- package/dist/detect.d.ts +122 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +594 -0
- package/dist/detect.js.map +1 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +76 -0
- package/dist/events.js.map +1 -0
- package/dist/frontmatter.d.ts +15 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +74 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/i18n/en.d.ts +421 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +443 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/index.d.ts +40 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +66 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/pt-BR.d.ts +11 -0
- package/dist/i18n/pt-BR.d.ts.map +1 -0
- package/dist/i18n/pt-BR.js +435 -0
- package/dist/i18n/pt-BR.js.map +1 -0
- package/dist/identity.d.ts +78 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +152 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +86 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +199 -0
- package/dist/insights.js.map +1 -0
- package/dist/interview.d.ts +81 -0
- package/dist/interview.d.ts.map +1 -0
- package/dist/interview.js +283 -0
- package/dist/interview.js.map +1 -0
- package/dist/inventory.d.ts +79 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +86 -0
- package/dist/inventory.js.map +1 -0
- package/dist/journal.d.ts +22 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +88 -0
- package/dist/journal.js.map +1 -0
- package/dist/migrations/legacyNames.d.ts +45 -0
- package/dist/migrations/legacyNames.d.ts.map +1 -0
- package/dist/migrations/legacyNames.js +118 -0
- package/dist/migrations/legacyNames.js.map +1 -0
- package/dist/plan.d.ts +42 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +126 -0
- package/dist/plan.js.map +1 -0
- package/dist/render/agents.d.ts +327 -0
- package/dist/render/agents.d.ts.map +1 -0
- package/dist/render/agents.js +356 -0
- package/dist/render/agents.js.map +1 -0
- package/dist/render/claudeMd.d.ts +29 -0
- package/dist/render/claudeMd.d.ts.map +1 -0
- package/dist/render/claudeMd.js +110 -0
- package/dist/render/claudeMd.js.map +1 -0
- package/dist/render/githooks.d.ts +41 -0
- package/dist/render/githooks.d.ts.map +1 -0
- package/dist/render/githooks.js +168 -0
- package/dist/render/githooks.js.map +1 -0
- package/dist/render/markers.d.ts +13 -0
- package/dist/render/markers.d.ts.map +1 -0
- package/dist/render/markers.js +35 -0
- package/dist/render/markers.js.map +1 -0
- package/dist/render/requirements.d.ts +56 -0
- package/dist/render/requirements.d.ts.map +1 -0
- package/dist/render/requirements.js +86 -0
- package/dist/render/requirements.js.map +1 -0
- package/dist/render/settings.d.ts +43 -0
- package/dist/render/settings.d.ts.map +1 -0
- package/dist/render/settings.js +94 -0
- package/dist/render/settings.js.map +1 -0
- package/dist/render/transparency.d.ts +7 -0
- package/dist/render/transparency.d.ts.map +1 -0
- package/dist/render/transparency.js +164 -0
- package/dist/render/transparency.js.map +1 -0
- package/dist/requirements.d.ts +84 -0
- package/dist/requirements.d.ts.map +1 -0
- package/dist/requirements.js +229 -0
- package/dist/requirements.js.map +1 -0
- package/dist/sizing.d.ts +63 -0
- package/dist/sizing.d.ts.map +1 -0
- package/dist/sizing.js +104 -0
- package/dist/sizing.js.map +1 -0
- package/dist/tasks.d.ts +199 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +320 -0
- package/dist/tasks.js.map +1 -0
- package/dist/util/diff3.d.ts +26 -0
- package/dist/util/diff3.d.ts.map +1 -0
- package/dist/util/diff3.js +112 -0
- package/dist/util/diff3.js.map +1 -0
- package/dist/util/fsx.d.ts +33 -0
- package/dist/util/fsx.d.ts.map +1 -0
- package/dist/util/fsx.js +153 -0
- package/dist/util/fsx.js.map +1 -0
- package/dist/util/git.d.ts +58 -0
- package/dist/util/git.d.ts.map +1 -0
- package/dist/util/git.js +171 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/merge.d.ts +27 -0
- package/dist/util/merge.d.ts.map +1 -0
- package/dist/util/merge.js +78 -0
- package/dist/util/merge.js.map +1 -0
- package/dist/util/out.d.ts +18 -0
- package/dist/util/out.d.ts.map +1 -0
- package/dist/util/out.js +23 -0
- package/dist/util/out.js.map +1 -0
- package/dist/util/proc.d.ts +12 -0
- package/dist/util/proc.d.ts.map +1 -0
- package/dist/util/proc.js +45 -0
- package/dist/util/proc.js.map +1 -0
- package/dist/util/registry.d.ts +58 -0
- package/dist/util/registry.d.ts.map +1 -0
- package/dist/util/registry.js +240 -0
- package/dist/util/registry.js.map +1 -0
- package/dist/verify.d.ts +52 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +205 -0
- package/dist/verify.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +18 -0
- package/dist/version.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Reference: application instrumentation (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/monitoring-observability` — OpenTelemetry SDK bootstrap, RED metrics, observability middleware, structured logger. Node.js shown; the same shape applies per runtime.
|
|
4
|
+
|
|
5
|
+
## OpenTelemetry bootstrap (import first)
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// src/telemetry.ts — import BEFORE everything else in src/index.ts
|
|
9
|
+
import { NodeSDK } from '@opentelemetry/sdk-node'
|
|
10
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
|
|
11
|
+
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
|
|
12
|
+
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
|
|
13
|
+
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'
|
|
14
|
+
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'
|
|
15
|
+
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg'
|
|
16
|
+
|
|
17
|
+
const sdk = new NodeSDK({
|
|
18
|
+
traceExporter: new OTLPTraceExporter({
|
|
19
|
+
url: process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
|
|
20
|
+
}),
|
|
21
|
+
metricReader: new PeriodicExportingMetricReader({
|
|
22
|
+
exporter: new OTLPMetricExporter({
|
|
23
|
+
url: process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
|
|
24
|
+
}),
|
|
25
|
+
exportIntervalMillis: 15000,
|
|
26
|
+
}),
|
|
27
|
+
instrumentations: [
|
|
28
|
+
new HttpInstrumentation({
|
|
29
|
+
ignoreIncomingPaths: ['/healthz', '/metrics'], // never trace health checks
|
|
30
|
+
}),
|
|
31
|
+
new ExpressInstrumentation(),
|
|
32
|
+
new PgInstrumentation(),
|
|
33
|
+
],
|
|
34
|
+
serviceName: process.env.OTEL_SERVICE_NAME,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
sdk.start()
|
|
38
|
+
process.on('SIGTERM', () => sdk.shutdown())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## RED + business metrics
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// src/metrics.ts
|
|
45
|
+
import { Registry, Counter, Histogram, Gauge } from 'prom-client'
|
|
46
|
+
|
|
47
|
+
export const registry = new Registry()
|
|
48
|
+
registry.setDefaultLabels({ service: process.env.OTEL_SERVICE_NAME!, env: process.env.NODE_ENV! })
|
|
49
|
+
|
|
50
|
+
export const httpRequestsTotal = new Counter({
|
|
51
|
+
name: 'http_requests_total',
|
|
52
|
+
help: 'Total HTTP requests',
|
|
53
|
+
labelNames: ['method', 'route', 'status_code'],
|
|
54
|
+
registers: [registry],
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export const httpRequestDuration = new Histogram({
|
|
58
|
+
name: 'http_request_duration_seconds',
|
|
59
|
+
help: 'HTTP request duration in seconds',
|
|
60
|
+
labelNames: ['method', 'route', 'status_code'],
|
|
61
|
+
buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5],
|
|
62
|
+
registers: [registry],
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Business metrics live next to RED metrics
|
|
66
|
+
export const ordersProcessed = new Counter({
|
|
67
|
+
name: 'app_orders_processed_total',
|
|
68
|
+
help: 'Total orders processed',
|
|
69
|
+
labelNames: ['status'], // success | failed
|
|
70
|
+
registers: [registry],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export const dbPoolSize = new Gauge({
|
|
74
|
+
name: 'pg_pool_size',
|
|
75
|
+
help: 'PostgreSQL connection pool size',
|
|
76
|
+
labelNames: ['state'], // idle | active | waiting
|
|
77
|
+
registers: [registry],
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Observability middleware
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// src/middleware/observability.ts
|
|
85
|
+
import { Request, Response, NextFunction } from 'express'
|
|
86
|
+
import { httpRequestsTotal, httpRequestDuration } from '../metrics'
|
|
87
|
+
import logger from '../logger'
|
|
88
|
+
|
|
89
|
+
export function metricsMiddleware(req: Request, res: Response, next: NextFunction) {
|
|
90
|
+
const start = Date.now()
|
|
91
|
+
const route = req.route?.path || req.path
|
|
92
|
+
|
|
93
|
+
res.on('finish', () => {
|
|
94
|
+
const duration = (Date.now() - start) / 1000
|
|
95
|
+
const labels = { method: req.method, route, status_code: String(res.statusCode) }
|
|
96
|
+
|
|
97
|
+
httpRequestsTotal.inc(labels)
|
|
98
|
+
httpRequestDuration.observe(labels, duration)
|
|
99
|
+
|
|
100
|
+
logger.info({
|
|
101
|
+
type: 'http_request',
|
|
102
|
+
method: req.method,
|
|
103
|
+
path: req.path,
|
|
104
|
+
status: res.statusCode,
|
|
105
|
+
duration_ms: Math.round(duration * 1000),
|
|
106
|
+
request_id: req.headers['x-request-id'],
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
next()
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Structured logger
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// src/logger.ts — always this, never console.log()
|
|
118
|
+
import pino from 'pino'
|
|
119
|
+
|
|
120
|
+
const logger = pino({
|
|
121
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
122
|
+
...(process.env.NODE_ENV === 'development'
|
|
123
|
+
? { transport: { target: 'pino-pretty' } }
|
|
124
|
+
: {}),
|
|
125
|
+
base: {
|
|
126
|
+
service: process.env.OTEL_SERVICE_NAME,
|
|
127
|
+
env: process.env.NODE_ENV,
|
|
128
|
+
version: process.env.APP_VERSION,
|
|
129
|
+
},
|
|
130
|
+
redact: ['req.headers.authorization', 'body.password', 'body.token'],
|
|
131
|
+
serializers: { err: pino.stdSerializers.err },
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
export default logger
|
|
135
|
+
|
|
136
|
+
// logger.info({ userId, action: 'login' }, 'User authenticated')
|
|
137
|
+
// logger.error({ err, orderId }, 'Order processing failed')
|
|
138
|
+
// NEVER: logger.info('User ' + userId + ' logged in')
|
|
139
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Reference: multi-tenancy patterns (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `domain/multi-tenancy` — RLS policy SQL, tenant-context middleware, tenant-aware caching/feature flags, and transactional provisioning. Evicted from the standing fragment; read when implementing one of these mechanisms.
|
|
4
|
+
|
|
5
|
+
## Row-level security policy (PostgreSQL)
|
|
6
|
+
|
|
7
|
+
```sql
|
|
8
|
+
-- Enable RLS on the table
|
|
9
|
+
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
|
|
10
|
+
|
|
11
|
+
-- Policy: a session only sees rows belonging to its tenant
|
|
12
|
+
CREATE POLICY tenant_isolation ON orders
|
|
13
|
+
USING (tenant_id = current_setting('app.tenant_id')::uuid);
|
|
14
|
+
|
|
15
|
+
-- In the application: set the context before any query, per transaction
|
|
16
|
+
SET LOCAL app.tenant_id = '<tenant-uuid>';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`SET LOCAL` scopes the setting to the current transaction — a pooled connection can never leak one tenant's context into another tenant's query.
|
|
20
|
+
|
|
21
|
+
## Tenant-context middleware
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Resolve tenant_id on EVERY request — never trust body/query params
|
|
25
|
+
app.use(async (req, res, next) => {
|
|
26
|
+
const tenantId = await resolveTenantFromSubdomain(req.hostname);
|
|
27
|
+
// alternatives: fromJWT(req), fromHeader(req), fromPath(req)
|
|
28
|
+
if (!tenantId) return res.status(400).json({ error: 'Cannot resolve tenant' });
|
|
29
|
+
req.tenantId = tenantId;
|
|
30
|
+
// For RLS: issue SET LOCAL at the start of each transaction
|
|
31
|
+
next();
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Subdomain routing: wildcard DNS (`*.app.com` → load balancer), resolve via `req.hostname.split('.')[0]`, return a friendly 404 for unknown tenants. Custom domains map `acme.com → tenant_id` through a CNAME plus a mapping table.
|
|
36
|
+
|
|
37
|
+
## Tenant-aware caching and feature flags
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// Cache keys ALWAYS tenant-prefixed: tenant:{id}:users:{page}
|
|
41
|
+
const users = await cache.get(`tenant:${tenantId}:users:${page}`);
|
|
42
|
+
|
|
43
|
+
// Feature flags per tenant: tenant_features table
|
|
44
|
+
// { tenant_id, feature_key, enabled, config_json }
|
|
45
|
+
async function isEnabled(tenantId: string, feature: string): Promise<boolean> {
|
|
46
|
+
const cached = await redis.get(`features:${tenantId}:${feature}`);
|
|
47
|
+
if (cached !== null) return cached === '1';
|
|
48
|
+
const row = await db.tenantFeatures.findOne({ tenantId, feature });
|
|
49
|
+
const result = row?.enabled ?? false;
|
|
50
|
+
await redis.setex(`features:${tenantId}:${feature}`, 60, result ? '1' : '0');
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Short TTL (≤60s) so flag changes propagate predictably; flush tenant-prefixed keys when tenant configuration changes.
|
|
56
|
+
|
|
57
|
+
## Query discipline (wrong vs right)
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
// ❌ WRONG: returns data from ALL tenants — mass data leakage
|
|
61
|
+
const orders = await db.orders.findMany({ where: { status: 'pending' } });
|
|
62
|
+
|
|
63
|
+
// ✅ RIGHT: explicit tenant filter in every query (+ RLS as the safety net)
|
|
64
|
+
const orders = await db.orders.findMany({
|
|
65
|
+
where: { tenantId: req.tenantId, status: 'pending' },
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Transactional provisioning (wrong vs right)
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// ❌ WRONG: if step 3 fails the tenant is stranded half-provisioned
|
|
73
|
+
await createTenantSchema(tenantId);
|
|
74
|
+
await seedDefaultData(tenantId);
|
|
75
|
+
await createDefaultAdmin(tenantId); // fails here → schema exists, no admin
|
|
76
|
+
await sendWelcomeEmail(tenantId);
|
|
77
|
+
|
|
78
|
+
// ✅ RIGHT: one transaction; side effects only after it commits
|
|
79
|
+
await db.transaction(async (trx) => {
|
|
80
|
+
await createTenantSchema(tenantId, trx);
|
|
81
|
+
await seedDefaultData(tenantId, trx);
|
|
82
|
+
await createDefaultAdmin(tenantId, trx);
|
|
83
|
+
}); // automatic rollback if any step throws
|
|
84
|
+
await sendWelcomeEmail(tenantId); // side effect stays outside the transaction
|
|
85
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Reference: NestJS guards, decorators and controller usage (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/nestjs-typescript` — JWT/roles guards, custom param decorators, and how a controller consumes them.
|
|
4
|
+
|
|
5
|
+
## Guards
|
|
6
|
+
|
|
7
|
+
Guards run before interceptors and pipes; they only answer "can this pass?" — no business logic.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// src/modules/auth/guards/jwt-auth.guard.ts
|
|
11
|
+
import { Injectable, ExecutionContext } from '@nestjs/common'
|
|
12
|
+
import { AuthGuard } from '@nestjs/passport'
|
|
13
|
+
import { Reflector } from '@nestjs/core'
|
|
14
|
+
import { IS_PUBLIC_KEY } from '../decorators/public.decorator'
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
18
|
+
constructor(private reflector: Reflector) {
|
|
19
|
+
super()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
canActivate(context: ExecutionContext) {
|
|
23
|
+
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
|
24
|
+
context.getHandler(),
|
|
25
|
+
context.getClass(),
|
|
26
|
+
])
|
|
27
|
+
if (isPublic) return true
|
|
28
|
+
return super.canActivate(context)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/modules/auth/guards/roles.guard.ts
|
|
33
|
+
@Injectable()
|
|
34
|
+
export class RolesGuard implements CanActivate {
|
|
35
|
+
constructor(private reflector: Reflector) {}
|
|
36
|
+
|
|
37
|
+
canActivate(context: ExecutionContext): boolean {
|
|
38
|
+
const requiredRoles = this.reflector.getAllAndOverride<Role[]>('roles', [
|
|
39
|
+
context.getHandler(),
|
|
40
|
+
context.getClass(),
|
|
41
|
+
])
|
|
42
|
+
if (!requiredRoles?.length) return true
|
|
43
|
+
const { user } = context.switchToHttp().getRequest()
|
|
44
|
+
return requiredRoles.includes(user.role)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Custom decorators
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// src/modules/auth/decorators/current-user.decorator.ts
|
|
53
|
+
import { createParamDecorator, ExecutionContext } from '@nestjs/common'
|
|
54
|
+
|
|
55
|
+
export const CurrentUser = createParamDecorator(
|
|
56
|
+
(_data: unknown, ctx: ExecutionContext) => {
|
|
57
|
+
const request = ctx.switchToHttp().getRequest()
|
|
58
|
+
return request.user // injected by JwtStrategy.validate()
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
// src/modules/auth/decorators/roles.decorator.ts
|
|
63
|
+
import { SetMetadata } from '@nestjs/common'
|
|
64
|
+
export const Roles = (...roles: string[]) => SetMetadata('roles', roles)
|
|
65
|
+
|
|
66
|
+
// src/common/decorators/public.decorator.ts
|
|
67
|
+
import { SetMetadata } from '@nestjs/common'
|
|
68
|
+
export const IS_PUBLIC_KEY = 'isPublic'
|
|
69
|
+
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Controller usage
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// src/modules/users/users.controller.ts
|
|
76
|
+
import { Controller, Get, Patch, Body, HttpCode } from '@nestjs/common'
|
|
77
|
+
import { CurrentUser } from '../auth/decorators/current-user.decorator'
|
|
78
|
+
import { Roles } from '../auth/decorators/roles.decorator'
|
|
79
|
+
import { UpdateUserDto } from './dto/update-user.dto'
|
|
80
|
+
import { UsersService } from './users.service'
|
|
81
|
+
|
|
82
|
+
@Controller('users')
|
|
83
|
+
export class UsersController {
|
|
84
|
+
constructor(private readonly usersService: UsersService) {}
|
|
85
|
+
|
|
86
|
+
@Get('me')
|
|
87
|
+
getMe(@CurrentUser() user: AuthUser) {
|
|
88
|
+
return this.usersService.findById(user.id)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Patch('me')
|
|
92
|
+
@HttpCode(200)
|
|
93
|
+
updateMe(@CurrentUser() user: AuthUser, @Body() dto: UpdateUserDto) {
|
|
94
|
+
return this.usersService.update(user.id, dto)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Get()
|
|
98
|
+
@Roles('admin')
|
|
99
|
+
findAll() {
|
|
100
|
+
return this.usersService.findAll()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Reference: NestJS module anatomy, DTOs and global setup (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/nestjs-typescript` — module template, validated DTOs, response envelope interceptor, and the global bootstrap.
|
|
4
|
+
|
|
5
|
+
## Module template
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// src/modules/posts/posts.module.ts
|
|
9
|
+
import { Module } from '@nestjs/common'
|
|
10
|
+
import { PostsController } from './posts.controller'
|
|
11
|
+
import { PostsService } from './posts.service'
|
|
12
|
+
import { PostsRepository } from './posts.repository'
|
|
13
|
+
import { DatabaseModule } from '../../database/database.module'
|
|
14
|
+
|
|
15
|
+
@Module({
|
|
16
|
+
imports: [DatabaseModule], // only what this module needs
|
|
17
|
+
controllers: [PostsController],
|
|
18
|
+
providers: [PostsService, PostsRepository],
|
|
19
|
+
exports: [PostsService], // only export what other modules consume
|
|
20
|
+
})
|
|
21
|
+
export class PostsModule {}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Create a module when the domain has its own entity, at least one endpoint, and its own business logic. Do not create modules for utilities (→ `common/`), config providers (→ the config module), or bare database access (→ an existing module's repository).
|
|
25
|
+
|
|
26
|
+
## DTO with validation and transformation
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// src/modules/users/dto/create-user.dto.ts
|
|
30
|
+
import { IsEmail, IsString, MinLength, IsEnum, IsOptional } from 'class-validator'
|
|
31
|
+
import { Transform } from 'class-transformer'
|
|
32
|
+
|
|
33
|
+
export class CreateUserDto {
|
|
34
|
+
@IsEmail({}, { message: 'Invalid email format' })
|
|
35
|
+
@Transform(({ value }) => value?.toLowerCase().trim())
|
|
36
|
+
email: string
|
|
37
|
+
|
|
38
|
+
@IsString()
|
|
39
|
+
@MinLength(2, { message: 'Name must be at least 2 characters' })
|
|
40
|
+
name: string
|
|
41
|
+
|
|
42
|
+
@IsString()
|
|
43
|
+
@MinLength(8, { message: 'Password must be at least 8 characters' })
|
|
44
|
+
password: string
|
|
45
|
+
|
|
46
|
+
@IsEnum(['admin', 'user'], { message: 'role must be admin or user' })
|
|
47
|
+
@IsOptional()
|
|
48
|
+
role?: 'admin' | 'user' = 'user'
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Response envelope interceptor
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// src/common/interceptors/transform.interceptor.ts
|
|
56
|
+
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'
|
|
57
|
+
import { map, Observable } from 'rxjs'
|
|
58
|
+
|
|
59
|
+
export interface Response<T> {
|
|
60
|
+
data: T
|
|
61
|
+
timestamp: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Injectable()
|
|
65
|
+
export class TransformInterceptor<T> implements NestInterceptor<T, Response<T>> {
|
|
66
|
+
intercept(_context: ExecutionContext, next: CallHandler<T>): Observable<Response<T>> {
|
|
67
|
+
return next.handle().pipe(
|
|
68
|
+
map(data => ({
|
|
69
|
+
data,
|
|
70
|
+
timestamp: new Date().toISOString(),
|
|
71
|
+
})),
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Global bootstrap
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// src/main.ts
|
|
81
|
+
import { NestFactory, Reflector } from '@nestjs/core'
|
|
82
|
+
import { ValidationPipe, ClassSerializerInterceptor } from '@nestjs/common'
|
|
83
|
+
import { AppModule } from './app.module'
|
|
84
|
+
import { JwtAuthGuard } from './modules/auth/guards/jwt-auth.guard'
|
|
85
|
+
import { RolesGuard } from './modules/auth/guards/roles.guard'
|
|
86
|
+
import { TransformInterceptor } from './common/interceptors/transform.interceptor'
|
|
87
|
+
import { HttpExceptionFilter } from './common/filters/http-exception.filter'
|
|
88
|
+
|
|
89
|
+
async function bootstrap() {
|
|
90
|
+
const app = await NestFactory.create(AppModule)
|
|
91
|
+
const reflector = app.get(Reflector)
|
|
92
|
+
|
|
93
|
+
app.setGlobalPrefix('api/v1')
|
|
94
|
+
app.useGlobalPipes(new ValidationPipe({
|
|
95
|
+
whitelist: true, // strip unknown properties
|
|
96
|
+
forbidNonWhitelisted: true, // and reject them
|
|
97
|
+
transform: true,
|
|
98
|
+
}))
|
|
99
|
+
app.useGlobalGuards(new JwtAuthGuard(reflector), new RolesGuard(reflector))
|
|
100
|
+
app.useGlobalInterceptors(new ClassSerializerInterceptor(reflector), new TransformInterceptor())
|
|
101
|
+
app.useGlobalFilters(new HttpExceptionFilter())
|
|
102
|
+
|
|
103
|
+
await app.listen(process.env.PORT ?? 3000)
|
|
104
|
+
}
|
|
105
|
+
bootstrap()
|
|
106
|
+
```
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Reference: Next.js App Router patterns (read on demand)
|
|
2
|
+
|
|
3
|
+
Exemplar for `stack/nextjs-app-router` — server/client split, Server Action contract, auth middleware, metadata, testing. Read when wiring a new feature route.
|
|
4
|
+
|
|
5
|
+
## Server Component fetching + Client leaf
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// app/(dashboard)/users/page.tsx — SERVER COMPONENT (default)
|
|
9
|
+
import { db } from '@/lib/db';
|
|
10
|
+
import { users } from '@/db/schema';
|
|
11
|
+
import { UserTable } from './_components/UserTable';
|
|
12
|
+
|
|
13
|
+
export default async function UsersPage() {
|
|
14
|
+
const allUsers = await db.select().from(users).orderBy(users.createdAt);
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<h1>Users</h1>
|
|
18
|
+
<UserTable users={allUsers} />
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// app/(dashboard)/users/_components/UserTable.tsx — CLIENT LEAF
|
|
26
|
+
'use client';
|
|
27
|
+
import { useState } from 'react';
|
|
28
|
+
import type { User } from '@/db/schema';
|
|
29
|
+
|
|
30
|
+
export function UserTable({ users }: { users: User[] }) {
|
|
31
|
+
const [search, setSearch] = useState('');
|
|
32
|
+
const filtered = users.filter((u) => u.name?.includes(search));
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<input value={search} onChange={(e) => setSearch(e.target.value)} />
|
|
36
|
+
<table>{/* render filtered */}</table>
|
|
37
|
+
</>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Server Action contract (auth → validate → mutate → revalidate)
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// app/(dashboard)/users/actions.ts
|
|
46
|
+
'use server';
|
|
47
|
+
import { z } from 'zod';
|
|
48
|
+
import { eq } from 'drizzle-orm';
|
|
49
|
+
import { db } from '@/lib/db';
|
|
50
|
+
import { users } from '@/db/schema';
|
|
51
|
+
import { revalidatePath } from 'next/cache';
|
|
52
|
+
import { auth } from '@/lib/auth';
|
|
53
|
+
|
|
54
|
+
const createUserSchema = z.object({
|
|
55
|
+
name: z.string().min(2, 'Name must have at least 2 characters'),
|
|
56
|
+
email: z.string().email('Invalid email'),
|
|
57
|
+
role: z.enum(['admin', 'member']),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export async function createUser(formData: FormData) {
|
|
61
|
+
// 1. Auth check
|
|
62
|
+
const session = await auth();
|
|
63
|
+
if (!session?.user) throw new Error('Unauthorized');
|
|
64
|
+
|
|
65
|
+
// 2. Validate input
|
|
66
|
+
const parsed = createUserSchema.safeParse(Object.fromEntries(formData));
|
|
67
|
+
if (!parsed.success) return { error: parsed.error.flatten() };
|
|
68
|
+
|
|
69
|
+
// 3. DB operation
|
|
70
|
+
const [user] = await db.insert(users).values(parsed.data).returning();
|
|
71
|
+
|
|
72
|
+
// 4. Revalidate cache
|
|
73
|
+
revalidatePath('/dashboard/users');
|
|
74
|
+
return { data: user };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function deleteUser(id: string) {
|
|
78
|
+
const session = await auth();
|
|
79
|
+
if (session?.user?.role !== 'admin') throw new Error('Forbidden');
|
|
80
|
+
|
|
81
|
+
await db.delete(users).where(eq(users.id, id));
|
|
82
|
+
revalidatePath('/dashboard/users');
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Auth middleware (matcher-scoped)
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// middleware.ts (project root)
|
|
90
|
+
import { auth } from '@/lib/auth';
|
|
91
|
+
import { NextResponse } from 'next/server';
|
|
92
|
+
|
|
93
|
+
export default auth((req) => {
|
|
94
|
+
const { pathname } = req.nextUrl;
|
|
95
|
+
|
|
96
|
+
if (pathname.startsWith('/dashboard') && !req.auth) {
|
|
97
|
+
return NextResponse.redirect(new URL('/login', req.url));
|
|
98
|
+
}
|
|
99
|
+
if (pathname === '/login' && req.auth) {
|
|
100
|
+
return NextResponse.redirect(new URL('/dashboard', req.url));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const config = {
|
|
105
|
+
matcher: ['/dashboard/:path*', '/login'],
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Dynamic metadata
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// app/(public)/blog/[slug]/page.tsx
|
|
113
|
+
import type { Metadata } from 'next';
|
|
114
|
+
|
|
115
|
+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
116
|
+
const post = await getPost(params.slug);
|
|
117
|
+
return {
|
|
118
|
+
title: post.title,
|
|
119
|
+
description: post.excerpt,
|
|
120
|
+
openGraph: {
|
|
121
|
+
title: post.title,
|
|
122
|
+
images: [{ url: post.ogImage }],
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Schema conventions (one file per table)
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// db/schema/users.ts
|
|
132
|
+
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core';
|
|
133
|
+
|
|
134
|
+
export const users = pgTable('users', {
|
|
135
|
+
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
136
|
+
email: text('email').unique().notNull(),
|
|
137
|
+
name: text('name').notNull(),
|
|
138
|
+
role: text('role', { enum: ['admin', 'member'] }).default('member').notNull(),
|
|
139
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
140
|
+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export type User = typeof users.$inferSelect;
|
|
144
|
+
export type NewUser = typeof users.$inferInsert;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Testing a Server Action
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// __tests__/users/actions.test.ts
|
|
151
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
152
|
+
import { createUser } from '@/app/(dashboard)/users/actions';
|
|
153
|
+
|
|
154
|
+
vi.mock('@/lib/auth', () => ({
|
|
155
|
+
auth: vi.fn(() => ({ user: { id: '1', role: 'admin' } })),
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
vi.mock('@/lib/db', () => ({
|
|
159
|
+
db: {
|
|
160
|
+
insert: vi.fn().mockReturnThis(),
|
|
161
|
+
values: vi.fn().mockReturnThis(),
|
|
162
|
+
returning: vi.fn(() => [{ id: '2', name: 'Test', email: 'test@test.com' }]),
|
|
163
|
+
},
|
|
164
|
+
}));
|
|
165
|
+
|
|
166
|
+
describe('createUser', () => {
|
|
167
|
+
it('rejects invalid input via the schema', async () => {
|
|
168
|
+
const formData = new FormData();
|
|
169
|
+
formData.set('name', '');
|
|
170
|
+
formData.set('email', 'invalid');
|
|
171
|
+
formData.set('role', 'member');
|
|
172
|
+
|
|
173
|
+
const result = await createUser(formData);
|
|
174
|
+
expect(result.error).toBeDefined();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
```
|