nexakit 0.0.0-stage → 0.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-plugin/marketplace.json +28 -0
- package/LICENSE +26 -0
- package/README.md +79 -2
- package/agents/claude/docs-researcher.md +9 -0
- package/agents/claude/implementation-tutor.md +9 -0
- package/agents/claude/project-explorer.md +9 -0
- package/agents/claude/quality-reviewer.md +9 -0
- package/agents/claude/requirements-analyst.md +9 -0
- package/agents/claude/solution-architect.md +9 -0
- package/agents/codex/docs-researcher.toml +10 -0
- package/agents/codex/implementation-tutor.toml +10 -0
- package/agents/codex/project-explorer.toml +10 -0
- package/agents/codex/quality-reviewer.toml +10 -0
- package/agents/codex/requirements-analyst.toml +11 -0
- package/agents/codex/solution-architect.toml +10 -0
- package/assets/brand/README.md +38 -0
- package/assets/brand/agent-toolkit-mark.png +0 -0
- package/assets/brand/agent-toolkit-mark.svg +13 -0
- package/assets/brand/agent-toolkit-tui-hero.png +0 -0
- package/assets/brand/nexakit-readme-hero.png +0 -0
- package/assets/brand/nexakit-readme-hero.svg +21 -0
- package/assets/runtime/package-lock.json +1425 -0
- package/bin/agent-task.js +14 -0
- package/bin/agent-toolkit-gemini.js +13 -0
- package/bin/agent-toolkit-inbox.js +14 -0
- package/bin/agent-toolkit-mcp.js +17 -0
- package/bin/agent-toolkit.js +13 -0
- package/bin/nexakit.js +13 -0
- package/bin/project-memory-mcp.js +22 -0
- package/bin/project-memory.js +7 -0
- package/catalogs/skills/api-design-principles/LICENSE.txt +21 -0
- package/catalogs/skills/api-design-principles/SKILL.md +110 -0
- package/catalogs/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/catalogs/skills/api-design-principles/assets/rest-api-template.py +185 -0
- package/catalogs/skills/api-design-principles/references/details.md +413 -0
- package/catalogs/skills/api-design-principles/references/graphql-schema-design.md +589 -0
- package/catalogs/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/catalogs/skills/nodejs-backend-patterns/LICENSE.txt +21 -0
- package/catalogs/skills/nodejs-backend-patterns/SKILL.md +45 -0
- package/catalogs/skills/nodejs-backend-patterns/references/advanced-patterns.md +430 -0
- package/catalogs/skills/nodejs-backend-patterns/references/details.md +599 -0
- package/catalogs/skills/supabase-postgres-best-practices/CHANGELOG.md +73 -0
- package/catalogs/skills/supabase-postgres-best-practices/LICENSE.txt +21 -0
- package/catalogs/skills/supabase-postgres-best-practices/SKILL.md +64 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/_template.md +34 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
- package/catalogs/skills/vercel-composition-patterns/AGENTS.md +946 -0
- package/catalogs/skills/vercel-composition-patterns/LICENSE.txt +27 -0
- package/catalogs/skills/vercel-composition-patterns/README.md +60 -0
- package/catalogs/skills/vercel-composition-patterns/SKILL.md +89 -0
- package/catalogs/skills/vercel-composition-patterns/metadata.json +11 -0
- package/catalogs/skills/vercel-composition-patterns/rules/_sections.md +29 -0
- package/catalogs/skills/vercel-composition-patterns/rules/_template.md +24 -0
- package/catalogs/skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
- package/catalogs/skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
- package/catalogs/skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
- package/catalogs/skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
- package/catalogs/skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
- package/catalogs/skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
- package/catalogs/skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
- package/catalogs/skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
- package/catalogs/skills/vercel-react-best-practices/AGENTS.md +3810 -0
- package/catalogs/skills/vercel-react-best-practices/LICENSE.txt +27 -0
- package/catalogs/skills/vercel-react-best-practices/README.md +123 -0
- package/catalogs/skills/vercel-react-best-practices/SKILL.md +149 -0
- package/catalogs/skills/vercel-react-best-practices/metadata.json +15 -0
- package/catalogs/skills/vercel-react-best-practices/rules/_sections.md +46 -0
- package/catalogs/skills/vercel-react-best-practices/rules/_template.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-effect-event-deps.md +56 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-defer-await.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-analyzable-paths.md +63 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +60 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-flatmap-filter.md +60 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-request-idle-callback.md +105 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-resource-hints.md +85 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-script-defer-async.md +68 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-no-inline-components.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-use-deferred-value.md +59 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-hoist-static-io.md +149 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-no-shared-module-state.md +50 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +34 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
- package/catalogs/skills/webapp-testing/LICENSE.txt +202 -0
- package/catalogs/skills/webapp-testing/SKILL.md +96 -0
- package/catalogs/skills/webapp-testing/examples/console_logging.py +35 -0
- package/catalogs/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/catalogs/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/catalogs/skills/webapp-testing/scripts/with_server.py +106 -0
- package/catalogs/skills.json +1115 -0
- package/docs/skills/evidencias/2026-10-28-evaluacion-inicial-mcp-seguridad.md +118 -0
- package/docs/skills/evidencias/2026-10-28-incorporacion-mcp-seguridad.json +152 -0
- package/docs/skills/evidencias/2026-10-28-recomendador-preparacion.md +50 -0
- package/package.json +73 -4
- package/plugins/nexakit-modelo/.claude-plugin/plugin.json +1 -0
- package/plugins/nexakit-modelo/hooks/hooks.json +1 -0
- package/plugins/nexakit-modelo/hooks/register.js +48 -0
- package/plugins/nexakit-modelo/hooks/status.js +8 -0
- package/plugins/nexakit-modelo/tests/register.test.ts +21 -0
- package/plugins/nexakit-panel/.claude-plugin/plugin.json +1 -0
- package/plugins/nexakit-panel/README.md +20 -0
- package/plugins/nexakit-panel/hooks/hooks.json +1 -0
- package/plugins/nexakit-panel/hooks/lienzo.js +382 -0
- package/plugins/nexakit-panel/hooks/panel.js +279 -0
- package/plugins/nexakit-panel/hooks/register.tsx +248 -0
- package/plugins/nexakit-panel/tests/lienzo.test.ts +142 -0
- package/plugins/nexakit-panel/tests/panel.test.ts +240 -0
- package/plugins/nexakit-panel/tests/register.test.ts +167 -0
- package/plugins/nexakit-panel/types/index.d.ts +41 -0
- package/plugins/nexakit-sesion/.claude-plugin/plugin.json +1 -0
- package/plugins/nexakit-sesion/README.md +12 -0
- package/plugins/nexakit-sesion/hooks/aviso.js +38 -0
- package/plugins/nexakit-sesion/hooks/hooks.json +1 -0
- package/plugins/nexakit-sesion/hooks/register.js +28 -0
- package/plugins/nexakit-sesion/tests/register.test.ts +96 -0
- package/plugins/niveles/.claude-plugin/plugin.json +5 -0
- package/plugins/niveles/agents/nivel-alto.md +13 -0
- package/plugins/niveles/agents/nivel-exigente.md +13 -0
- package/plugins/niveles/agents/nivel-ligero.md +13 -0
- package/plugins/niveles/agents/nivel-normal.md +13 -0
- package/schemas/agent-client-adapter.schema.json +786 -0
- package/schemas/agent-client-auth-diagnostic.schema.json +801 -0
- package/schemas/agent-client-isolated-variant.schema.json +105 -0
- package/schemas/agent-client-isolated-verification.schema.json +99 -0
- package/schemas/agent-client-managed-preferences-invocation.schema.json +67 -0
- package/schemas/agent-client-managed-preferences.schema.json +63 -0
- package/schemas/agent-client-native-diagnostics.schema.json +85 -0
- package/schemas/agent-client-native-evaluation.schema.json +171 -0
- package/schemas/agent-client-native-preflight.schema.json +90 -0
- package/schemas/agent-client-output.schema.json +551 -0
- package/schemas/agent-client-runtime-fixture.schema.json +90 -0
- package/schemas/agent-client-runtime-local.schema.json +95 -0
- package/schemas/agent-client-runtime.schema.json +1288 -0
- package/schemas/agent-client-selective-config.schema.json +77 -0
- package/schemas/agent-client-supervised-local.schema.json +135 -0
- package/schemas/agent-client-supervised.schema.json +186 -0
- package/schemas/agent-model-preference.schema.json +573 -0
- package/schemas/agent-model-selection.schema.json +311 -0
- package/schemas/agent-task-approvals.schema.json +362 -0
- package/schemas/agent-task-prepare.schema.json +1324 -0
- package/schemas/agent-task-verify.schema.json +198 -0
- package/schemas/project-memory-update.schema.json +33 -0
- package/schemas/project-memory.schema.json +298 -0
- package/schemas/skill-catalog.schema.json +246 -0
- package/schemas/task-workflow-plan-output.schema.json +35 -0
- package/scripts/prepare-package.js +6 -0
- package/scripts/validate-skill-catalog.js +41 -0
- package/skills/cerrar-avisens/SKILL.md +12 -0
- package/skills/cerrar-memoria/SKILL.md +96 -0
- package/skills/cerrar-memoria/references/cierre.md +76 -0
- package/skills/decision-records/SKILL.md +27 -0
- package/skills/decision-records/agents/openai.yaml +7 -0
- package/skills/decision-records/references/adr-template.md +35 -0
- package/skills/differential-review/LICENSE.txt +427 -0
- package/skills/differential-review/SKILL.md +225 -0
- package/skills/differential-review/adversarial.md +203 -0
- package/skills/differential-review/agents/openai.yaml +6 -0
- package/skills/differential-review/assets/trail-of-bits-mark.svg +1 -0
- package/skills/differential-review/methodology.md +234 -0
- package/skills/differential-review/patterns.md +300 -0
- package/skills/differential-review/reporting.md +369 -0
- package/skills/elegir-modelo/SKILL.md +68 -0
- package/skills/elegir-modelo/modelos.mjs +108 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +71 -0
- package/skills/gemini/SKILL.md +52 -0
- package/skills/imagen/SKILL.md +12 -0
- package/skills/investigar/SKILL.md +11 -0
- package/skills/mcp-builder/LICENSE.txt +202 -0
- package/skills/mcp-builder/SKILL.md +236 -0
- package/skills/mcp-builder/reference/evaluation.md +602 -0
- package/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/skills/mcp-builder/scripts/connections.py +151 -0
- package/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/skills/ordenar-proyecto/SKILL.md +56 -0
- package/skills/project-handoff/SKILL.md +53 -0
- package/skills/project-handoff/agents/openai.yaml +7 -0
- package/skills/project-handoff/references/handoff-template.md +35 -0
- package/skills/quality-gate/LICENSE.txt +26 -0
- package/skills/quality-gate/SKILL.md +44 -0
- package/skills/quality-gate/agents/openai.yaml +7 -0
- package/skills/quality-gate/references/review-checklist.md +42 -0
- package/skills/revisar/SKILL.md +11 -0
- package/skills/revisar-skill/LICENSE-find-skills.txt +26 -0
- package/skills/revisar-skill/SKILL.md +94 -0
- package/skills/revision-cruzada/SKILL.md +59 -0
- package/skills/web-design-guidelines/AGENTS.md +156 -0
- package/skills/web-design-guidelines/LICENSE.txt +21 -0
- package/skills/web-design-guidelines/SKILL.md +29 -0
- package/src/agent-models.js +131 -0
- package/src/brand.js +117 -0
- package/src/claude-code-runner.js +642 -0
- package/src/cli-executable.js +88 -0
- package/src/cli.js +778 -0
- package/src/client-adapter-plan.js +271 -0
- package/src/client-auth-diagnostic-parser.js +211 -0
- package/src/client-auth-diagnostic.js +257 -0
- package/src/client-isolated-variant.js +106 -0
- package/src/client-isolated-verification.js +130 -0
- package/src/client-local-platform.js +14 -0
- package/src/client-managed-preferences-invocation.js +209 -0
- package/src/client-managed-preferences.js +78 -0
- package/src/client-native-access.js +134 -0
- package/src/client-native-diagnostics.js +253 -0
- package/src/client-native-evaluation.js +106 -0
- package/src/client-native-preflight-files.js +68 -0
- package/src/client-native-preflight.js +95 -0
- package/src/client-output-json.js +118 -0
- package/src/client-output-parser.js +278 -0
- package/src/client-runtime-admission.js +80 -0
- package/src/client-runtime-coordinator.js +70 -0
- package/src/client-runtime-core.js +92 -0
- package/src/client-runtime-fixture-permit.js +20 -0
- package/src/client-runtime-fixture-protocol.js +39 -0
- package/src/client-runtime-state.js +67 -0
- package/src/client-runtime-store-files.js +91 -0
- package/src/client-runtime-store.js +239 -0
- package/src/client-runtime-supervisor.js +146 -0
- package/src/client-selective-config.js +195 -0
- package/src/client-selective-files.js +126 -0
- package/src/client-supervised-codes.js +32 -0
- package/src/client-supervised-contract.js +52 -0
- package/src/client-supervised-coordinator.js +36 -0
- package/src/client-supervised-permit.js +20 -0
- package/src/client-supervised-protocol.js +37 -0
- package/src/client-supervised-store.js +167 -0
- package/src/client-supervised-supervisor.js +167 -0
- package/src/client-supervised.js +160 -0
- package/src/codex-cli-runner.js +358 -0
- package/src/codex-delivery.js +101 -0
- package/src/connect.js +703 -0
- package/src/doctor.js +795 -0
- package/src/gemini-cli.js +76 -0
- package/src/gemini-files.js +45 -0
- package/src/gemini-tools.js +249 -0
- package/src/init.js +473 -0
- package/src/install-lock.js +127 -0
- package/src/install-registry.js +61 -0
- package/src/legacy-repair.js +71 -0
- package/src/level-agents.js +111 -0
- package/src/link-states.js +172 -0
- package/src/memory-connection-artifacts.js +192 -0
- package/src/memory-connection-descriptor.js +158 -0
- package/src/memory-connection-diagnostic.js +177 -0
- package/src/memory-connection-files.js +191 -0
- package/src/memory-connection-manifest.js +118 -0
- package/src/memory-connection-package.js +176 -0
- package/src/memory-connection-plan.js +211 -0
- package/src/memory-connection-skill.js +211 -0
- package/src/memory-connection-toml.js +153 -0
- package/src/memory-locator.js +118 -0
- package/src/memory-mcp-policy.js +181 -0
- package/src/memory-mcp-server.js +166 -0
- package/src/memory-mcp-transport.js +59 -0
- package/src/missing-dependencies.js +21 -0
- package/src/model-command.js +147 -0
- package/src/model-preference.js +235 -0
- package/src/model-selection.js +368 -0
- package/src/native/managed-preferences.c +100 -0
- package/src/native/managed-preferences.h +17 -0
- package/src/package-lock-path.js +13 -0
- package/src/panel-cli.js +182 -0
- package/src/peer-handoff.js +27 -0
- package/src/peer-inbox-cli.js +211 -0
- package/src/peer-review-mcp.js +210 -0
- package/src/peer-review-store.js +532 -0
- package/src/platform.js +24 -0
- package/src/project-root.js +41 -0
- package/src/project-signals.js +339 -0
- package/src/recommend-report.js +77 -0
- package/src/review-instructions.js +211 -0
- package/src/review-policy.js +35 -0
- package/src/revision-adapters.js +157 -0
- package/src/revision-context.js +86 -0
- package/src/revision-isolation.js +222 -0
- package/src/revision-process.js +103 -0
- package/src/revision-provenance.js +89 -0
- package/src/revision-snapshot.js +120 -0
- package/src/revision.js +242 -0
- package/src/runtime-fixtures/runtime-supervisor/child.cjs +3 -0
- package/src/runtime-fixtures/runtime-supervisor/fixture.cjs +49 -0
- package/src/runtime-fixtures/supervised/child.cjs +3 -0
- package/src/runtime-fixtures/supervised/fixture.cjs +47 -0
- package/src/sensitive-data.js +21 -0
- package/src/setup-apply.js +231 -0
- package/src/setup-plan.js +231 -0
- package/src/setup-state.js +277 -0
- package/src/setup-tui.js +555 -0
- package/src/skill-catalog-add.js +91 -0
- package/src/skill-catalog-audit.js +68 -0
- package/src/skill-catalog.js +170 -0
- package/src/skill-files.js +39 -0
- package/src/skill-recommendations.js +1673 -0
- package/src/skill-scan-report.js +14 -0
- package/src/skill-scan.js +178 -0
- package/src/stable-command.js +53 -0
- package/src/stable-install.js +222 -0
- package/src/status.js +200 -0
- package/src/superpowers.js +133 -0
- package/src/sync-apply.js +227 -0
- package/src/sync-files.js +109 -0
- package/src/sync-inspect.js +394 -0
- package/src/sync-ledger.js +94 -0
- package/src/sync-markdown.js +151 -0
- package/src/sync-proposal.js +84 -0
- package/src/sync-record.js +459 -0
- package/src/sync.js +360 -0
- package/src/task-approvals.js +367 -0
- package/src/task-cli.js +79 -0
- package/src/task-external-verifier.js +584 -0
- package/src/task-prepare-files.js +115 -0
- package/src/task-prepare.js +180 -0
- package/src/task-verify-cli.js +67 -0
- package/src/task-verify-files.js +188 -0
- package/src/task-verify.js +118 -0
- package/src/task-workflow-mcp.js +544 -0
- package/src/task-workflow-store.js +254 -0
- package/src/terminal-text.js +68 -0
- package/src/toolkit-cli.js +543 -0
- package/src/toolkit-commands-guide.js +107 -0
- package/src/toolkit-setup.js +614 -0
- package/src/usage-metrics.js +43 -0
- package/templates/agent-team/01-encargo.md +158 -0
- package/templates/agent-team/02-propuesta.md +132 -0
- package/templates/agent-team/03-revision.md +150 -0
- package/templates/agent-team/README.md +213 -0
- package/templates/model-inventory/01-inventario.md +154 -0
- package/templates/model-inventory/README.md +115 -0
- package/templates/project-memory/README.md +67 -0
- package/templates/project-memory/project-memory.example.json +53 -0
- package/templates/project-memory/skill/project-id/SKILL.md +37 -0
- package/templates/project-memory/skill/project-id/references/project-profile.md +44 -0
- package/templates/project-memory/vault/00-INICIO/Estado actual.md +44 -0
- package/templates/project-memory/vault/00-INICIO/Fuentes de verdad.md +30 -0
- package/templates/project-memory/vault/00-INICIO/Inicio del proyecto.md +44 -0
- package/templates/project-memory/vault/00-INICIO/Mantenimiento de la memoria.md +26 -0
- package/templates/project-memory/vault/00-INICIO/Mapa de la memoria.md +33 -0
- package/templates/project-memory/vault/00-INICIO/Registro de sincronizaci/303/263n.md" +28 -0
- package/templates/project-memory/vault/01-PRODUCTO/Producto.md +16 -0
- package/templates/project-memory/vault/02-ARQUITECTURA/Arquitectura.md +16 -0
- package/templates/project-memory/vault/03-IMPLEMENTACION/Implementaci/303/263n.md +15 -0
- package/templates/project-memory/vault/04-DECISIONES/Decisiones.md +19 -0
- package/templates/project-memory/vault/05-ENTREGAS/Entregas.md +12 -0
- package/templates/project-memory/vault/06-OPERACION/Operaci/303/263n.md +15 -0
- package/templates/project-memory/vault/07-AGENTES/Protocolo de agentes.md +33 -0
- package/templates/project-memory/vault/08-RECURSOS/Recursos.md +12 -0
- package/templates/project-memory/vault/09-ARCHIVO/README.md +5 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
# nodejs-backend-patterns — detailed patterns and worked examples
|
|
2
|
+
|
|
3
|
+
## Core Frameworks
|
|
4
|
+
|
|
5
|
+
### Express.js - Minimalist Framework
|
|
6
|
+
|
|
7
|
+
**Basic Setup:**
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import express, { Request, Response, NextFunction } from "express";
|
|
11
|
+
import helmet from "helmet";
|
|
12
|
+
import cors from "cors";
|
|
13
|
+
import compression from "compression";
|
|
14
|
+
|
|
15
|
+
const app = express();
|
|
16
|
+
|
|
17
|
+
// Security middleware
|
|
18
|
+
app.use(helmet());
|
|
19
|
+
app.use(cors({ origin: process.env.ALLOWED_ORIGINS?.split(",") }));
|
|
20
|
+
app.use(compression());
|
|
21
|
+
|
|
22
|
+
// Body parsing
|
|
23
|
+
app.use(express.json({ limit: "10mb" }));
|
|
24
|
+
app.use(express.urlencoded({ extended: true, limit: "10mb" }));
|
|
25
|
+
|
|
26
|
+
// Request logging
|
|
27
|
+
app.use((req: Request, res: Response, next: NextFunction) => {
|
|
28
|
+
console.log(`${req.method} ${req.path}`);
|
|
29
|
+
next();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const PORT = process.env.PORT || 3000;
|
|
33
|
+
app.listen(PORT, () => {
|
|
34
|
+
console.log(`Server running on port ${PORT}`);
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Fastify - High Performance Framework
|
|
39
|
+
|
|
40
|
+
**Basic Setup:**
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import Fastify from "fastify";
|
|
44
|
+
import helmet from "@fastify/helmet";
|
|
45
|
+
import cors from "@fastify/cors";
|
|
46
|
+
import compress from "@fastify/compress";
|
|
47
|
+
|
|
48
|
+
const fastify = Fastify({
|
|
49
|
+
logger: {
|
|
50
|
+
level: process.env.LOG_LEVEL || "info",
|
|
51
|
+
transport: {
|
|
52
|
+
target: "pino-pretty",
|
|
53
|
+
options: { colorize: true },
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Plugins
|
|
59
|
+
await fastify.register(helmet);
|
|
60
|
+
await fastify.register(cors, { origin: true });
|
|
61
|
+
await fastify.register(compress);
|
|
62
|
+
|
|
63
|
+
// Type-safe routes with schema validation
|
|
64
|
+
fastify.post<{
|
|
65
|
+
Body: { name: string; email: string };
|
|
66
|
+
Reply: { id: string; name: string };
|
|
67
|
+
}>(
|
|
68
|
+
"/users",
|
|
69
|
+
{
|
|
70
|
+
schema: {
|
|
71
|
+
body: {
|
|
72
|
+
type: "object",
|
|
73
|
+
required: ["name", "email"],
|
|
74
|
+
properties: {
|
|
75
|
+
name: { type: "string", minLength: 1 },
|
|
76
|
+
email: { type: "string", format: "email" },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
async (request, reply) => {
|
|
82
|
+
const { name, email } = request.body;
|
|
83
|
+
return { id: "123", name };
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
await fastify.listen({ port: 3000, host: "0.0.0.0" });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Architectural Patterns
|
|
91
|
+
|
|
92
|
+
### Pattern 1: Layered Architecture
|
|
93
|
+
|
|
94
|
+
**Structure:**
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
src/
|
|
98
|
+
├── controllers/ # Handle HTTP requests/responses
|
|
99
|
+
├── services/ # Business logic
|
|
100
|
+
├── repositories/ # Data access layer
|
|
101
|
+
├── models/ # Data models
|
|
102
|
+
├── middleware/ # Express/Fastify middleware
|
|
103
|
+
├── routes/ # Route definitions
|
|
104
|
+
├── utils/ # Helper functions
|
|
105
|
+
├── config/ # Configuration
|
|
106
|
+
└── types/ # TypeScript types
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Controller Layer:**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// controllers/user.controller.ts
|
|
113
|
+
import { Request, Response, NextFunction } from "express";
|
|
114
|
+
import { UserService } from "../services/user.service";
|
|
115
|
+
import { CreateUserDTO, UpdateUserDTO } from "../types/user.types";
|
|
116
|
+
|
|
117
|
+
export class UserController {
|
|
118
|
+
constructor(private userService: UserService) {}
|
|
119
|
+
|
|
120
|
+
async createUser(req: Request, res: Response, next: NextFunction) {
|
|
121
|
+
try {
|
|
122
|
+
const userData: CreateUserDTO = req.body;
|
|
123
|
+
const user = await this.userService.createUser(userData);
|
|
124
|
+
res.status(201).json(user);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
next(error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async getUser(req: Request, res: Response, next: NextFunction) {
|
|
131
|
+
try {
|
|
132
|
+
const { id } = req.params;
|
|
133
|
+
const user = await this.userService.getUserById(id);
|
|
134
|
+
res.json(user);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
next(error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async updateUser(req: Request, res: Response, next: NextFunction) {
|
|
141
|
+
try {
|
|
142
|
+
const { id } = req.params;
|
|
143
|
+
const updates: UpdateUserDTO = req.body;
|
|
144
|
+
const user = await this.userService.updateUser(id, updates);
|
|
145
|
+
res.json(user);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
next(error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async deleteUser(req: Request, res: Response, next: NextFunction) {
|
|
152
|
+
try {
|
|
153
|
+
const { id } = req.params;
|
|
154
|
+
await this.userService.deleteUser(id);
|
|
155
|
+
res.status(204).send();
|
|
156
|
+
} catch (error) {
|
|
157
|
+
next(error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Service Layer:**
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// services/user.service.ts
|
|
167
|
+
import { UserRepository } from "../repositories/user.repository";
|
|
168
|
+
import { CreateUserDTO, UpdateUserDTO, User } from "../types/user.types";
|
|
169
|
+
import { NotFoundError, ValidationError } from "../utils/errors";
|
|
170
|
+
import bcrypt from "bcrypt";
|
|
171
|
+
|
|
172
|
+
export class UserService {
|
|
173
|
+
constructor(private userRepository: UserRepository) {}
|
|
174
|
+
|
|
175
|
+
async createUser(userData: CreateUserDTO): Promise<User> {
|
|
176
|
+
// Validation
|
|
177
|
+
const existingUser = await this.userRepository.findByEmail(userData.email);
|
|
178
|
+
if (existingUser) {
|
|
179
|
+
throw new ValidationError("Email already exists");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Hash password
|
|
183
|
+
const hashedPassword = await bcrypt.hash(userData.password, 10);
|
|
184
|
+
|
|
185
|
+
// Create user
|
|
186
|
+
const user = await this.userRepository.create({
|
|
187
|
+
...userData,
|
|
188
|
+
password: hashedPassword,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Remove password from response
|
|
192
|
+
const { password, ...userWithoutPassword } = user;
|
|
193
|
+
return userWithoutPassword as User;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async getUserById(id: string): Promise<User> {
|
|
197
|
+
const user = await this.userRepository.findById(id);
|
|
198
|
+
if (!user) {
|
|
199
|
+
throw new NotFoundError("User not found");
|
|
200
|
+
}
|
|
201
|
+
const { password, ...userWithoutPassword } = user;
|
|
202
|
+
return userWithoutPassword as User;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async updateUser(id: string, updates: UpdateUserDTO): Promise<User> {
|
|
206
|
+
const user = await this.userRepository.update(id, updates);
|
|
207
|
+
if (!user) {
|
|
208
|
+
throw new NotFoundError("User not found");
|
|
209
|
+
}
|
|
210
|
+
const { password, ...userWithoutPassword } = user;
|
|
211
|
+
return userWithoutPassword as User;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async deleteUser(id: string): Promise<void> {
|
|
215
|
+
const deleted = await this.userRepository.delete(id);
|
|
216
|
+
if (!deleted) {
|
|
217
|
+
throw new NotFoundError("User not found");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Repository Layer:**
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
// repositories/user.repository.ts
|
|
227
|
+
import { Pool } from "pg";
|
|
228
|
+
import { CreateUserDTO, UpdateUserDTO, UserEntity } from "../types/user.types";
|
|
229
|
+
|
|
230
|
+
export class UserRepository {
|
|
231
|
+
constructor(private db: Pool) {}
|
|
232
|
+
|
|
233
|
+
async create(
|
|
234
|
+
userData: CreateUserDTO & { password: string },
|
|
235
|
+
): Promise<UserEntity> {
|
|
236
|
+
const query = `
|
|
237
|
+
INSERT INTO users (name, email, password)
|
|
238
|
+
VALUES ($1, $2, $3)
|
|
239
|
+
RETURNING id, name, email, password, created_at, updated_at
|
|
240
|
+
`;
|
|
241
|
+
const { rows } = await this.db.query(query, [
|
|
242
|
+
userData.name,
|
|
243
|
+
userData.email,
|
|
244
|
+
userData.password,
|
|
245
|
+
]);
|
|
246
|
+
return rows[0];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async findById(id: string): Promise<UserEntity | null> {
|
|
250
|
+
const query = "SELECT * FROM users WHERE id = $1";
|
|
251
|
+
const { rows } = await this.db.query(query, [id]);
|
|
252
|
+
return rows[0] || null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async findByEmail(email: string): Promise<UserEntity | null> {
|
|
256
|
+
const query = "SELECT * FROM users WHERE email = $1";
|
|
257
|
+
const { rows } = await this.db.query(query, [email]);
|
|
258
|
+
return rows[0] || null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async update(id: string, updates: UpdateUserDTO): Promise<UserEntity | null> {
|
|
262
|
+
const fields = Object.keys(updates);
|
|
263
|
+
const values = Object.values(updates);
|
|
264
|
+
|
|
265
|
+
const setClause = fields
|
|
266
|
+
.map((field, idx) => `${field} = $${idx + 2}`)
|
|
267
|
+
.join(", ");
|
|
268
|
+
|
|
269
|
+
const query = `
|
|
270
|
+
UPDATE users
|
|
271
|
+
SET ${setClause}, updated_at = CURRENT_TIMESTAMP
|
|
272
|
+
WHERE id = $1
|
|
273
|
+
RETURNING *
|
|
274
|
+
`;
|
|
275
|
+
|
|
276
|
+
const { rows } = await this.db.query(query, [id, ...values]);
|
|
277
|
+
return rows[0] || null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async delete(id: string): Promise<boolean> {
|
|
281
|
+
const query = "DELETE FROM users WHERE id = $1";
|
|
282
|
+
const { rowCount } = await this.db.query(query, [id]);
|
|
283
|
+
return rowCount > 0;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Pattern 2: Dependency Injection
|
|
289
|
+
|
|
290
|
+
Use a DI container to wire up repositories, services, and controllers. For a full container implementation, see [references/advanced-patterns.md](./advanced-patterns.md).
|
|
291
|
+
|
|
292
|
+
## Middleware Patterns
|
|
293
|
+
|
|
294
|
+
### Authentication Middleware
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
// middleware/auth.middleware.ts
|
|
298
|
+
import { Request, Response, NextFunction } from "express";
|
|
299
|
+
import jwt from "jsonwebtoken";
|
|
300
|
+
import { UnauthorizedError } from "../utils/errors";
|
|
301
|
+
|
|
302
|
+
interface JWTPayload {
|
|
303
|
+
userId: string;
|
|
304
|
+
email: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
declare global {
|
|
308
|
+
namespace Express {
|
|
309
|
+
interface Request {
|
|
310
|
+
user?: JWTPayload;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export const authenticate = async (
|
|
316
|
+
req: Request,
|
|
317
|
+
res: Response,
|
|
318
|
+
next: NextFunction,
|
|
319
|
+
) => {
|
|
320
|
+
try {
|
|
321
|
+
const token = req.headers.authorization?.replace("Bearer ", "");
|
|
322
|
+
|
|
323
|
+
if (!token) {
|
|
324
|
+
throw new UnauthorizedError("No token provided");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const payload = jwt.verify(token, process.env.JWT_SECRET!) as JWTPayload;
|
|
328
|
+
|
|
329
|
+
req.user = payload;
|
|
330
|
+
next();
|
|
331
|
+
} catch (error) {
|
|
332
|
+
next(new UnauthorizedError("Invalid token"));
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export const authorize = (...roles: string[]) => {
|
|
337
|
+
return async (req: Request, res: Response, next: NextFunction) => {
|
|
338
|
+
if (!req.user) {
|
|
339
|
+
return next(new UnauthorizedError("Not authenticated"));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Check if user has required role
|
|
343
|
+
const hasRole = roles.some((role) => req.user?.roles?.includes(role));
|
|
344
|
+
|
|
345
|
+
if (!hasRole) {
|
|
346
|
+
return next(new UnauthorizedError("Insufficient permissions"));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
next();
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Validation Middleware
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
// middleware/validation.middleware.ts
|
|
358
|
+
import { Request, Response, NextFunction } from "express";
|
|
359
|
+
import { AnyZodObject, ZodError } from "zod";
|
|
360
|
+
import { ValidationError } from "../utils/errors";
|
|
361
|
+
|
|
362
|
+
export const validate = (schema: AnyZodObject) => {
|
|
363
|
+
return async (req: Request, res: Response, next: NextFunction) => {
|
|
364
|
+
try {
|
|
365
|
+
await schema.parseAsync({
|
|
366
|
+
body: req.body,
|
|
367
|
+
query: req.query,
|
|
368
|
+
params: req.params,
|
|
369
|
+
});
|
|
370
|
+
next();
|
|
371
|
+
} catch (error) {
|
|
372
|
+
if (error instanceof ZodError) {
|
|
373
|
+
const errors = error.errors.map((err) => ({
|
|
374
|
+
field: err.path.join("."),
|
|
375
|
+
message: err.message,
|
|
376
|
+
}));
|
|
377
|
+
next(new ValidationError("Validation failed", errors));
|
|
378
|
+
} else {
|
|
379
|
+
next(error);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// Usage with Zod
|
|
386
|
+
import { z } from "zod";
|
|
387
|
+
|
|
388
|
+
const createUserSchema = z.object({
|
|
389
|
+
body: z.object({
|
|
390
|
+
name: z.string().min(1),
|
|
391
|
+
email: z.string().email(),
|
|
392
|
+
password: z.string().min(8),
|
|
393
|
+
}),
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
router.post("/users", validate(createUserSchema), userController.createUser);
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Rate Limiting Middleware
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
// middleware/rate-limit.middleware.ts
|
|
403
|
+
import rateLimit from "express-rate-limit";
|
|
404
|
+
import RedisStore from "rate-limit-redis";
|
|
405
|
+
import Redis from "ioredis";
|
|
406
|
+
|
|
407
|
+
const redis = new Redis({
|
|
408
|
+
host: process.env.REDIS_HOST,
|
|
409
|
+
port: parseInt(process.env.REDIS_PORT || "6379"),
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
export const apiLimiter = rateLimit({
|
|
413
|
+
store: new RedisStore({
|
|
414
|
+
client: redis,
|
|
415
|
+
prefix: "rl:",
|
|
416
|
+
}),
|
|
417
|
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
418
|
+
max: 100, // Limit each IP to 100 requests per windowMs
|
|
419
|
+
message: "Too many requests from this IP, please try again later",
|
|
420
|
+
standardHeaders: true,
|
|
421
|
+
legacyHeaders: false,
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
export const authLimiter = rateLimit({
|
|
425
|
+
store: new RedisStore({
|
|
426
|
+
client: redis,
|
|
427
|
+
prefix: "rl:auth:",
|
|
428
|
+
}),
|
|
429
|
+
windowMs: 15 * 60 * 1000,
|
|
430
|
+
max: 5, // Stricter limit for auth endpoints
|
|
431
|
+
skipSuccessfulRequests: true,
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Request Logging Middleware
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
// middleware/logger.middleware.ts
|
|
439
|
+
import { Request, Response, NextFunction } from "express";
|
|
440
|
+
import pino from "pino";
|
|
441
|
+
|
|
442
|
+
const logger = pino({
|
|
443
|
+
level: process.env.LOG_LEVEL || "info",
|
|
444
|
+
transport: {
|
|
445
|
+
target: "pino-pretty",
|
|
446
|
+
options: { colorize: true },
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
export const requestLogger = (
|
|
451
|
+
req: Request,
|
|
452
|
+
res: Response,
|
|
453
|
+
next: NextFunction,
|
|
454
|
+
) => {
|
|
455
|
+
const start = Date.now();
|
|
456
|
+
|
|
457
|
+
// Log response when finished
|
|
458
|
+
res.on("finish", () => {
|
|
459
|
+
const duration = Date.now() - start;
|
|
460
|
+
logger.info({
|
|
461
|
+
method: req.method,
|
|
462
|
+
url: req.url,
|
|
463
|
+
status: res.statusCode,
|
|
464
|
+
duration: `${duration}ms`,
|
|
465
|
+
userAgent: req.headers["user-agent"],
|
|
466
|
+
ip: req.ip,
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
next();
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
export { logger };
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## Error Handling
|
|
477
|
+
|
|
478
|
+
### Custom Error Classes
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
// utils/errors.ts
|
|
482
|
+
export class AppError extends Error {
|
|
483
|
+
constructor(
|
|
484
|
+
public message: string,
|
|
485
|
+
public statusCode: number = 500,
|
|
486
|
+
public isOperational: boolean = true,
|
|
487
|
+
) {
|
|
488
|
+
super(message);
|
|
489
|
+
Object.setPrototypeOf(this, AppError.prototype);
|
|
490
|
+
Error.captureStackTrace(this, this.constructor);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export class ValidationError extends AppError {
|
|
495
|
+
constructor(
|
|
496
|
+
message: string,
|
|
497
|
+
public errors?: any[],
|
|
498
|
+
) {
|
|
499
|
+
super(message, 400);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export class NotFoundError extends AppError {
|
|
504
|
+
constructor(message: string = "Resource not found") {
|
|
505
|
+
super(message, 404);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export class UnauthorizedError extends AppError {
|
|
510
|
+
constructor(message: string = "Unauthorized") {
|
|
511
|
+
super(message, 401);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export class ForbiddenError extends AppError {
|
|
516
|
+
constructor(message: string = "Forbidden") {
|
|
517
|
+
super(message, 403);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export class ConflictError extends AppError {
|
|
522
|
+
constructor(message: string) {
|
|
523
|
+
super(message, 409);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### Global Error Handler
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
// middleware/error-handler.ts
|
|
532
|
+
import { Request, Response, NextFunction } from "express";
|
|
533
|
+
import { AppError } from "../utils/errors";
|
|
534
|
+
import { logger } from "./logger.middleware";
|
|
535
|
+
|
|
536
|
+
export const errorHandler = (
|
|
537
|
+
err: Error,
|
|
538
|
+
req: Request,
|
|
539
|
+
res: Response,
|
|
540
|
+
next: NextFunction,
|
|
541
|
+
) => {
|
|
542
|
+
if (err instanceof AppError) {
|
|
543
|
+
return res.status(err.statusCode).json({
|
|
544
|
+
status: "error",
|
|
545
|
+
message: err.message,
|
|
546
|
+
...(err instanceof ValidationError && { errors: err.errors }),
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Log unexpected errors
|
|
551
|
+
logger.error({
|
|
552
|
+
error: err.message,
|
|
553
|
+
stack: err.stack,
|
|
554
|
+
url: req.url,
|
|
555
|
+
method: req.method,
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
// Don't leak error details in production
|
|
559
|
+
const message =
|
|
560
|
+
process.env.NODE_ENV === "production"
|
|
561
|
+
? "Internal server error"
|
|
562
|
+
: err.message;
|
|
563
|
+
|
|
564
|
+
res.status(500).json({
|
|
565
|
+
status: "error",
|
|
566
|
+
message,
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// Async error wrapper
|
|
571
|
+
export const asyncHandler = (
|
|
572
|
+
fn: (req: Request, res: Response, next: NextFunction) => Promise<any>,
|
|
573
|
+
) => {
|
|
574
|
+
return (req: Request, res: Response, next: NextFunction) => {
|
|
575
|
+
Promise.resolve(fn(req, res, next)).catch(next);
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
## Database Patterns
|
|
581
|
+
|
|
582
|
+
Node.js supports both SQL and NoSQL databases. Use connection pooling for all production databases.
|
|
583
|
+
|
|
584
|
+
Key patterns covered in [references/advanced-patterns.md](./advanced-patterns.md):
|
|
585
|
+
- **PostgreSQL with connection pool** — `pg` Pool configuration and graceful shutdown
|
|
586
|
+
- **MongoDB with Mongoose** — connection management and schema definition
|
|
587
|
+
- **Transaction pattern** — `BEGIN`/`COMMIT`/`ROLLBACK` with `pg` client
|
|
588
|
+
|
|
589
|
+
## Authentication & Authorization
|
|
590
|
+
|
|
591
|
+
JWT-based auth with access tokens (short-lived, 15m) and refresh tokens (7d). Full `AuthService` implementation with `bcrypt` password comparison in [references/advanced-patterns.md](./advanced-patterns.md).
|
|
592
|
+
|
|
593
|
+
## Caching Strategies
|
|
594
|
+
|
|
595
|
+
Redis-backed `CacheService` with get/set/delete/invalidatePattern, plus a `@Cacheable` decorator for method-level caching. See [references/advanced-patterns.md](./advanced-patterns.md).
|
|
596
|
+
|
|
597
|
+
## API Response Format
|
|
598
|
+
|
|
599
|
+
Standardized `ApiResponse` helper with `success`, `error`, and `paginated` static methods. See [references/advanced-patterns.md](./advanced-patterns.md).
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.6.0](https://github.com/supabase/agent-skills/compare/supabase-postgres-best-practices-v1.5.0...supabase-postgres-best-practices-v1.6.0) (2026-07-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))
|
|
9
|
+
* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* correct broken reference link in postgres best practices skill ([#58](https://github.com/supabase/agent-skills/issues/58)) ([f4e2277](https://github.com/supabase/agent-skills/commit/f4e22777fd8573537297b568c16e5a45a25927da))
|
|
15
|
+
* cover SECURITY DEFINER, auth.role() deprecation, and BOLA in security checklist ([#85](https://github.com/supabase/agent-skills/issues/85)) ([133f43e](https://github.com/supabase/agent-skills/commit/133f43e8c2ffc48823ff0630c692cabecea3e3a3))
|
|
16
|
+
* **supabase-postgres-best-practices:** make skill description trigger-rich ([#194](https://github.com/supabase/agent-skills/issues/194)) ([3291216](https://github.com/supabase/agent-skills/commit/32912161e2732c3e5001c6811a76c1f8308ed0da))
|
|
17
|
+
|
|
18
|
+
## [1.5.0](https://github.com/supabase/agent-skills/compare/supabase-postgres-best-practices-v1.4.0...supabase-postgres-best-practices-v1.5.0) (2026-07-30)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))
|
|
24
|
+
* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* correct broken reference link in postgres best practices skill ([#58](https://github.com/supabase/agent-skills/issues/58)) ([f4e2277](https://github.com/supabase/agent-skills/commit/f4e22777fd8573537297b568c16e5a45a25927da))
|
|
30
|
+
* cover SECURITY DEFINER, auth.role() deprecation, and BOLA in security checklist ([#85](https://github.com/supabase/agent-skills/issues/85)) ([133f43e](https://github.com/supabase/agent-skills/commit/133f43e8c2ffc48823ff0630c692cabecea3e3a3))
|
|
31
|
+
* **supabase-postgres-best-practices:** make skill description trigger-rich ([#194](https://github.com/supabase/agent-skills/issues/194)) ([3291216](https://github.com/supabase/agent-skills/commit/32912161e2732c3e5001c6811a76c1f8308ed0da))
|
|
32
|
+
|
|
33
|
+
## [1.4.0](https://github.com/supabase/agent-skills/compare/v1.3.0...v1.4.0) (2026-07-10)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))
|
|
39
|
+
* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* correct broken reference link in postgres best practices skill ([#58](https://github.com/supabase/agent-skills/issues/58)) ([f4e2277](https://github.com/supabase/agent-skills/commit/f4e22777fd8573537297b568c16e5a45a25927da))
|
|
45
|
+
* cover SECURITY DEFINER, auth.role() deprecation, and BOLA in security checklist ([#85](https://github.com/supabase/agent-skills/issues/85)) ([133f43e](https://github.com/supabase/agent-skills/commit/133f43e8c2ffc48823ff0630c692cabecea3e3a3))
|
|
46
|
+
|
|
47
|
+
## [1.3.0](https://github.com/supabase/agent-skills/compare/v1.2.0...v1.3.0) (2026-06-05)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))
|
|
53
|
+
* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Bug Fixes
|
|
57
|
+
|
|
58
|
+
* correct broken reference link in postgres best practices skill ([#58](https://github.com/supabase/agent-skills/issues/58)) ([f4e2277](https://github.com/supabase/agent-skills/commit/f4e22777fd8573537297b568c16e5a45a25927da))
|
|
59
|
+
* cover SECURITY DEFINER, auth.role() deprecation, and BOLA in security checklist ([#85](https://github.com/supabase/agent-skills/issues/85)) ([133f43e](https://github.com/supabase/agent-skills/commit/133f43e8c2ffc48823ff0630c692cabecea3e3a3))
|
|
60
|
+
|
|
61
|
+
## [1.2.0](https://github.com/supabase/agent-skills/compare/v1.1.1...v1.2.0) (2026-06-02)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
|
|
66
|
+
* add schema-constraints reference for safe migration patterns ([#30](https://github.com/supabase/agent-skills/issues/30)) ([9b236f3](https://github.com/supabase/agent-skills/commit/9b236f3ebd65d76a2c570f19931353da9c858d5a))
|
|
67
|
+
* using Supabase agent skills ([#12](https://github.com/supabase/agent-skills/issues/12)) ([7c2e389](https://github.com/supabase/agent-skills/commit/7c2e3894fddfde8eb6c77d2a8921904543b9be7a))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### Bug Fixes
|
|
71
|
+
|
|
72
|
+
* correct broken reference link in postgres best practices skill ([#58](https://github.com/supabase/agent-skills/issues/58)) ([f4e2277](https://github.com/supabase/agent-skills/commit/f4e22777fd8573537297b568c16e5a45a25927da))
|
|
73
|
+
* cover SECURITY DEFINER, auth.role() deprecation, and BOLA in security checklist ([#85](https://github.com/supabase/agent-skills/issues/85)) ([133f43e](https://github.com/supabase/agent-skills/commit/133f43e8c2ffc48823ff0630c692cabecea3e3a3))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Supabase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|