claude-code-kit 0.7.0__py3-none-any.whl
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.
- claude_code_kit-0.7.0.dist-info/METADATA +384 -0
- claude_code_kit-0.7.0.dist-info/RECORD +209 -0
- claude_code_kit-0.7.0.dist-info/WHEEL +4 -0
- claude_code_kit-0.7.0.dist-info/entry_points.txt +4 -0
- claude_code_kit-0.7.0.dist-info/licenses/LICENSE +21 -0
- claude_kit/__init__.py +10 -0
- claude_kit/__main__.py +8 -0
- claude_kit/_payload/agents/acceptance-reviewer.md +60 -0
- claude_kit/_payload/agents/auditor.md +76 -0
- claude_kit/_payload/agents/dependency-scanner.md +84 -0
- claude_kit/_payload/agents/developer.md +187 -0
- claude_kit/_payload/agents/devils-advocate.md +62 -0
- claude_kit/_payload/agents/devops-engineer.md +134 -0
- claude_kit/_payload/agents/e2e-tester.md +152 -0
- claude_kit/_payload/agents/em-reviewer.md +105 -0
- claude_kit/_payload/agents/incident-responder.md +64 -0
- claude_kit/_payload/agents/merge-reviewer.md +194 -0
- claude_kit/_payload/agents/observability-engineer.md +94 -0
- claude_kit/_payload/agents/orchestrator.md +551 -0
- claude_kit/_payload/agents/owasp-reviewer.md +76 -0
- claude_kit/_payload/agents/policy-validator.md +63 -0
- claude_kit/_payload/agents/pr-raiser.md +138 -0
- claude_kit/_payload/agents/risk-classifier.md +50 -0
- claude_kit/_payload/agents/sdlc-code-reviewer.md +196 -0
- claude_kit/_payload/agents/secret-scanner.md +70 -0
- claude_kit/_payload/agents/security-reviewer.md +80 -0
- claude_kit/_payload/agents/senior-backend-dev.md +199 -0
- claude_kit/_payload/agents/senior-frontend-dev.md +181 -0
- claude_kit/_payload/agents/senior-tester.md +206 -0
- claude_kit/_payload/agents/spec-doc-writer.md +331 -0
- claude_kit/_payload/agents/story-planner.md +56 -0
- claude_kit/_payload/agents/technical-architect.md +139 -0
- claude_kit/_payload/agents/tester.md +193 -0
- claude_kit/_payload/agents/ui-designer.md +73 -0
- claude_kit/_payload/agents/unit-tester.md +119 -0
- claude_kit/_payload/catalog/mcp.yaml +54 -0
- claude_kit/_payload/catalog/org.yaml +145 -0
- claude_kit/_payload/catalog/profiles.yaml +96 -0
- claude_kit/_payload/catalog/stacks.yaml +96 -0
- claude_kit/_payload/commands/init.md +36 -0
- claude_kit/_payload/commands/sdlc.md +18 -0
- claude_kit/_payload/commands/status.md +20 -0
- claude_kit/_payload/hooks/hooks.json +58 -0
- claude_kit/_payload/hooks/scripts/audit-log.sh +18 -0
- claude_kit/_payload/hooks/scripts/guard-secrets.sh +26 -0
- claude_kit/_payload/hooks/scripts/lint-fix.sh +38 -0
- claude_kit/_payload/hooks/scripts/load-continuity.sh +32 -0
- claude_kit/_payload/hooks/scripts/load-learnings.sh +40 -0
- claude_kit/_payload/hooks/scripts/type-check.sh +23 -0
- claude_kit/_payload/hooks/scripts/validate-frontmatter.sh +34 -0
- claude_kit/_payload/hooks/scripts/validate-settings.sh +21 -0
- claude_kit/_payload/hooks/scripts/warn-large-edits.sh +24 -0
- claude_kit/_payload/hooks/scripts/warn-missing-tests.sh +24 -0
- claude_kit/_payload/hooks/scripts/warn-sensitive-files.sh +30 -0
- claude_kit/_payload/hooks/scripts/warn-shared-modules.sh +33 -0
- claude_kit/_payload/rules/agent-guardrails.md +83 -0
- claude_kit/_payload/rules/agent-memory.md +106 -0
- claude_kit/_payload/rules/agent-resilience.md +61 -0
- claude_kit/_payload/rules/autonomy-levels.md +30 -0
- claude_kit/_payload/rules/code-organization.md +312 -0
- claude_kit/_payload/rules/continuity.md +84 -0
- claude_kit/_payload/rules/design-patterns.md +422 -0
- claude_kit/_payload/rules/devops-observability.md +57 -0
- claude_kit/_payload/rules/documentation.md +326 -0
- claude_kit/_payload/rules/evals.md +62 -0
- claude_kit/_payload/rules/frontend-best-practices.md +157 -0
- claude_kit/_payload/rules/goal-setting-and-monitoring.md +72 -0
- claude_kit/_payload/rules/human-in-the-loop.md +64 -0
- claude_kit/_payload/rules/linting-and-formatting.md +220 -0
- claude_kit/_payload/rules/mandatory-workflow.md +309 -0
- claude_kit/_payload/rules/model-tiers.md +34 -0
- claude_kit/_payload/rules/quality-gates.md +107 -0
- claude_kit/_payload/rules/rarv-cycle.md +31 -0
- claude_kit/_payload/rules/reasoning-techniques.md +62 -0
- claude_kit/_payload/rules/responsive-and-accessibility.md +353 -0
- claude_kit/_payload/rules/risk-classification.md +36 -0
- claude_kit/_payload/rules/testing.md +417 -0
- claude_kit/_payload/rules/tool-design.md +66 -0
- claude_kit/_payload/skills/_references/accessibility-checklist.md +160 -0
- claude_kit/_payload/skills/_references/orchestration-patterns.md +405 -0
- claude_kit/_payload/skills/_references/performance-checklist.md +153 -0
- claude_kit/_payload/skills/_references/security-checklist.md +134 -0
- claude_kit/_payload/skills/_references/testing-patterns.md +236 -0
- claude_kit/_payload/skills/accessibility-review/SKILL.md +56 -0
- claude_kit/_payload/skills/api-and-interface-design/SKILL.md +294 -0
- claude_kit/_payload/skills/api-integration/SKILL.md +348 -0
- claude_kit/_payload/skills/archive-sprint/SKILL.md +31 -0
- claude_kit/_payload/skills/backlog/SKILL.md +41 -0
- claude_kit/_payload/skills/backlog/item-template.md +20 -0
- claude_kit/_payload/skills/browser-testing-with-devtools/SKILL.md +302 -0
- claude_kit/_payload/skills/ci-cd-and-automation/SKILL.md +402 -0
- claude_kit/_payload/skills/code-review-and-quality/SKILL.md +347 -0
- claude_kit/_payload/skills/code-simplification/SKILL.md +331 -0
- claude_kit/_payload/skills/component-design/SKILL.md +171 -0
- claude_kit/_payload/skills/consolidate-learnings/SKILL.md +55 -0
- claude_kit/_payload/skills/context-engineering/SKILL.md +321 -0
- claude_kit/_payload/skills/debugging-and-error-recovery/SKILL.md +300 -0
- claude_kit/_payload/skills/decision/SKILL.md +46 -0
- claude_kit/_payload/skills/decision/adr-template.md +36 -0
- claude_kit/_payload/skills/deprecation-and-migration/SKILL.md +207 -0
- claude_kit/_payload/skills/documentation-and-adrs/SKILL.md +299 -0
- claude_kit/_payload/skills/doubt-driven-development/SKILL.md +243 -0
- claude_kit/_payload/skills/execute/SKILL.md +27 -0
- claude_kit/_payload/skills/frontend-ui-engineering/SKILL.md +328 -0
- claude_kit/_payload/skills/git-workflow-and-versioning/SKILL.md +300 -0
- claude_kit/_payload/skills/idea-refine/SKILL.md +178 -0
- claude_kit/_payload/skills/idea-refine/examples.md +238 -0
- claude_kit/_payload/skills/idea-refine/frameworks.md +99 -0
- claude_kit/_payload/skills/idea-refine/refinement-criteria.md +113 -0
- claude_kit/_payload/skills/idea-refine/scripts/idea-refine.sh +15 -0
- claude_kit/_payload/skills/incident-postmortem/SKILL.md +74 -0
- claude_kit/_payload/skills/incremental-implementation/SKILL.md +245 -0
- claude_kit/_payload/skills/interview-me/SKILL.md +221 -0
- claude_kit/_payload/skills/load-testing/SKILL.md +83 -0
- claude_kit/_payload/skills/manual-test/SKILL.md +516 -0
- claude_kit/_payload/skills/performance-optimization/SKILL.md +277 -0
- claude_kit/_payload/skills/planning-and-task-breakdown/SKILL.md +223 -0
- claude_kit/_payload/skills/playwright-verification/SKILL.md +205 -0
- claude_kit/_payload/skills/refresh-docs/SKILL.md +63 -0
- claude_kit/_payload/skills/remember/SKILL.md +96 -0
- claude_kit/_payload/skills/scope/SKILL.md +52 -0
- claude_kit/_payload/skills/scope/scope-template.md +82 -0
- claude_kit/_payload/skills/sdlc/SKILL.md +83 -0
- claude_kit/_payload/skills/security-and-hardening/SKILL.md +368 -0
- claude_kit/_payload/skills/security-verification/SKILL.md +209 -0
- claude_kit/_payload/skills/shipping-and-launch/SKILL.md +309 -0
- claude_kit/_payload/skills/smoke-test/SKILL.md +78 -0
- claude_kit/_payload/skills/source-driven-development/SKILL.md +195 -0
- claude_kit/_payload/skills/spec-driven-development/SKILL.md +200 -0
- claude_kit/_payload/skills/sprint/SKILL.md +67 -0
- claude_kit/_payload/skills/sprint/sprint-template.md +90 -0
- claude_kit/_payload/skills/test-driven-development/SKILL.md +383 -0
- claude_kit/_payload/skills/threat-model/SKILL.md +60 -0
- claude_kit/_payload/skills/triage/SKILL.md +87 -0
- claude_kit/_payload/skills/ui-ux-design/SKILL.md +71 -0
- claude_kit/_payload/skills/unit-test/SKILL.md +237 -0
- claude_kit/_payload/skills/using-agent-skills/SKILL.md +180 -0
- claude_kit/_payload/templates/CLAUDE.md +238 -0
- claude_kit/_payload/templates/CLAUDE.stack.md.tmpl +53 -0
- claude_kit/_payload/templates/CONTINUITY.template.md +35 -0
- claude_kit/_payload/templates/README.claude-sdlc.md.tmpl +219 -0
- claude_kit/_payload/templates/agent-memory/MEMORY.md +30 -0
- claude_kit/_payload/templates/agent-memory/api/.gitkeep +0 -0
- claude_kit/_payload/templates/agent-memory/architecture/.gitkeep +0 -0
- claude_kit/_payload/templates/agent-memory/debugging/.gitkeep +0 -0
- claude_kit/_payload/templates/agent-memory/gotchas/.gitkeep +0 -0
- claude_kit/_payload/templates/agent-memory/patterns/.gitkeep +0 -0
- claude_kit/_payload/templates/agent-memory/performance/.gitkeep +0 -0
- claude_kit/_payload/templates/artifacts/adr.md +18 -0
- claude_kit/_payload/templates/artifacts/feature-spec.md +29 -0
- claude_kit/_payload/templates/artifacts/release-plan.md +23 -0
- claude_kit/_payload/templates/artifacts/runbook.md +24 -0
- claude_kit/_payload/templates/artifacts/security-review.md +23 -0
- claude_kit/_payload/templates/artifacts/test-plan.md +22 -0
- claude_kit/_payload/templates/org/README.md +53 -0
- claude_kit/_payload/templates/org/agents/data-workflow-agent.md +59 -0
- claude_kit/_payload/templates/org/agents/founder-prototype-agent.md +61 -0
- claude_kit/_payload/templates/org/agents/internal-tools-builder.md +63 -0
- claude_kit/_payload/templates/org/agents/pm-copilot.md +60 -0
- claude_kit/_payload/templates/org/agents/support-ticket-engineer.md +63 -0
- claude_kit/_payload/templates/org/packs/devops-and-release/README.md +46 -0
- claude_kit/_payload/templates/org/packs/devops-and-release/pack.yaml +32 -0
- claude_kit/_payload/templates/org/packs/engineering-core/README.md +46 -0
- claude_kit/_payload/templates/org/packs/engineering-core/pack.yaml +44 -0
- claude_kit/_payload/templates/org/packs/non-engineer-builder/README.md +53 -0
- claude_kit/_payload/templates/org/packs/non-engineer-builder/pack.yaml +39 -0
- claude_kit/_payload/templates/org/packs/onboarding-and-docs/README.md +49 -0
- claude_kit/_payload/templates/org/packs/onboarding-and-docs/pack.yaml +26 -0
- claude_kit/_payload/templates/org/packs/product-to-code/README.md +50 -0
- claude_kit/_payload/templates/org/packs/product-to-code/pack.yaml +34 -0
- claude_kit/_payload/templates/org/packs/quality-and-review/README.md +53 -0
- claude_kit/_payload/templates/org/packs/quality-and-review/pack.yaml +40 -0
- claude_kit/_payload/templates/org/packs/security-and-compliance/README.md +50 -0
- claude_kit/_payload/templates/org/packs/security-and-compliance/pack.yaml +36 -0
- claude_kit/_payload/templates/org/rules/ai-working-agreement.md +45 -0
- claude_kit/_payload/templates/org/rules/ambiguity-resolution.md +36 -0
- claude_kit/_payload/templates/org/rules/branch-and-pr-policy.md +41 -0
- claude_kit/_payload/templates/org/rules/compliance-policy.md +50 -0
- claude_kit/_payload/templates/org/rules/non-engineer-safe-coding.md +37 -0
- claude_kit/_payload/templates/org/rules/pii-policy.md +46 -0
- claude_kit/_payload/templates/org/rules/production-data-policy.md +35 -0
- claude_kit/_payload/templates/org/rules/prompt-to-task-conversion.md +30 -0
- claude_kit/_payload/templates/org/rules/prototype-boundaries.md +40 -0
- claude_kit/_payload/templates/org/rules/secrets-policy.md +34 -0
- claude_kit/_payload/templates/org/skills/customer-issue-to-fix/SKILL.md +61 -0
- claude_kit/_payload/templates/org/skills/feature-from-idea/SKILL.md +56 -0
- claude_kit/_payload/templates/org/skills/prompt-to-safe-task/SKILL.md +59 -0
- claude_kit/_payload/templates/org/skills/prototype-to-production/SKILL.md +61 -0
- claude_kit/_payload/templates/org/skills/repo-onboarding/SKILL.md +60 -0
- claude_kit/_payload/templates/settings.json +53 -0
- claude_kit/_payload/templates/stacks/backend/python/fastapi/rules/fastapi-patterns.md +64 -0
- claude_kit/_payload/templates/stacks/db/mongodb/agents/migration-specialist.md +61 -0
- claude_kit/_payload/templates/stacks/db/mongodb/agents/mongodb-specialist.md +59 -0
- claude_kit/_payload/templates/stacks/db/mongodb/rules/mongodb-patterns.md +39 -0
- claude_kit/_payload/templates/stacks/db/postgres/agents/db-performance-reviewer.md +66 -0
- claude_kit/_payload/templates/stacks/db/postgres/agents/migration-specialist.md +56 -0
- claude_kit/_payload/templates/stacks/db/postgres/agents/postgres-specialist.md +58 -0
- claude_kit/_payload/templates/stacks/db/postgres/rules/database-performance.md +64 -0
- claude_kit/_payload/templates/stacks/db/postgres/rules/postgres-patterns.md +43 -0
- claude_kit/_payload/templates/stacks/frontend/react/rules/react-patterns.md +63 -0
- claude_kit/catalog.py +476 -0
- claude_kit/cli.py +327 -0
- claude_kit/hooks.py +246 -0
- claude_kit/models.py +205 -0
- claude_kit/prompts.py +209 -0
- claude_kit/render.py +146 -0
- claude_kit/scaffold.py +492 -0
- claude_kit/upgrader.py +294 -0
- claude_kit/validator.py +197 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: migration-specialist
|
|
3
|
+
description: Database migration specialist for relational (PostgreSQL) schemas. Authors safe, reversible, zero-downtime schema migrations and backfills, and reviews migrations before they ship. Use whenever a change alters the database schema.
|
|
4
|
+
tools: Read, Glob, Grep, Bash, Write, Edit
|
|
5
|
+
model: sonnet
|
|
6
|
+
color: magenta
|
|
7
|
+
tier: specialist
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
You are the **Migration Specialist** for relational schemas. When a change touches the database
|
|
11
|
+
shape, you turn the intended schema change into a migration that is **safe to run against live
|
|
12
|
+
data**, **reversible**, and **decoupled from the deploy** so it never causes downtime.
|
|
13
|
+
|
|
14
|
+
## You Do NOT
|
|
15
|
+
|
|
16
|
+
- Decide the target schema — that's the `postgres-specialist` / spec. You make *getting there* safe.
|
|
17
|
+
- Hand-edit a live database. Every change is a versioned, repeatable migration in the project's
|
|
18
|
+
migration tool (whatever `.claude/rules/postgres-patterns.md` / `CLAUDE.md` declares).
|
|
19
|
+
|
|
20
|
+
## Inputs expected
|
|
21
|
+
|
|
22
|
+
- The desired schema change (from the spec or `postgres-specialist`) and the current schema.
|
|
23
|
+
- The project's migration command and conventions from `CLAUDE.md` and
|
|
24
|
+
`.claude/rules/postgres-patterns.md`.
|
|
25
|
+
|
|
26
|
+
## Outputs required
|
|
27
|
+
|
|
28
|
+
1. **Forward migration** — the up step, written so it can run while the old code is still serving
|
|
29
|
+
(additive first: add nullable column / new table / new index, then backfill, then enforce).
|
|
30
|
+
2. **Reverse migration** — a real down step that restores the prior state, or an explicit,
|
|
31
|
+
documented reason it is irreversible (with the data-loss consequence spelled out).
|
|
32
|
+
3. **Backfill plan** — for new non-null columns or new constraints: batched backfill, then the
|
|
33
|
+
constraint added `NOT VALID` → `VALIDATE`, so large tables don't lock.
|
|
34
|
+
4. **Expand/contract sequencing** — when a rename or type change is needed, the expand → migrate →
|
|
35
|
+
contract steps across releases, with what must deploy between them.
|
|
36
|
+
5. **Index changes** — created `CONCURRENTLY` where the table is hot; noted as non-transactional.
|
|
37
|
+
|
|
38
|
+
## Constraints
|
|
39
|
+
|
|
40
|
+
- A migration must be runnable independently of the application deploy and safe if it runs slightly
|
|
41
|
+
before or after it (backward/forward compatible for one release).
|
|
42
|
+
- Long locks are defects: avoid table rewrites and validating constraints in one shot on large
|
|
43
|
+
tables. Prefer additive + backfill + validate.
|
|
44
|
+
- Verify the down path actually works — apply, roll back, re-apply against a scratch database using
|
|
45
|
+
the project's migration command before declaring done.
|
|
46
|
+
|
|
47
|
+
## Quality gate & self-check
|
|
48
|
+
|
|
49
|
+
Run the **RARV** cycle (`.claude/rules/rarv-cycle.md`); Verify means you *ran* up→down→up and it is
|
|
50
|
+
green, not that it looks right. Update `.claude/CONTINUITY.md` at handoff and classify risks by
|
|
51
|
+
`.claude/rules/quality-gates.md` — an irreversible or table-locking migration is at least High.
|
|
52
|
+
|
|
53
|
+
## Escalation
|
|
54
|
+
|
|
55
|
+
Escalate when the change cannot be made both zero-downtime and single-release (it needs an
|
|
56
|
+
expand/contract spanning deploys), or when a safe migration is impossible without accepted data loss.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: postgres-specialist
|
|
3
|
+
description: PostgreSQL data-layer specialist. Designs relational schemas, indexes, and queries; reviews data access for correctness, performance, and integrity. Use for schema design, query/index tuning, and Postgres-specific review on the backend lane.
|
|
4
|
+
tools: Read, Glob, Grep, Bash, Write, Edit
|
|
5
|
+
model: sonnet
|
|
6
|
+
color: blue
|
|
7
|
+
tier: specialist
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
You are the **PostgreSQL Specialist** — the data-layer expert on the backend lane. You design and
|
|
11
|
+
review relational schemas, indexes, and queries so the persistence layer is correct, fast, and
|
|
12
|
+
durable. You work *within* the backend implementation, not as a separate pipeline phase.
|
|
13
|
+
|
|
14
|
+
## You Do NOT
|
|
15
|
+
|
|
16
|
+
- Own application/business logic — that's the `developer` / `senior-backend-dev`. You shape the
|
|
17
|
+
data model and the queries that serve it.
|
|
18
|
+
- Author migrations as deliverables — that's the `migration-specialist`. You specify the schema
|
|
19
|
+
change; they make it safe and reversible.
|
|
20
|
+
- Assume a deployment shape (containers, managed service, local) — the database is reached however
|
|
21
|
+
the project's config says. Stay infrastructure-neutral.
|
|
22
|
+
|
|
23
|
+
## Inputs expected
|
|
24
|
+
|
|
25
|
+
- The approved spec and the backend overlay rules — `.claude/rules/postgres-patterns.md` and the
|
|
26
|
+
framework rule (e.g. `.claude/rules/fastapi-patterns.md`) — plus `CLAUDE.md` for the commands.
|
|
27
|
+
- The current schema / models and the access paths (repositories, queries) under review.
|
|
28
|
+
|
|
29
|
+
## Outputs required
|
|
30
|
+
|
|
31
|
+
1. **Schema design** — tables, columns, types, nullability, defaults, and the constraints that make
|
|
32
|
+
invalid states unrepresentable (PK/FK, `UNIQUE`, `CHECK`, `NOT NULL`). Prefer the database to
|
|
33
|
+
enforce invariants over application code.
|
|
34
|
+
2. **Index plan** — the indexes each access path needs (and the composite/partial/covering ones it
|
|
35
|
+
doesn't), with the query they serve. Call out write-amplification trade-offs.
|
|
36
|
+
3. **Query review** — N+1s, unbounded scans, missing pagination, lock/contention risks; rewrite or
|
|
37
|
+
`EXPLAIN`-justify hot queries. Parameterized queries only (no string interpolation).
|
|
38
|
+
4. **Integrity & concurrency notes** — transaction boundaries, isolation level where it matters,
|
|
39
|
+
and how concurrent writers stay consistent.
|
|
40
|
+
|
|
41
|
+
## Constraints
|
|
42
|
+
|
|
43
|
+
- Follow `.claude/rules/postgres-patterns.md` for naming, types, and the resource recipe.
|
|
44
|
+
- Every schema change implies a migration — hand the change to the `migration-specialist`; never
|
|
45
|
+
mutate a live schema ad hoc.
|
|
46
|
+
- Evidence for performance claims: an `EXPLAIN (ANALYZE, BUFFERS)` or a measured query, not a guess.
|
|
47
|
+
|
|
48
|
+
## Quality gate & self-check
|
|
49
|
+
|
|
50
|
+
Run the **RARV** cycle (`.claude/rules/rarv-cycle.md`) with a green Verify (constraints hold, the
|
|
51
|
+
indexes match the queries, no unparameterized SQL) and update `.claude/CONTINUITY.md` at handoff.
|
|
52
|
+
Classify findings by the severity model in `.claude/rules/quality-gates.md`.
|
|
53
|
+
|
|
54
|
+
## Escalation
|
|
55
|
+
|
|
56
|
+
Escalate when the spec's access patterns can't be served without denormalization or a schema the
|
|
57
|
+
spec doesn't allow, when a needed index would unacceptably slow writes, or when correctness requires
|
|
58
|
+
an isolation level the rest of the system doesn't use.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Database Performance (PostgreSQL + SQLAlchemy 2.0 async)
|
|
2
|
+
|
|
3
|
+
Performance rules for the data layer. The dominant failure modes in a multi-tenant async app are **N+1 queries**, **missing composite indexes on tenant-scoped lookups**, and **offset pagination on large tables**. Treat these as defects, not nice-to-haves.
|
|
4
|
+
|
|
5
|
+
> Overlay rule — installed only when PostgreSQL is selected. Complements the general patterns in
|
|
6
|
+
> `.claude/rules/postgres-patterns.md`. Adapted from a portfolio project's database-performance rule.
|
|
7
|
+
|
|
8
|
+
## N+1 Queries — the #1 offender
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
# BAD — lazy-loads relationship once per row (N+1)
|
|
12
|
+
orgs = (await db.execute(select(Organization))).scalars().all()
|
|
13
|
+
for o in orgs:
|
|
14
|
+
print(o.members) # fires a query each iteration
|
|
15
|
+
|
|
16
|
+
# GOOD — eager-load in one round trip
|
|
17
|
+
stmt = select(Organization).options(selectinload(Organization.members))
|
|
18
|
+
orgs = (await db.execute(stmt)).scalars().all()
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- **`selectinload`** for collections (one-to-many / many-to-many) — second query with `IN (...)`, no row multiplication.
|
|
22
|
+
- **`joinedload`** for to-one (many-to-one / one-to-one) — single JOIN.
|
|
23
|
+
- Never access a relationship inside a loop without eager-loading it first.
|
|
24
|
+
- Watch async lazy-loading: a lazy attribute access outside the session/greenlet raises — eager-load deliberately.
|
|
25
|
+
|
|
26
|
+
## Indexes — especially tenant-scoped
|
|
27
|
+
|
|
28
|
+
- Every tenant-scoped table needs a **composite index leading with the tenant key** (e.g. `organization_id`): `Index("ix_<table>_org_<col>", "organization_id", "<filter_or_sort_col>")`. A bare tenant-key index is not enough when you also filter/sort by another column.
|
|
29
|
+
- Index foreign keys used in JOINs and columns used in `WHERE`, `ORDER BY`, and `UNIQUE` constraints.
|
|
30
|
+
- Unique constraints in a multi-tenant app are usually **per-tenant**: `UniqueConstraint("organization_id", "email")`, not global on `email`.
|
|
31
|
+
- Add the index in the **same migration** as the column/query (see the migration patterns in `.claude/rules/postgres-patterns.md`).
|
|
32
|
+
|
|
33
|
+
## Pagination
|
|
34
|
+
|
|
35
|
+
- Prefer **keyset (cursor) pagination** for large or hot lists: `WHERE (organization_id = :org) AND (created_at, id) < (:cursor_ts, :cursor_id) ORDER BY created_at DESC, id DESC LIMIT :n`.
|
|
36
|
+
- `OFFSET` degrades linearly — acceptable only for small, bounded result sets (admin tables). Never `OFFSET` into the thousands.
|
|
37
|
+
- Always `ORDER BY` a unique tiebreaker (e.g. `id`) so pages are stable.
|
|
38
|
+
|
|
39
|
+
## Query hygiene
|
|
40
|
+
|
|
41
|
+
- Select only what you need; avoid loading large columns/relationships you won't use. Use `load_only(...)` / `selectinload` selectively.
|
|
42
|
+
- **Bulk** insert/update/delete instead of per-row loops (`insert().values([...])`, `update().where(...)`).
|
|
43
|
+
- Compute `COUNT` with care — `SELECT count(*)` over a huge filtered set is expensive; cache or approximate where product allows.
|
|
44
|
+
- Push filtering/aggregation into SQL; don't pull rows into Python to filter them.
|
|
45
|
+
- Wrap a logical unit of work in one transaction; don't open a transaction per row.
|
|
46
|
+
|
|
47
|
+
## Connection pool (asyncpg)
|
|
48
|
+
|
|
49
|
+
- Tune `create_async_engine(pool_size=..., max_overflow=..., pool_pre_ping=True, pool_recycle=...)` to fit the DB's `max_connections` and worker count. Default `pool_size=5` is often too small under load and too large × many workers.
|
|
50
|
+
- Don't hold a DB session across an external `await` (HTTP call) — you pin a pooled connection while idle.
|
|
51
|
+
|
|
52
|
+
## How to verify
|
|
53
|
+
|
|
54
|
+
```sql
|
|
55
|
+
EXPLAIN (ANALYZE, BUFFERS) <query>; -- look for Seq Scan on big tables, high rows, nested loops over many rows
|
|
56
|
+
```
|
|
57
|
+
- Enable SQLAlchemy echo or query logging in dev to count queries per request — a request firing 30 queries for 10 rows is an N+1.
|
|
58
|
+
- Add a regression guard for hot endpoints: assert the query count stays bounded. (See the `load-testing` skill to drive that load.)
|
|
59
|
+
|
|
60
|
+
## Severity (per `.claude/rules/quality-gates.md`)
|
|
61
|
+
|
|
62
|
+
- Unbounded N+1 on a list endpoint, or a tenant-scoped query with no supporting index on a large table → **High**.
|
|
63
|
+
- `OFFSET` pagination on an unbounded list, missing FK index used in a hot JOIN → **Medium**.
|
|
64
|
+
- Over-fetching columns, sub-optimal pool sizing → **Low**.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# PostgreSQL patterns
|
|
2
|
+
|
|
3
|
+
Database conventions. Installed into `.claude/rules/` only when **PostgreSQL** is selected. Read
|
|
4
|
+
`.claude/rules/design-patterns.md` and your backend overlay rule first; this file makes the data
|
|
5
|
+
layer concrete for Postgres.
|
|
6
|
+
|
|
7
|
+
## Access
|
|
8
|
+
|
|
9
|
+
- Use a connection **pool** (the framework's default async engine/pool) — never a connection per
|
|
10
|
+
request created by hand. One engine per process.
|
|
11
|
+
- The **session/transaction is owned at the request boundary** (a dependency or middleware):
|
|
12
|
+
commit on success, roll back on error. Repositories `flush`, never `commit`.
|
|
13
|
+
- Parameterise every query. Never build SQL by string-concatenating user input — use bound
|
|
14
|
+
parameters or the ORM. This is the first line against SQL injection.
|
|
15
|
+
|
|
16
|
+
## Schema & migrations
|
|
17
|
+
|
|
18
|
+
- Schema changes go through **versioned migrations** (e.g. Alembic). The database is the source of
|
|
19
|
+
truth; the migration history is how it got there.
|
|
20
|
+
- **Review every autogenerated migration before applying it.** Autogenerate compares your models to a
|
|
21
|
+
*running* database and misses server defaults, type/enum changes, and renames.
|
|
22
|
+
- Typical loop (run from the backend project, against a reachable Postgres):
|
|
23
|
+
- New migration: `alembic revision --autogenerate -m "<message>"` — then read the generated file.
|
|
24
|
+
- Apply: `alembic upgrade head`
|
|
25
|
+
- If no database is reachable, hand-write the migration using an existing one as a template.
|
|
26
|
+
- For new non-null columns on populated tables, set a dialect-safe `server_default`
|
|
27
|
+
(`sa.false()`, `sa.text("now()")`) so existing rows get a value, then drop the default if it
|
|
28
|
+
shouldn't persist.
|
|
29
|
+
|
|
30
|
+
## Modeling
|
|
31
|
+
|
|
32
|
+
- Prefer explicit types: `timestamptz` for instants (store UTC), `numeric` for money (never float),
|
|
33
|
+
native `enum` or a checked text column for small closed sets, `jsonb` for documents.
|
|
34
|
+
- Add **indexes** for every foreign key and every column used in a `WHERE`/`ORDER BY` on a hot path.
|
|
35
|
+
Add a unique constraint where the domain requires uniqueness — don't enforce it only in code.
|
|
36
|
+
- Use foreign keys with deliberate `ON DELETE` behavior; don't leave referential integrity to the app.
|
|
37
|
+
|
|
38
|
+
## Operations
|
|
39
|
+
|
|
40
|
+
- Keep credentials in env (`DATABASE_URL`); never commit them. Document required vars in
|
|
41
|
+
`.env.example`.
|
|
42
|
+
- Long/locking migrations (new index, type change) on large tables: prefer `CREATE INDEX
|
|
43
|
+
CONCURRENTLY` and back-fill in batches; call this out in the release/runbook notes.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# React frontend patterns
|
|
2
|
+
|
|
3
|
+
Stack-specific conventions for the frontend. This overlay is installed into `.claude/rules/` only
|
|
4
|
+
when the **React** frontend is selected. Read the generic
|
|
5
|
+
`.claude/rules/frontend-best-practices.md`, `.claude/rules/code-organization.md`, and
|
|
6
|
+
`.claude/rules/responsive-and-accessibility.md` first; this file makes them concrete for React.
|
|
7
|
+
|
|
8
|
+
## Stack
|
|
9
|
+
|
|
10
|
+
- **React** + **TypeScript** (strict), a modern build/dev server (Vite or your project's choice).
|
|
11
|
+
- Data: a shared HTTP client instance (e.g. `src/api/client.ts`); typed API modules under `src/api/`.
|
|
12
|
+
- Tests: a component testing stack (Vitest/Jest + React Testing Library + `@testing-library/jest-dom`).
|
|
13
|
+
- Tooling: ESLint (flat config) and `tsc --noEmit` for type checking.
|
|
14
|
+
|
|
15
|
+
Run the project's own scripts for these tasks (see the **Commands** section of `CLAUDE.md`):
|
|
16
|
+
install, run/dev, test, lint, type-check, build.
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
src/
|
|
22
|
+
api/client.ts one configured HTTP client instance (base URL, headers, interceptors)
|
|
23
|
+
api/<resource>.ts typed request functions (one module per resource)
|
|
24
|
+
types/<resource>.ts shared types — mirror the backend response/request schemas
|
|
25
|
+
features/<feature>/ a folder per feature:
|
|
26
|
+
use<Feature>.ts data hook: state + fetching + actions
|
|
27
|
+
<Feature>Page.tsx presentational component (renders the hook's data)
|
|
28
|
+
<Feature>Page.test.tsx component tests with the API module mocked
|
|
29
|
+
test/setup.ts test matcher registration + cleanup
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Rules of thumb:
|
|
33
|
+
- **Container/presentational split.** Data fetching and state live in a hook (`use<Feature>`);
|
|
34
|
+
components render props/hook output and own only local UI state (form fields, toggles).
|
|
35
|
+
- **Never call the HTTP library directly.** Import the shared client so base URL and headers are
|
|
36
|
+
configured once. Put request functions in `src/api/<resource>.ts`, fully typed.
|
|
37
|
+
- **Types mirror the backend.** Keep `src/types/<resource>.ts` in sync with the backend schemas.
|
|
38
|
+
A field added on the backend is added here — and in any test fixtures/mocks that build that type
|
|
39
|
+
(`tsc --noEmit` flags the ones you miss).
|
|
40
|
+
- **Config via env.** Read backend URLs from build-time env (e.g. `import.meta.env.VITE_*`), declared
|
|
41
|
+
in the env typings. Never hard-code hosts in components.
|
|
42
|
+
- **Accessibility.** Label inputs (`aria-label` or `<label>`), use `role="alert"` for errors, and
|
|
43
|
+
give actionable controls accessible names — tests select by role/label, which enforces this.
|
|
44
|
+
|
|
45
|
+
## Adding a feature (the recipe)
|
|
46
|
+
|
|
47
|
+
1. **Types** — `src/types/<feature>.ts`, matching the backend schema.
|
|
48
|
+
2. **API** — `src/api/<feature>.ts`: typed functions using the shared client.
|
|
49
|
+
3. **Hook** — `src/features/<feature>/use<Feature>.ts`: state + fetching + actions.
|
|
50
|
+
4. **Component** — `src/features/<feature>/<Feature>Page.tsx`: presentational; consumes the hook.
|
|
51
|
+
5. **Wire it in** — render the page from `App.tsx` (or the router).
|
|
52
|
+
6. **Tests** — `<Feature>Page.test.tsx`: mock the API module, then assert rendering, the empty
|
|
53
|
+
state, and the create/update flow. Select by role/label, not test ids.
|
|
54
|
+
|
|
55
|
+
## Conventions
|
|
56
|
+
|
|
57
|
+
- **Type everything.** No `any`; exported functions and hooks have explicit return types and doc
|
|
58
|
+
comments per `.claude/rules/documentation.md`. Type-check and lint must pass.
|
|
59
|
+
- **Keep tests behavioral.** Mock the API module, drive the UI like a user, and assert what the user
|
|
60
|
+
sees — not implementation details. When testing-library cleanup is not automatic, register an
|
|
61
|
+
explicit `afterEach(cleanup)` in `test/setup.ts`.
|
|
62
|
+
- **Small components.** If a component grows past one responsibility, split it; move shared logic
|
|
63
|
+
into a hook.
|