@polymorphism-tech/morph-spec 3.0.1 → 3.2.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/CLAUDE.md +561 -63
- package/LICENSE +72 -72
- package/README.md +275 -79
- package/bin/detect-agents.js +3 -1
- package/bin/morph-spec.js +60 -1
- package/bin/render-template.js +61 -14
- package/bin/semantic-detect-agents.js +2 -1
- package/bin/{task-manager.js → task-manager.cjs} +113 -8
- package/bin/validate-agents-skills.js +10 -4
- package/bin/validate-agents.js +4 -3
- package/docs/api/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +977 -977
- package/docs/api/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1048 -1048
- package/docs/api/scripts/collapse.js +38 -38
- package/docs/api/scripts/commonNav.js +28 -28
- package/docs/api/scripts/linenumber.js +25 -25
- package/docs/api/scripts/nav.js +12 -12
- package/docs/api/scripts/polyfill.js +3 -3
- package/docs/api/scripts/prettify/Apache-License-2.0.txt +202 -202
- package/docs/api/scripts/prettify/lang-css.js +2 -2
- package/docs/api/scripts/prettify/prettify.js +28 -28
- package/docs/api/scripts/search.js +98 -98
- package/docs/api/styles/jsdoc.css +776 -776
- package/docs/api/styles/prettify.css +80 -80
- package/docs/cli-auto-detection.md +219 -0
- package/docs/examples.md +328 -328
- package/docs/getting-started.md +3 -3
- package/docs/llm-interaction-config.md +735 -0
- package/docs/templates.md +418 -418
- package/docs/troubleshooting.md +269 -0
- package/package.json +7 -3
- package/scripts/postinstall.js +132 -132
- package/scripts/reorganize-skills.cjs +1 -1
- package/scripts/validate-agents-structure.cjs +1 -1
- package/scripts/validate-skills.cjs +2 -2
- package/src/commands/advance-phase.js +93 -2
- package/src/commands/analyze-blazor-concurrency.js +193 -193
- package/src/commands/approve.js +221 -0
- package/src/commands/capture-pattern.js +121 -0
- package/src/commands/create-story.js +5 -2
- package/src/commands/deploy.js +780 -780
- package/src/commands/detect-agents.js +4 -2
- package/src/commands/generate.js +276 -149
- package/src/commands/init.js +37 -0
- package/src/commands/lint-fluent.js +352 -352
- package/src/commands/migrate-state.js +158 -0
- package/src/commands/rollback-phase.js +185 -185
- package/src/commands/search-patterns.js +126 -0
- package/src/commands/session-summary.js +291 -291
- package/src/commands/shard-spec.js +224 -224
- package/src/commands/spawn-team.js +172 -0
- package/src/commands/sprint-status.js +250 -250
- package/src/commands/task.js +3 -3
- package/src/commands/troubleshoot.js +222 -222
- package/src/commands/update.js +36 -0
- package/src/commands/upgrade.js +346 -0
- package/src/commands/validate-blazor-state.js +210 -210
- package/src/commands/validate-blazor.js +156 -156
- package/src/commands/validate-css.js +84 -84
- package/src/commands/validate-phase.js +221 -221
- package/src/generator/.gitkeep +0 -0
- package/src/generator/config-generator.js +206 -0
- package/src/generator/templates/config.json.template +40 -0
- package/src/generator/templates/project.md.template +67 -0
- package/src/lib/blazor-concurrency-analyzer.js +288 -288
- package/src/lib/blazor-state-validator.js +291 -291
- package/src/lib/blazor-validator.js +374 -374
- package/src/lib/checkpoint-hooks.js +258 -0
- package/src/lib/context-generator.js +7 -4
- package/src/lib/css-validator.js +352 -352
- package/src/lib/design-system-generator.js +298 -298
- package/src/lib/hook-executor.js +2 -1
- package/src/lib/learning-system.js +520 -520
- package/src/lib/metadata-extractor.js +380 -0
- package/src/lib/mockup-generator.js +366 -366
- package/src/lib/phase-state-machine.js +214 -0
- package/src/lib/stack-resolver.js +148 -0
- package/src/lib/standards-context-injector.js +4 -3
- package/src/lib/state-manager.js +120 -0
- package/src/lib/team-orchestrator.js +2 -1
- package/src/lib/template-data-sources.js +325 -0
- package/src/lib/troubleshoot-grep.js +204 -194
- package/src/lib/troubleshoot-index.js +144 -144
- package/src/lib/ui-detector.js +350 -350
- package/src/lib/validation-runner.js +2 -1
- package/src/lib/validators/architecture-validator.js +387 -387
- package/src/lib/validators/content-validator.js +351 -0
- package/src/lib/validators/package-validator.js +360 -360
- package/src/lib/validators/ui-contrast-validator.js +422 -422
- package/src/llm/.gitkeep +0 -0
- package/src/llm/analyzer.js +215 -0
- package/src/llm/environment-detector.js +43 -0
- package/src/llm/few-shot-examples.js +216 -0
- package/src/llm/project-config-schema.json +188 -0
- package/src/llm/prompt-builder.js +96 -0
- package/src/llm/schema-validator.js +121 -0
- package/src/orchestrator.js +206 -0
- package/src/sanitizer/.gitkeep +0 -0
- package/src/sanitizer/context-sanitizer.js +221 -0
- package/src/sanitizer/patterns.js +163 -0
- package/src/scanner/.gitkeep +0 -0
- package/src/scanner/project-scanner.js +242 -0
- package/src/types/index.js +477 -0
- package/src/ui/.gitkeep +0 -0
- package/src/ui/diff-display.js +91 -0
- package/src/ui/interactive-wizard.js +96 -0
- package/src/ui/user-review.js +211 -0
- package/src/ui/wizard-questions.js +190 -0
- package/src/utils/file-copier.js +3 -1
- package/src/utils/logger.js +32 -32
- package/src/utils/version-checker.js +175 -175
- package/src/writer/.gitkeep +0 -0
- package/src/writer/file-writer.js +86 -0
- package/{content → stacks/blazor-azure}/.azure/README.md +2 -2
- package/{content → stacks/blazor-azure}/.azure/pipelines/pipeline-variables.yml +1 -1
- package/{content → stacks/blazor-azure}/.azure/pipelines/prod-pipeline.yml +1 -1
- package/{content → stacks/blazor-azure}/.azure/pipelines/staging-pipeline.yml +1 -1
- package/{content → stacks/blazor-azure}/.claude/commands/morph-preflight.md +227 -227
- package/{content → stacks/blazor-azure}/.claude/commands/morph-troubleshoot.md +122 -122
- package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-setup.md +1 -1
- package/{content → stacks/blazor-azure}/.morph/docs/workflows/enforcement-pipeline.md +3 -3
- package/{content → stacks/blazor-azure}/.morph/hooks/README.md +12 -12
- package/{content → stacks/blazor-azure}/.morph/standards/agent-teams-workflow.md +2 -2
- package/{content → stacks/blazor-azure}/.morph/standards/migration-guide.md +2 -2
- package/{content → stacks/blazor-azure}/.morph/templates/infra/deploy-checklist.md +426 -426
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/backend/dotnet-supabase.md +244 -0
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/frontend/nextjs-supabase.md +335 -0
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/infrastructure/easypanel-deployer.md +189 -0
- package/stacks/nextjs-supabase/.claude/skills/level-2-domains/integrations/supabase-expert.md +170 -0
- package/stacks/nextjs-supabase/.morph/config/agents.json +345 -0
- package/stacks/nextjs-supabase/.morph/config/config.template.json +92 -0
- package/stacks/nextjs-supabase/.morph/docs/easypanel-setup.md +169 -0
- package/stacks/nextjs-supabase/.morph/docs/supabase-mcp-setup.md +247 -0
- package/stacks/nextjs-supabase/.morph/examples/crud-nextjs-supabase/README.md +697 -0
- package/stacks/nextjs-supabase/.morph/examples/crud-nextjs-supabase/spec.md +85 -0
- package/stacks/nextjs-supabase/.morph/examples/crud-nextjs-supabase/tasks.md +86 -0
- package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/README.md +498 -0
- package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/decisions.md +121 -0
- package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/spec.md +138 -0
- package/stacks/nextjs-supabase/.morph/examples/saas-nextjs-supabase/tasks.md +162 -0
- package/stacks/nextjs-supabase/.morph/project.md +168 -0
- package/stacks/nextjs-supabase/.morph/standards/easypanel-deploy.md +191 -0
- package/stacks/nextjs-supabase/.morph/standards/nextjs-patterns.md +193 -0
- package/stacks/nextjs-supabase/.morph/standards/supabase-auth.md +171 -0
- package/stacks/nextjs-supabase/.morph/standards/supabase-pgvector.md +164 -0
- package/stacks/nextjs-supabase/.morph/standards/supabase-rls.md +179 -0
- package/stacks/nextjs-supabase/.morph/standards/supabase-storage.md +148 -0
- package/stacks/nextjs-supabase/.morph/templates/contracts.cs +173 -0
- package/stacks/nextjs-supabase/.morph/templates/contracts.ts +168 -0
- package/stacks/nextjs-supabase/.morph/templates/decisions.md +115 -0
- package/stacks/nextjs-supabase/.morph/templates/dockerfile-api.dockerfile +38 -0
- package/stacks/nextjs-supabase/.morph/templates/dockerfile-web.dockerfile +48 -0
- package/stacks/nextjs-supabase/.morph/templates/proposal.md +145 -0
- package/stacks/nextjs-supabase/.morph/templates/recap.md +134 -0
- package/stacks/nextjs-supabase/.morph/templates/rls-policy.sql +57 -0
- package/stacks/nextjs-supabase/.morph/templates/spec.md +231 -0
- package/stacks/nextjs-supabase/.morph/templates/supabase-migration.sql +100 -0
- package/stacks/nextjs-supabase/.morph/templates/tasks.md +257 -0
- package/stacks/nextjs-supabase/CLAUDE.md +149 -0
- package/stacks/nextjs-supabase/README.md +112 -0
- /package/{content → stacks/blazor-azure}/.azure/docs/azure-devops-setup.md +0 -0
- /package/{content → stacks/blazor-azure}/.azure/docs/branch-strategy.md +0 -0
- /package/{content → stacks/blazor-azure}/.azure/docs/local-development.md +0 -0
- /package/{content → stacks/blazor-azure}/.azure/pipelines/templates/build-dotnet.yml +0 -0
- /package/{content → stacks/blazor-azure}/.azure/pipelines/templates/deploy-app-service.yml +0 -0
- /package/{content → stacks/blazor-azure}/.azure/pipelines/templates/deploy-container-app.yml +0 -0
- /package/{content → stacks/blazor-azure}/.azure/pipelines/templates/infra-deploy.yml +0 -0
- /package/{content → stacks/blazor-azure}/.claude/commands/morph-apply.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/commands/morph-archive.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/commands/morph-deploy.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/commands/morph-infra.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/commands/morph-proposal.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/commands/morph-status.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/settings.local.json +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/code-review.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/morph-checklist.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-0-meta/simulation-checklist.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/morph-replicate.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-clarify.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-design.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-tasks.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-1-workflows/phase-uiux.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/ai-agents/ai-system-architect.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/architecture/po-pm-advisor.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/architecture/prompt-engineer.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/architecture/seo-growth-hacker.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/architecture/standards-architect.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/dotnet-senior.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/ef-modeler.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/hangfire-orchestrator.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/backend/ms-agent-expert.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/frontend/blazor-builder.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/frontend/nextjs-expert.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/frontend/ui-ux-designer.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/azure-architect.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/azure-deploy-specialist.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/bicep-architect.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/container-specialist.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/infrastructure/devops-engineer.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/asaas-financial.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/azure-identity.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/clerk-auth.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/integrations/resend-email.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/quality/code-analyzer.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-2-domains/quality/testing-specialist.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-3-technologies/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.claude/skills/level-4-patterns/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/.morphversion +0 -0
- /package/{content → stacks/blazor-azure}/.morph/archive/.gitkeep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/config/agents.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/config/config.template.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/docs/STORY-DRIVEN-DEVELOPMENT.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/docs/workflows/design-impl.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/docs/workflows/fast-track.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/docs/workflows/full-morph.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/docs/workflows/standard.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/docs/workflows/ui-refresh.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/contracts.ts +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/spec.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/api-nextjs/tasks.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/contracts.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/decisions.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/spec.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/micro-saas/tasks.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/contracts.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/spec.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/multi-agent/tasks.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/scheduled-reports/decisions.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/scheduled-reports/proposal.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/scheduled-reports/spec.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/examples/state-v3.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/features/.gitkeep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-agents.sh +0 -0
- /package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-all.sh +0 -0
- /package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-specs.sh +0 -0
- /package/{content → stacks/blazor-azure}/.morph/hooks/pre-commit-tests.sh +0 -0
- /package/{content → stacks/blazor-azure}/.morph/hooks/task-completed.js +0 -0
- /package/{content → stacks/blazor-azure}/.morph/hooks/teammate-idle.js +0 -0
- /package/{content → stacks/blazor-azure}/.morph/project.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/schemas/agent.schema.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/schemas/tasks.schema.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/specs/.gitkeep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-blazor-ui.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-production.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-setup.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/agent-framework-workflows.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/architecture.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/azure.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/coding.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/dotnet10-migration.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/fluent-ui-setup.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/passkeys-auth.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/standards/vector-search-rag.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/state.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/CONTEXT-FEATURE.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/CONTEXT.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/FluentDesignTheme.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/MudTheme.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/agent.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/clarify-questions.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/component.razor +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/contracts/Commands.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/contracts/Entities.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/contracts/Queries.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/contracts/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/contracts.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/decisions.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/design-system.css +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/.dockerignore.example +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/Dockerfile.example +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/README.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/app-insights.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/app-service.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/azure-pipelines-deploy.yml +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/container-app-env.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/container-app.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/deploy.ps1 +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/deploy.sh +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/key-vault.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/main.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/parameters.dev.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/parameters.prod.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/parameters.staging.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/sql-database.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/infra/storage.bicep +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/integrations/asaas-client.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/integrations/asaas-webhook.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/integrations/azure-identity-config.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/integrations/clerk-config.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/job.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/migration.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/proposal.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/recap.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/repository.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/saas/subscription.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/saas/tenant.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/service.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/simulation.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/spec.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/sprint-status.yaml +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/state.template.json +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/story.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/tasks.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/test.cs +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/ui-components.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/ui-design-system.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/ui-flows.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/templates/ui-mockups.md +0 -0
- /package/{content → stacks/blazor-azure}/.morph/test-infra/example.bicep +0 -0
- /package/{content → stacks/blazor-azure}/CLAUDE.md +0 -0
- /package/{content → stacks/blazor-azure}/README.md +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Supabase pgvector Standard
|
|
2
|
+
|
|
3
|
+
> Stack: Next.js 15 + Supabase + .NET Backend
|
|
4
|
+
|
|
5
|
+
## Core Rules
|
|
6
|
+
|
|
7
|
+
- ALWAYS use HNSW indexes for production (faster queries, no training required)
|
|
8
|
+
- ALWAYS match dimensions to embedding model (e.g., 1536 for text-embedding-3-small)
|
|
9
|
+
- NEVER store embeddings without an index -- full table scan at query time
|
|
10
|
+
- Use `halfvec` for large datasets to halve storage (16-bit vs 32-bit per dimension)
|
|
11
|
+
- ALWAYS use RLS on tables containing embeddings
|
|
12
|
+
|
|
13
|
+
## Setup and Table Design
|
|
14
|
+
|
|
15
|
+
```sql
|
|
16
|
+
CREATE EXTENSION IF NOT EXISTS vector;
|
|
17
|
+
|
|
18
|
+
CREATE TABLE documents (
|
|
19
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
20
|
+
user_id UUID NOT NULL REFERENCES auth.users(id),
|
|
21
|
+
title TEXT NOT NULL,
|
|
22
|
+
content TEXT NOT NULL,
|
|
23
|
+
metadata JSONB DEFAULT '{}',
|
|
24
|
+
embedding vector(1536),
|
|
25
|
+
created_at TIMESTAMPTZ DEFAULT now()
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
|
|
29
|
+
CREATE POLICY "owner_access" ON documents FOR ALL
|
|
30
|
+
USING (user_id = auth.uid()) WITH CHECK (user_id = auth.uid());
|
|
31
|
+
CREATE INDEX idx_documents_user_id ON documents (user_id);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### halfvec Optimization
|
|
35
|
+
|
|
36
|
+
| Type | Storage/dim | 1536-dim | Best for |
|
|
37
|
+
|------|------------|----------|----------|
|
|
38
|
+
| `vector` | 4 bytes | 6 KB | High precision, small datasets |
|
|
39
|
+
| `halfvec` | 2 bytes | 3 KB | Large datasets, cost optimization |
|
|
40
|
+
|
|
41
|
+
## Index Types
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
-- HNSW (recommended)
|
|
45
|
+
CREATE INDEX idx_docs_embedding ON documents
|
|
46
|
+
USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64);
|
|
47
|
+
|
|
48
|
+
-- IVFFlat (legacy, requires existing data)
|
|
49
|
+
CREATE INDEX idx_docs_ivf ON documents
|
|
50
|
+
USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Feature | HNSW | IVFFlat |
|
|
54
|
+
|---------|------|---------|
|
|
55
|
+
| Query speed | Faster | Slower |
|
|
56
|
+
| Requires training | No | Yes |
|
|
57
|
+
| Recall quality | Higher | Lower |
|
|
58
|
+
| Recommended | Yes | Only for very large datasets |
|
|
59
|
+
|
|
60
|
+
## HNSW Parameters
|
|
61
|
+
|
|
62
|
+
| Parameter | Default | Tuning |
|
|
63
|
+
|-----------|---------|--------|
|
|
64
|
+
| `m` | 16 | Higher = better recall, more memory |
|
|
65
|
+
| `ef_construction` | 64 | Higher = better index, slower build |
|
|
66
|
+
| `ef_search` | 40 | `SET hnsw.ef_search = 100;` per session |
|
|
67
|
+
|
|
68
|
+
## Distance Functions
|
|
69
|
+
|
|
70
|
+
| Operator | Function | Index Ops | Use Case |
|
|
71
|
+
|----------|----------|-----------|----------|
|
|
72
|
+
| `<=>` | Cosine distance | `vector_cosine_ops` | Normalized embeddings (most common) |
|
|
73
|
+
| `<->` | L2 (Euclidean) | `vector_l2_ops` | Spatial/positional data |
|
|
74
|
+
| `<#>` | Inner product (neg) | `vector_ip_ops` | Pre-normalized, max similarity |
|
|
75
|
+
|
|
76
|
+
## Similarity Search
|
|
77
|
+
|
|
78
|
+
```sql
|
|
79
|
+
CREATE OR REPLACE FUNCTION match_documents(
|
|
80
|
+
query_embedding vector(1536),
|
|
81
|
+
match_threshold float DEFAULT 0.78,
|
|
82
|
+
match_count int DEFAULT 10,
|
|
83
|
+
p_user_id uuid DEFAULT auth.uid()
|
|
84
|
+
) RETURNS TABLE (id uuid, title text, content text, similarity float)
|
|
85
|
+
LANGUAGE sql STABLE AS $$
|
|
86
|
+
SELECT d.id, d.title, d.content,
|
|
87
|
+
1 - (d.embedding <=> query_embedding) AS similarity
|
|
88
|
+
FROM documents d
|
|
89
|
+
WHERE d.user_id = p_user_id
|
|
90
|
+
AND 1 - (d.embedding <=> query_embedding) > match_threshold
|
|
91
|
+
ORDER BY d.embedding <=> query_embedding
|
|
92
|
+
LIMIT match_count;
|
|
93
|
+
$$;
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Hybrid Search (Vector + Full-Text)
|
|
97
|
+
|
|
98
|
+
```sql
|
|
99
|
+
CREATE OR REPLACE FUNCTION hybrid_search(
|
|
100
|
+
query_text text, query_embedding vector(1536),
|
|
101
|
+
match_count int DEFAULT 10,
|
|
102
|
+
text_weight float DEFAULT 0.3, vector_weight float DEFAULT 0.7
|
|
103
|
+
) RETURNS TABLE (id uuid, title text, content text, score float)
|
|
104
|
+
LANGUAGE sql STABLE AS $$
|
|
105
|
+
WITH vector_results AS (
|
|
106
|
+
SELECT id, title, content,
|
|
107
|
+
1 - (embedding <=> query_embedding) AS vector_score
|
|
108
|
+
FROM documents WHERE user_id = auth.uid()
|
|
109
|
+
ORDER BY embedding <=> query_embedding LIMIT match_count * 2
|
|
110
|
+
),
|
|
111
|
+
text_results AS (
|
|
112
|
+
SELECT id, title, content,
|
|
113
|
+
ts_rank(to_tsvector('english', content), plainto_tsquery('english', query_text)) AS text_score
|
|
114
|
+
FROM documents WHERE user_id = auth.uid()
|
|
115
|
+
AND to_tsvector('english', content) @@ plainto_tsquery('english', query_text)
|
|
116
|
+
LIMIT match_count * 2
|
|
117
|
+
)
|
|
118
|
+
SELECT COALESCE(v.id, t.id), COALESCE(v.title, t.title), COALESCE(v.content, t.content),
|
|
119
|
+
(COALESCE(v.vector_score, 0) * vector_weight + COALESCE(t.text_score, 0) * text_weight)
|
|
120
|
+
FROM vector_results v FULL OUTER JOIN text_results t ON v.id = t.id
|
|
121
|
+
ORDER BY score DESC LIMIT match_count;
|
|
122
|
+
$$;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## .NET Integration (Npgsql)
|
|
126
|
+
|
|
127
|
+
```csharp
|
|
128
|
+
public sealed class DocumentRepository(AppDbContext db)
|
|
129
|
+
{
|
|
130
|
+
public async Task StoreEmbeddingAsync(
|
|
131
|
+
Guid documentId, float[] embedding, CancellationToken ct = default)
|
|
132
|
+
{
|
|
133
|
+
await db.Database.ExecuteSqlInterpolatedAsync(
|
|
134
|
+
$"UPDATE documents SET embedding = {new Vector(embedding)} WHERE id = {documentId}", ct);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public async Task<List<DocumentMatch>> SearchSimilarAsync(
|
|
138
|
+
float[] queryEmbedding, int limit = 10, float threshold = 0.78f,
|
|
139
|
+
CancellationToken ct = default)
|
|
140
|
+
{
|
|
141
|
+
return await db.Database.SqlQuery<DocumentMatch>($"""
|
|
142
|
+
SELECT id, title, content,
|
|
143
|
+
1 - (embedding <=> {new Vector(queryEmbedding)}::vector) AS similarity
|
|
144
|
+
FROM documents
|
|
145
|
+
WHERE 1 - (embedding <=> {new Vector(queryEmbedding)}::vector) > {threshold}
|
|
146
|
+
ORDER BY embedding <=> {new Vector(queryEmbedding)}::vector LIMIT {limit}
|
|
147
|
+
""").ToListAsync(ct);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// EF Core registration
|
|
152
|
+
builder.Services.AddDbContext<AppDbContext>(o =>
|
|
153
|
+
o.UseNpgsql(connectionString, npg => npg.UseVector()));
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Common Mistakes
|
|
157
|
+
|
|
158
|
+
| Wrong | Right | Why |
|
|
159
|
+
|-------|-------|-----|
|
|
160
|
+
| No index on embedding column | HNSW index | Full table scan, extremely slow |
|
|
161
|
+
| `ORDER BY similarity DESC` | `ORDER BY embedding <=> query ASC` | Operator returns distance, not similarity |
|
|
162
|
+
| Mixing embedding dimensions | Consistent dimensions per column | Dimension mismatch causes runtime errors |
|
|
163
|
+
| Full-precision for millions of rows | `halfvec` for large datasets | 2x storage savings, minimal quality loss |
|
|
164
|
+
| Missing RLS on embedding tables | RLS with user/tenant policies | Embeddings contain sensitive content context |
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Supabase Row Level Security Standard
|
|
2
|
+
|
|
3
|
+
> Stack: Next.js 15 + Supabase + .NET Backend
|
|
4
|
+
|
|
5
|
+
## Core Rules
|
|
6
|
+
|
|
7
|
+
- ALWAYS enable RLS on every table: `ALTER TABLE t ENABLE ROW LEVEL SECURITY`
|
|
8
|
+
- NEVER rely solely on application-level filtering — RLS is the security boundary
|
|
9
|
+
- `service_role` key bypasses ALL RLS — use only on trusted backend
|
|
10
|
+
- ALWAYS create at least one policy after enabling RLS — otherwise no rows are accessible
|
|
11
|
+
- ALWAYS add indexes on columns used in RLS policies
|
|
12
|
+
|
|
13
|
+
## Policy Syntax
|
|
14
|
+
|
|
15
|
+
### USING vs WITH CHECK
|
|
16
|
+
|
|
17
|
+
| Clause | Applies To | Purpose |
|
|
18
|
+
|--------|-----------|---------|
|
|
19
|
+
| `USING (expr)` | SELECT, UPDATE, DELETE | Filter which existing rows are visible |
|
|
20
|
+
| `WITH CHECK (expr)` | INSERT, UPDATE | Validate new/modified row data |
|
|
21
|
+
|
|
22
|
+
```sql
|
|
23
|
+
-- SELECT: only see your own rows
|
|
24
|
+
CREATE POLICY "users_select_own" ON documents
|
|
25
|
+
FOR SELECT USING (user_id = auth.uid());
|
|
26
|
+
|
|
27
|
+
-- INSERT: can only insert rows owned by you
|
|
28
|
+
CREATE POLICY "users_insert_own" ON documents
|
|
29
|
+
FOR INSERT WITH CHECK (user_id = auth.uid());
|
|
30
|
+
|
|
31
|
+
-- UPDATE: can only see AND modify your own rows
|
|
32
|
+
CREATE POLICY "users_update_own" ON documents
|
|
33
|
+
FOR UPDATE
|
|
34
|
+
USING (user_id = auth.uid())
|
|
35
|
+
WITH CHECK (user_id = auth.uid());
|
|
36
|
+
|
|
37
|
+
-- DELETE: can only delete your own rows
|
|
38
|
+
CREATE POLICY "users_delete_own" ON documents
|
|
39
|
+
FOR DELETE USING (user_id = auth.uid());
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Auth Functions
|
|
43
|
+
|
|
44
|
+
| Function | Returns | Use Case |
|
|
45
|
+
|----------|---------|----------|
|
|
46
|
+
| `auth.uid()` | UUID of authenticated user | Ownership checks |
|
|
47
|
+
| `auth.jwt()` | Full JWT claims as JSON | Custom claims, roles, tenant ID |
|
|
48
|
+
| `auth.role()` | Current role string | Distinguish anon vs authenticated |
|
|
49
|
+
|
|
50
|
+
```sql
|
|
51
|
+
-- Access custom JWT claims
|
|
52
|
+
auth.jwt() ->> 'tenant_id'
|
|
53
|
+
auth.jwt() -> 'app_metadata' ->> 'role'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Common Patterns
|
|
57
|
+
|
|
58
|
+
### 1. Ownership
|
|
59
|
+
|
|
60
|
+
```sql
|
|
61
|
+
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
|
|
62
|
+
|
|
63
|
+
CREATE POLICY "owner_all" ON documents
|
|
64
|
+
FOR ALL USING (user_id = auth.uid())
|
|
65
|
+
WITH CHECK (user_id = auth.uid());
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Tenant Isolation
|
|
69
|
+
|
|
70
|
+
```sql
|
|
71
|
+
-- Requires tenant_id in JWT app_metadata
|
|
72
|
+
CREATE POLICY "tenant_isolation" ON orders
|
|
73
|
+
FOR ALL
|
|
74
|
+
USING (tenant_id = (auth.jwt() -> 'app_metadata' ->> 'tenant_id')::uuid)
|
|
75
|
+
WITH CHECK (tenant_id = (auth.jwt() -> 'app_metadata' ->> 'tenant_id')::uuid);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Role-Based Access
|
|
79
|
+
|
|
80
|
+
```sql
|
|
81
|
+
-- Admins see everything, users see own
|
|
82
|
+
CREATE POLICY "admin_full_access" ON documents
|
|
83
|
+
FOR ALL USING (
|
|
84
|
+
auth.jwt() -> 'app_metadata' ->> 'role' = 'admin'
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
CREATE POLICY "user_own_access" ON documents
|
|
88
|
+
FOR ALL USING (user_id = auth.uid())
|
|
89
|
+
WITH CHECK (user_id = auth.uid());
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 4. Public Read, Authenticated Write
|
|
93
|
+
|
|
94
|
+
```sql
|
|
95
|
+
CREATE POLICY "public_read" ON posts
|
|
96
|
+
FOR SELECT USING (published = true);
|
|
97
|
+
|
|
98
|
+
CREATE POLICY "auth_write" ON posts
|
|
99
|
+
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 5. Team/Organization Access
|
|
103
|
+
|
|
104
|
+
```sql
|
|
105
|
+
CREATE POLICY "team_access" ON projects
|
|
106
|
+
FOR SELECT USING (
|
|
107
|
+
EXISTS (
|
|
108
|
+
SELECT 1 FROM team_members
|
|
109
|
+
WHERE team_members.team_id = projects.team_id
|
|
110
|
+
AND team_members.user_id = auth.uid()
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Index Recommendations
|
|
116
|
+
|
|
117
|
+
Always index columns used in RLS policies for performance:
|
|
118
|
+
|
|
119
|
+
```sql
|
|
120
|
+
CREATE INDEX idx_documents_user_id ON documents (user_id);
|
|
121
|
+
CREATE INDEX idx_orders_tenant_id ON orders (tenant_id);
|
|
122
|
+
CREATE INDEX idx_team_members_lookup ON team_members (team_id, user_id);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Testing RLS Policies
|
|
126
|
+
|
|
127
|
+
### Via SQL (Supabase SQL Editor)
|
|
128
|
+
|
|
129
|
+
```sql
|
|
130
|
+
-- Test as a specific user
|
|
131
|
+
SET request.jwt.claims = '{"sub": "user-uuid-here", "role": "authenticated",
|
|
132
|
+
"app_metadata": {"tenant_id": "tenant-uuid", "role": "admin"}}';
|
|
133
|
+
SET role = 'authenticated';
|
|
134
|
+
|
|
135
|
+
SELECT * FROM documents; -- should only return rows matching policy
|
|
136
|
+
|
|
137
|
+
RESET role;
|
|
138
|
+
RESET request.jwt.claims;
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Via Client (different auth contexts)
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
// Test with anon key (unauthenticated)
|
|
145
|
+
const anonClient = createClient(url, anonKey);
|
|
146
|
+
const { data } = await anonClient.from("documents").select("*");
|
|
147
|
+
// Should return empty if no public policy
|
|
148
|
+
|
|
149
|
+
// Test with authenticated user
|
|
150
|
+
const { data: userData } = await authClient.from("documents").select("*");
|
|
151
|
+
// Should return only user's rows
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Migration Pattern
|
|
155
|
+
|
|
156
|
+
```sql
|
|
157
|
+
-- migration: 001_enable_rls.sql
|
|
158
|
+
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
|
|
159
|
+
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
|
|
160
|
+
ALTER TABLE team_members ENABLE ROW LEVEL SECURITY;
|
|
161
|
+
|
|
162
|
+
-- Always pair with policies
|
|
163
|
+
CREATE POLICY "documents_owner" ON documents
|
|
164
|
+
FOR ALL USING (user_id = auth.uid())
|
|
165
|
+
WITH CHECK (user_id = auth.uid());
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Common Mistakes
|
|
169
|
+
|
|
170
|
+
| Wrong | Right | Why |
|
|
171
|
+
|-------|-------|-----|
|
|
172
|
+
| Enable RLS without policies | Enable RLS + create policies | No policies = no access at all |
|
|
173
|
+
| `FOR ALL USING (true)` | Specific conditions per operation | Grants unrestricted access, defeats RLS |
|
|
174
|
+
| UPDATE with only USING | UPDATE with USING + WITH CHECK | User could change user_id to another user |
|
|
175
|
+
| Complex subqueries in policies | Simple conditions + indexed columns | Subqueries in policies cause N+1 perf issues |
|
|
176
|
+
| Using `anon` key as service_role | Separate keys, service_role only on backend | anon key respects RLS (correct), don't confuse |
|
|
177
|
+
| RLS on some tables but not others | RLS on ALL tables with user data | Attackers target unprotected tables |
|
|
178
|
+
| `auth.uid()` without null check | `auth.uid() IS NOT NULL AND user_id = auth.uid()` | Prevents anon access when policy is permissive |
|
|
179
|
+
| Forgetting junction table RLS | RLS on junction tables too | team_members without RLS leaks membership |
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Supabase Storage Standard
|
|
2
|
+
|
|
3
|
+
> Stack: Next.js 15 + Supabase + .NET Backend
|
|
4
|
+
|
|
5
|
+
## Core Rules
|
|
6
|
+
|
|
7
|
+
- ALWAYS use RLS policies on storage.objects for access control
|
|
8
|
+
- NEVER serve private files without signed URLs
|
|
9
|
+
- ALWAYS validate file type and size before upload
|
|
10
|
+
- Public buckets: anyone can read, still need auth for write
|
|
11
|
+
- Private buckets: require signed URLs or authenticated access
|
|
12
|
+
|
|
13
|
+
## Bucket Configuration
|
|
14
|
+
|
|
15
|
+
```sql
|
|
16
|
+
-- Public bucket (avatars, logos)
|
|
17
|
+
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
|
|
18
|
+
VALUES ('avatars', 'avatars', true, 2097152, ARRAY['image/jpeg','image/png','image/webp']);
|
|
19
|
+
|
|
20
|
+
-- Private bucket (documents, reports)
|
|
21
|
+
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
|
|
22
|
+
VALUES ('documents', 'documents', false, 10485760, ARRAY['application/pdf','image/jpeg','image/png']);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
| Setting | Public Bucket | Private Bucket |
|
|
26
|
+
|---------|--------------|----------------|
|
|
27
|
+
| Read access | Anyone via URL | Signed URL or auth required |
|
|
28
|
+
| Write access | RLS policy required | RLS policy required |
|
|
29
|
+
| Use case | Avatars, public images | Documents, reports |
|
|
30
|
+
|
|
31
|
+
## Storage RLS Policies
|
|
32
|
+
|
|
33
|
+
```sql
|
|
34
|
+
-- Users upload/view/delete in their own folder
|
|
35
|
+
CREATE POLICY "user_upload" ON storage.objects FOR INSERT
|
|
36
|
+
WITH CHECK (bucket_id = 'documents' AND (storage.foldername(name))[1] = auth.uid()::text);
|
|
37
|
+
|
|
38
|
+
CREATE POLICY "user_select" ON storage.objects FOR SELECT
|
|
39
|
+
USING (bucket_id = 'documents' AND (storage.foldername(name))[1] = auth.uid()::text);
|
|
40
|
+
|
|
41
|
+
CREATE POLICY "user_delete" ON storage.objects FOR DELETE
|
|
42
|
+
USING (bucket_id = 'documents' AND (storage.foldername(name))[1] = auth.uid()::text);
|
|
43
|
+
|
|
44
|
+
-- Public bucket: anyone reads, auth users upload to own folder
|
|
45
|
+
CREATE POLICY "public_read" ON storage.objects FOR SELECT
|
|
46
|
+
USING (bucket_id = 'avatars');
|
|
47
|
+
|
|
48
|
+
CREATE POLICY "auth_upload_avatar" ON storage.objects FOR INSERT
|
|
49
|
+
WITH CHECK (bucket_id = 'avatars' AND (storage.foldername(name))[1] = auth.uid()::text);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Path Naming Convention
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
{bucket}/{user_id}/{category}/{filename}
|
|
56
|
+
avatars/{user_id}/profile.webp
|
|
57
|
+
documents/{user_id}/invoices/2026-01-invoice.pdf
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
First folder segment = user_id (enables simple RLS). Use lowercase, hyphens, include extension.
|
|
61
|
+
|
|
62
|
+
## Upload Patterns
|
|
63
|
+
|
|
64
|
+
### Browser Upload (Next.js)
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
async function uploadFile(file: File, userId: string) {
|
|
68
|
+
if (file.size > 10 * 1024 * 1024) throw new Error("File too large");
|
|
69
|
+
const allowedTypes = ["application/pdf", "image/jpeg", "image/png"];
|
|
70
|
+
if (!allowedTypes.includes(file.type)) throw new Error("Invalid type");
|
|
71
|
+
|
|
72
|
+
const path = `${userId}/uploads/${Date.now()}-${file.name}`;
|
|
73
|
+
const { data, error } = await supabase.storage
|
|
74
|
+
.from("documents")
|
|
75
|
+
.upload(path, file, { cacheControl: "3600", upsert: false, contentType: file.type });
|
|
76
|
+
if (error) throw error;
|
|
77
|
+
return data.path;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Server Upload (.NET)
|
|
82
|
+
|
|
83
|
+
```csharp
|
|
84
|
+
public sealed class StorageService(Supabase.Client client, ILogger<StorageService> logger)
|
|
85
|
+
{
|
|
86
|
+
private static readonly string[] AllowedTypes = ["application/pdf", "image/jpeg", "image/png"];
|
|
87
|
+
|
|
88
|
+
public async Task<string> UploadAsync(
|
|
89
|
+
string bucket, string path, Stream stream,
|
|
90
|
+
string contentType, CancellationToken ct = default)
|
|
91
|
+
{
|
|
92
|
+
if (!AllowedTypes.Contains(contentType))
|
|
93
|
+
throw new ValidationException($"Invalid content type: {contentType}");
|
|
94
|
+
var response = await client.Storage.From(bucket)
|
|
95
|
+
.Upload(stream, path, new FileOptions { ContentType = contentType, Upsert = false });
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Download and Signed URLs
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// Public bucket: direct URL
|
|
105
|
+
const { data } = supabase.storage.from("avatars").getPublicUrl("user-id/profile.webp");
|
|
106
|
+
|
|
107
|
+
// Private bucket: signed URL (time-limited)
|
|
108
|
+
const { data } = await supabase.storage
|
|
109
|
+
.from("documents").createSignedUrl("user-id/report.pdf", 3600); // 1 hour
|
|
110
|
+
|
|
111
|
+
// Download file content (returns Blob)
|
|
112
|
+
const { data } = await supabase.storage.from("documents").download("user-id/report.pdf");
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Image Transformations
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const { data } = supabase.storage.from("avatars").getPublicUrl("user-id/photo.jpg", {
|
|
119
|
+
transform: { width: 200, height: 200, resize: "cover", quality: 80 },
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Parameter | Options | Default |
|
|
124
|
+
|-----------|---------|---------|
|
|
125
|
+
| `width` / `height` | 1-2500 px | original |
|
|
126
|
+
| `resize` | cover, contain, fill | cover |
|
|
127
|
+
| `quality` | 20-100 | 80 |
|
|
128
|
+
| `format` | origin, avif, webp | origin |
|
|
129
|
+
|
|
130
|
+
## File Validation
|
|
131
|
+
|
|
132
|
+
| Check | Client-Side | Server-Side | Bucket Config |
|
|
133
|
+
|-------|------------|-------------|---------------|
|
|
134
|
+
| File size | `file.size` | Stream length | `file_size_limit` |
|
|
135
|
+
| MIME type | `file.type` | Content-Type | `allowed_mime_types` |
|
|
136
|
+
| Extension | File name | File name | -- |
|
|
137
|
+
|
|
138
|
+
Always validate at all three levels. Client-side can be bypassed.
|
|
139
|
+
|
|
140
|
+
## Common Mistakes
|
|
141
|
+
|
|
142
|
+
| Wrong | Right | Why |
|
|
143
|
+
|-------|-------|-----|
|
|
144
|
+
| No RLS on storage.objects | Policies for each bucket | Anyone can read/write without policies |
|
|
145
|
+
| Private files via public URL | `createSignedUrl()` | Private bucket returns 403 without auth |
|
|
146
|
+
| User-provided filename as-is | Sanitize + timestamp prefix | Path traversal attacks, collisions |
|
|
147
|
+
| `upsert: true` by default | `upsert: false` | Prevents accidental file overwrites |
|
|
148
|
+
| Files without user folder | `{user_id}/...` path pattern | Cannot write simple RLS policies |
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// CONTRACTS: {{FEATURE_NAME_TITLE}}
|
|
3
|
+
// Stack: Next.js + Supabase + .NET API
|
|
4
|
+
// Generated by MORPH Framework
|
|
5
|
+
// Date: {{DATE}}
|
|
6
|
+
// ============================================================
|
|
7
|
+
|
|
8
|
+
#region Usings
|
|
9
|
+
|
|
10
|
+
using System;
|
|
11
|
+
using System.Collections.Generic;
|
|
12
|
+
using System.Threading;
|
|
13
|
+
using System.Threading.Tasks;
|
|
14
|
+
|
|
15
|
+
#endregion
|
|
16
|
+
|
|
17
|
+
namespace {{NAMESPACE}}.Application.Features.{{FEATURE_NAME_PASCAL}};
|
|
18
|
+
|
|
19
|
+
#region Configuration
|
|
20
|
+
|
|
21
|
+
/// <summary>
|
|
22
|
+
/// Supabase configuration options.
|
|
23
|
+
/// Bind from appsettings.json "Supabase" section.
|
|
24
|
+
/// </summary>
|
|
25
|
+
public sealed record SupabaseConfig
|
|
26
|
+
{
|
|
27
|
+
public required string Url { get; init; }
|
|
28
|
+
public required string AnonKey { get; init; }
|
|
29
|
+
public required string ServiceRoleKey { get; init; }
|
|
30
|
+
public required string JwtSecret { get; init; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#endregion
|
|
34
|
+
|
|
35
|
+
#region Pagination
|
|
36
|
+
|
|
37
|
+
/// <summary>
|
|
38
|
+
/// Pagination query parameters. Use with [AsParameters] in Minimal API.
|
|
39
|
+
/// </summary>
|
|
40
|
+
public sealed record PaginationQuery(
|
|
41
|
+
int Page = 1,
|
|
42
|
+
int PageSize = 20)
|
|
43
|
+
{
|
|
44
|
+
public int Offset => (Page - 1) * PageSize;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
/// Paginated result wrapper.
|
|
49
|
+
/// </summary>
|
|
50
|
+
public sealed record PagedResult<T>(
|
|
51
|
+
List<T> Items,
|
|
52
|
+
int TotalCount,
|
|
53
|
+
int Page,
|
|
54
|
+
int PageSize)
|
|
55
|
+
{
|
|
56
|
+
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
|
57
|
+
public bool HasNext => Page < TotalPages;
|
|
58
|
+
public bool HasPrevious => Page > 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#endregion
|
|
62
|
+
|
|
63
|
+
#region Repository Interfaces
|
|
64
|
+
|
|
65
|
+
/// <summary>
|
|
66
|
+
/// Generic repository interface for Supabase/PostgreSQL data access via Dapper.
|
|
67
|
+
/// </summary>
|
|
68
|
+
public interface IRepository<T, TId>
|
|
69
|
+
{
|
|
70
|
+
Task<T?> GetByIdAsync(TId id, CancellationToken cancellationToken = default);
|
|
71
|
+
Task<List<T>> GetAllAsync(CancellationToken cancellationToken = default);
|
|
72
|
+
Task<PagedResult<T>> GetPagedAsync(PaginationQuery query, CancellationToken cancellationToken = default);
|
|
73
|
+
Task<TId> CreateAsync(T entity, CancellationToken cancellationToken = default);
|
|
74
|
+
Task UpdateAsync(T entity, CancellationToken cancellationToken = default);
|
|
75
|
+
Task DeleteAsync(TId id, CancellationToken cancellationToken = default);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#endregion
|
|
79
|
+
|
|
80
|
+
#region Service Interfaces
|
|
81
|
+
|
|
82
|
+
/// <summary>
|
|
83
|
+
/// Service for managing {{FEATURE_NAME_PASCAL}} operations.
|
|
84
|
+
/// </summary>
|
|
85
|
+
public interface I{{FEATURE_NAME_PASCAL}}Service
|
|
86
|
+
{
|
|
87
|
+
/// <summary>
|
|
88
|
+
/// Gets a {{FEATURE_NAME_PASCAL}} by its identifier.
|
|
89
|
+
/// </summary>
|
|
90
|
+
Task<{{FEATURE_NAME_PASCAL}}Dto?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
|
|
91
|
+
|
|
92
|
+
/// <summary>
|
|
93
|
+
/// Gets paginated list of {{FEATURE_NAME_PASCAL}} items.
|
|
94
|
+
/// </summary>
|
|
95
|
+
Task<PagedResult<{{FEATURE_NAME_PASCAL}}Dto>> GetPagedAsync(PaginationQuery query, Guid userId, CancellationToken cancellationToken = default);
|
|
96
|
+
|
|
97
|
+
/// <summary>
|
|
98
|
+
/// Creates a new {{FEATURE_NAME_PASCAL}}.
|
|
99
|
+
/// </summary>
|
|
100
|
+
Task<{{FEATURE_NAME_PASCAL}}Dto> CreateAsync(Create{{FEATURE_NAME_PASCAL}}Request request, Guid userId, CancellationToken cancellationToken = default);
|
|
101
|
+
|
|
102
|
+
/// <summary>
|
|
103
|
+
/// Updates an existing {{FEATURE_NAME_PASCAL}}.
|
|
104
|
+
/// </summary>
|
|
105
|
+
Task UpdateAsync(Guid id, Update{{FEATURE_NAME_PASCAL}}Request request, Guid userId, CancellationToken cancellationToken = default);
|
|
106
|
+
|
|
107
|
+
/// <summary>
|
|
108
|
+
/// Deletes a {{FEATURE_NAME_PASCAL}}.
|
|
109
|
+
/// </summary>
|
|
110
|
+
Task DeleteAsync(Guid id, Guid userId, CancellationToken cancellationToken = default);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#endregion
|
|
114
|
+
|
|
115
|
+
#region DTOs
|
|
116
|
+
|
|
117
|
+
/// <summary>
|
|
118
|
+
/// Data transfer object for {{FEATURE_NAME_PASCAL}}.
|
|
119
|
+
/// </summary>
|
|
120
|
+
public sealed record {{FEATURE_NAME_PASCAL}}Dto(
|
|
121
|
+
Guid Id,
|
|
122
|
+
string Name,
|
|
123
|
+
Guid UserId,
|
|
124
|
+
{{FEATURE_NAME_PASCAL}}Status Status,
|
|
125
|
+
DateTime CreatedAt,
|
|
126
|
+
DateTime? UpdatedAt
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
/// <summary>
|
|
130
|
+
/// Request to create a new {{FEATURE_NAME_PASCAL}}.
|
|
131
|
+
/// </summary>
|
|
132
|
+
public sealed record Create{{FEATURE_NAME_PASCAL}}Request(
|
|
133
|
+
string Name
|
|
134
|
+
// Add other required fields
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
/// <summary>
|
|
138
|
+
/// Request to update an existing {{FEATURE_NAME_PASCAL}}.
|
|
139
|
+
/// </summary>
|
|
140
|
+
public sealed record Update{{FEATURE_NAME_PASCAL}}Request(
|
|
141
|
+
string Name
|
|
142
|
+
// Add other updatable fields
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
#endregion
|
|
146
|
+
|
|
147
|
+
#region Enums
|
|
148
|
+
|
|
149
|
+
/// <summary>
|
|
150
|
+
/// Status of a {{FEATURE_NAME_PASCAL}}.
|
|
151
|
+
/// </summary>
|
|
152
|
+
public enum {{FEATURE_NAME_PASCAL}}Status
|
|
153
|
+
{
|
|
154
|
+
Draft = 0,
|
|
155
|
+
Active = 1,
|
|
156
|
+
Completed = 2,
|
|
157
|
+
Archived = 3,
|
|
158
|
+
// Error states
|
|
159
|
+
Failed = 100,
|
|
160
|
+
Cancelled = 101
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#endregion
|
|
164
|
+
|
|
165
|
+
#region Exceptions
|
|
166
|
+
|
|
167
|
+
public sealed class {{FEATURE_NAME_PASCAL}}NotFoundException(Guid id)
|
|
168
|
+
: Exception($"{{FEATURE_NAME_PASCAL}} with ID {id} was not found.");
|
|
169
|
+
|
|
170
|
+
public sealed class {{FEATURE_NAME_PASCAL}}AccessDeniedException(Guid id, Guid userId)
|
|
171
|
+
: Exception($"User {userId} does not have access to {{FEATURE_NAME_PASCAL}} {id}.");
|
|
172
|
+
|
|
173
|
+
#endregion
|