@zigordev/dev 0.0.0 → 1.0.1

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.
Files changed (94) hide show
  1. package/README.md +217 -1
  2. package/bin/zigordev.js +29 -0
  3. package/biome.json +49 -0
  4. package/commitlint.js +16 -0
  5. package/dist/cli.d.ts +13 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +184 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/commits.d.ts +3 -0
  10. package/dist/commits.d.ts.map +1 -0
  11. package/dist/commits.js +15 -0
  12. package/dist/commits.js.map +1 -0
  13. package/dist/files.d.ts +3 -0
  14. package/dist/files.d.ts.map +1 -0
  15. package/dist/files.js +38 -0
  16. package/dist/files.js.map +1 -0
  17. package/dist/first-publish.d.ts +16 -0
  18. package/dist/first-publish.d.ts.map +1 -0
  19. package/dist/first-publish.js +126 -0
  20. package/dist/first-publish.js.map +1 -0
  21. package/dist/release.d.ts +21 -0
  22. package/dist/release.d.ts.map +1 -0
  23. package/dist/release.js +81 -0
  24. package/dist/release.js.map +1 -0
  25. package/dist/rule.d.ts +17 -0
  26. package/dist/rule.d.ts.map +1 -0
  27. package/dist/rule.js +2 -0
  28. package/dist/rule.js.map +1 -0
  29. package/dist/rules/actions.d.ts +3 -0
  30. package/dist/rules/actions.d.ts.map +1 -0
  31. package/dist/rules/actions.js +57 -0
  32. package/dist/rules/actions.js.map +1 -0
  33. package/dist/rules/attribution.d.ts +3 -0
  34. package/dist/rules/attribution.d.ts.map +1 -0
  35. package/dist/rules/attribution.js +37 -0
  36. package/dist/rules/attribution.js.map +1 -0
  37. package/dist/rules/comments.d.ts +3 -0
  38. package/dist/rules/comments.d.ts.map +1 -0
  39. package/dist/rules/comments.js +368 -0
  40. package/dist/rules/comments.js.map +1 -0
  41. package/dist/rules/docs.d.ts +3 -0
  42. package/dist/rules/docs.d.ts.map +1 -0
  43. package/dist/rules/docs.js +32 -0
  44. package/dist/rules/docs.js.map +1 -0
  45. package/dist/rules/identity.d.ts +4 -0
  46. package/dist/rules/identity.d.ts.map +1 -0
  47. package/dist/rules/identity.js +64 -0
  48. package/dist/rules/identity.js.map +1 -0
  49. package/dist/rules/index.d.ts +3 -0
  50. package/dist/rules/index.d.ts.map +1 -0
  51. package/dist/rules/index.js +12 -0
  52. package/dist/rules/index.js.map +1 -0
  53. package/dist/rules/links.d.ts +3 -0
  54. package/dist/rules/links.d.ts.map +1 -0
  55. package/dist/rules/links.js +52 -0
  56. package/dist/rules/links.js.map +1 -0
  57. package/dist/rules/scripts.d.ts +3 -0
  58. package/dist/rules/scripts.d.ts.map +1 -0
  59. package/dist/rules/scripts.js +50 -0
  60. package/dist/rules/scripts.js.map +1 -0
  61. package/dist/rules/shared.d.ts +3 -0
  62. package/dist/rules/shared.d.ts.map +1 -0
  63. package/dist/rules/shared.js +26 -0
  64. package/dist/rules/shared.js.map +1 -0
  65. package/dist/shared.d.ts +5 -0
  66. package/dist/shared.d.ts.map +1 -0
  67. package/dist/shared.js +33 -0
  68. package/dist/shared.js.map +1 -0
  69. package/lefthook.yml +36 -0
  70. package/package.json +54 -4
  71. package/semantic-release.js +22 -0
  72. package/shared/.claude/hooks/guard.mjs +785 -0
  73. package/shared/.claude/hooks/guard.sh +7 -0
  74. package/shared/.claude/rules/api.md +48 -0
  75. package/shared/.claude/rules/core.md +71 -0
  76. package/shared/.claude/rules/data.md +43 -0
  77. package/shared/.claude/rules/docs.md +49 -0
  78. package/shared/.claude/rules/infra.md +49 -0
  79. package/shared/.claude/rules/tests.md +40 -0
  80. package/shared/.claude/rules/web.md +42 -0
  81. package/shared/.claude/rules/workflows.md +19 -0
  82. package/shared/.claude/settings.json +84 -0
  83. package/shared/.claude/skills/finish-work/SKILL.md +20 -0
  84. package/shared/.claude/skills/start-work/SKILL.md +16 -0
  85. package/shared/.claude/skills/write-decision-record/SKILL.md +20 -0
  86. package/shared/.claude/skills/write-decision-record/template.md +21 -0
  87. package/shared/.commitlintrc.json +3 -0
  88. package/shared/.github/pull_request_template.md +23 -0
  89. package/shared/.markdownlint-cli2.jsonc +8 -0
  90. package/shared/lefthook.yml +2 -0
  91. package/shared/renovate.json +5 -0
  92. package/tsconfig/base.json +20 -0
  93. package/tsconfig/library.json +9 -0
  94. package/tsconfig/node.json +11 -0
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ input=$(cat)
3
+ case "$input" in
4
+ *git* | *[!i]gh* | *file_path* | *bashEditDiff*) ;;
5
+ *) exit 0 ;;
6
+ esac
7
+ printf '%s' "$input" | node "${0%/*}/guard.mjs"
@@ -0,0 +1,48 @@
1
+ ---
2
+ paths:
3
+ - "**/apps/*-api/**"
4
+ - "packages/api/**"
5
+ ---
6
+
7
+ # API rules
8
+
9
+ These rules apply to every Fastify service and to `@zigordev/api`.
10
+
11
+ ## Shape of a service
12
+
13
+ - `src/main.ts` starts the server. On SIGTERM it calls `app.close()`, which stops taking work, finishes what is in flight and closes every connection, within 30 seconds.
14
+ - `src/app.ts` exports `buildApp()`, which registers everything and never listens. Tests build the app with it.
15
+ - `src/config.ts` reads the environment once, validates it with Zod and fails at start on a missing setting. Nothing else reads `process.env`.
16
+ - `src/plugins/` holds what cuts across features: errors, auth, database, docs and health. `src/features/<name>/` holds `routes.ts`, `schemas.ts`, `service.ts` and `repository.ts`, with their tests beside them.
17
+ - Each feature is a plugin registered with its prefix. A shared instance, such as the database, is decorated once, in a plugin wrapped with `fastify-plugin`.
18
+ - Plugins come from `@fastify/*`. Express middleware is never mounted.
19
+
20
+ ## Routes
21
+
22
+ - Every business endpoint lives under `/api/v1/`. A breaking change adds `/api/v2/` for the resources it touches, and v1 keeps working until its callers have moved.
23
+ - A resource is a lowercase plural noun in kebab-case, nested at most two levels, with no verb and no trailing slash: `/payment-methods`, `/organizations/{orgId}/members`.
24
+ - An action that is not CRUD is a `POST` to a noun below the resource, such as `POST /pools/{poolId}/invitations`, or else a kebab-case action segment.
25
+ - `GET` answers 200. A `POST` that creates answers 201 with a `Location` header. A `POST` that acts answers 200, or 202 when the work continues. `PUT` and `PATCH` answer 200 with the resource. `DELETE` answers 204.
26
+ - A list takes filters as `?field=value`, sorting as `sort=field` or `sort=-field`, and paging as `limit` (20 by default, 100 at most) and `cursor`. It answers `{ "items": [], "nextCursor": "..." }`, with no `nextCursor` on the last page. An unknown filter or sort field is a 400.
27
+ - JSON uses camelCase fields, UUIDs as ids, and timestamps in ISO 8601 UTC.
28
+
29
+ ## Schemas and errors
30
+
31
+ - Every body, query, path parameter and header a route reads has a Zod schema, and objects are strict. Every status a route can return is declared, so Fastify drops any field the schema does not list.
32
+ - Every endpoint needs authentication unless it is explicitly marked public.
33
+ - An error is an RFC 9457 problem, `application/problem+json`, with `type`, `title`, `status`, `detail` and `instance`, plus a stable `code` and its `params`. A validation error lists every invalid field. A 5xx body carries no internal detail. One error handler and one not-found handler produce them all.
34
+ - A write that another service calls accepts an `Idempotency-Key` header.
35
+
36
+ ## Contract
37
+
38
+ - Every route has a `summary`, `tags` and a stable camelCase `operationId`, such as `listPools`.
39
+ - The service serves Swagger UI at `GET /api/v1/docs` and the OpenAPI 3.1 document at `GET /api/v1/openapi.json`.
40
+ - The generated document is committed as `openapi.json` beside the app. CI fails when it drifts from the code, and the clients are regenerated from it in the same pull request.
41
+ - A service calls another service only over HTTP, through the client generated from that service's document, and keeps working when the other one is down.
42
+
43
+ ## Telemetry
44
+
45
+ - `GET /health` sits at the root, outside any prefix. It answers 200 `ok`, 200 `degraded` when an optional component is down, and 503 `error` when a required one is. A new dependency is a new component.
46
+ - Logs are JSON lines on stdout through the shared logger, with fields at the top level and no personal data. An event is named `area.what_happened`. `error` means a person should look, `warn` a handled problem, and `info` lifecycle and business events.
47
+ - Metrics and traces go out over OTLP through `@zigordev/otel`. Names follow the OpenTelemetry conventions, attribute values are bounded (route patterns, never raw paths, ids or emails), and a new counter starts at zero.
48
+ - New I/O runs inside a span, and nothing calls `console`.
@@ -0,0 +1,71 @@
1
+ # Core rules
2
+
3
+ These rules hold in every zigordev repo and in every session. `toolkit` owns this file. Every other repo holds a copy, `zigordev sync` updates it, and `pnpm check` fails when a copy differs. A repo's own `CLAUDE.md` adds detail. When the two disagree, stop and ask.
4
+
5
+ ## The rules
6
+
7
+ 1. **Identity.** Every commit is authored and committed as `zigordev <zigordev@gmail.com>`, and `gh` acts as `zigordev`.
8
+ 2. **No attribution.** Nothing credits a tool or a co-author: no `Co-Authored-By` trailer, no "Generated with" line, no line that names Claude or another AI tool as an author, and no robot emoji. This covers commits, pull requests, issues, comments, release notes, code and docs.
9
+ 3. **No comments.** No file gets a comment of any kind. The reasoning goes in the commit body, the pull request, the docs or a decision record. A line that a tool needs is not a comment: a shebang, a `# syntax=` line, the version label after a pinned action, and a suppression that cannot be avoided, which the pull request names.
10
+ 4. **Protected history.** Nothing is pushed to `main`. The git hooks are never skipped. A force push goes only to your own working branch.
11
+ 5. **One format.** Commits and pull request titles follow Conventional Commits: `type(scope): summary`, in lower case, with no final period.
12
+ 6. **Done means checked.** `pnpm check` passes before a push, because it runs what CI runs. A change that can be observed is also tried for real.
13
+ 7. **Some changes wait for the owner.** They are listed below. Every other change merges by itself once `check` is green.
14
+
15
+ ## What waits for the owner
16
+
17
+ Ask in the conversation and wait for a clear yes before any of these. A yes covers one action, not the next one.
18
+
19
+ - An infrastructure change. The plan shows in the pull request, and the apply waits for the owner's approval in GitHub. Nothing in AWS, Cloudflare, GitHub or Grafana is changed by hand.
20
+ - A migration that deletes data.
21
+ - A tool, library or service the handbook does not list yet. Propose it with the reason, the alternatives, the licence and the price.
22
+ - A new major version of a dependency.
23
+ - A repo's settings and rulesets, and creating or deleting a repo.
24
+ - Deleting data, and running a deploy, a rollback or a pipeline job by hand.
25
+ - A message on a pull request or an issue that the task is not about.
26
+
27
+ Two things a session never does, even with a yes: it never sets, rotates or deletes a secret or a variable, and it never approves a pull request or a deployment. Say exactly what is needed, and the owner does it.
28
+
29
+ ## What enforces each rule
30
+
31
+ | Rule | Enforced by |
32
+ | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
33
+ | Identity | The guard hook, before a commit, a push and a change made with `gh`. The `identity` rule of `zigordev check`, in the commit hook and in CI on the pull request's commits |
34
+ | No attribution | The guard hook, on commit messages and on text sent with `gh`. commitlint, on every commit message and on the pull request title. The `attribution` rule of `zigordev check`, in CI on the pull request's title, description and commits |
35
+ | No comments | The `comments` rule of `zigordev check`: after a file is written, in the commit hook and in CI |
36
+ | Protected history | GitHub's ruleset on `main`, the push hook and the guard hook |
37
+ | One format | commitlint in the commit hook, and the `Title` job in CI |
38
+ | Done means checked | The push hook runs `pnpm check:quick`, and `check` is the one required check on `main` |
39
+ | Infrastructure waits | From phase 3, the apply job waits for the owner's approval in GitHub. The guard hook already refuses to give an approval, and the permission rules ask before an apply |
40
+ | A destructive migration waits | From phase 4, a CI check fails until the owner labels the pull request. The guard hook already asks before a label changes |
41
+ | Settings, secrets and repos wait | The permission rules in `.claude/settings.json` ask before a repo, a release or a workflow run is created or changed, and refuse to set a secret. The guard hook asks before any change made through GitHub's API |
42
+
43
+ ## How work flows
44
+
45
+ - Work happens in the repo's own folder, on one working branch per change. There is no worktree and no second copy of a repo.
46
+ - A branch is named `<type>/<short-summary>`, is cut from `origin/main`, lives for hours and holds one concern.
47
+ - A pull request opens as a draft. Marking it ready means: merge it when `check` is green. Merges are squashes, so the title becomes the commit.
48
+ - Unfinished work ships switched off, behind a flag that carries a removal date.
49
+ - A red `main` is fixed or reverted before any other work.
50
+ - The `start-work` skill begins a change, and the `finish-work` skill ends it.
51
+
52
+ ## Everywhere
53
+
54
+ - Same thing, same way. Before building something, look at how the product template and the other repos do it, and do it that way. To change the way, change it in `toolkit`, for everyone.
55
+ - One tool per job. The handbook in `toolkit` lists the tools.
56
+ - Stable versions only. A new major version waits a month and arrives as its own task.
57
+ - English in code, commits and docs. Dates are absolute, such as 2026-11-22.
58
+ - Secrets and personal data never reach git, logs, metrics, traces or error messages.
59
+ - Never stop, recreate or reconfigure a container you did not start. Stop every server, container and process you started before you finish.
60
+
61
+ ## Done
62
+
63
+ A change is done when all of this holds:
64
+
65
+ 1. `pnpm check` passes, and the change was tried for real when it can be observed.
66
+ 2. Tests cover the new behaviour: unit, API and browser tests, where each applies.
67
+ 3. The docs that describe the behaviour changed in the same pull request.
68
+ 4. The change can be seen when it runs: its logs, metrics and traces use the standard names, and a new failure a user would notice has an alert with a runbook.
69
+ 5. The pull request is a draft or is green, and nothing that waits for the owner was done without a yes.
70
+
71
+ The report says what changed, with links, how it was checked, what was not checked and what needs the owner. It shows the output of anything that failed.
@@ -0,0 +1,43 @@
1
+ ---
2
+ paths:
3
+ - "**/drizzle/**"
4
+ - "**/migrations/**"
5
+ - "**/drizzle.config.ts"
6
+ - "**/*.sql"
7
+ - "**/src/db/**"
8
+ - "**/repository.ts"
9
+ ---
10
+
11
+ # Data rules
12
+
13
+ These rules apply to schemas, migrations, queries and background jobs.
14
+
15
+ ## Migrations
16
+
17
+ - A schema change is a forward-only migration. A migration that has run anywhere is never edited: a mistake gets a new migration.
18
+ - drizzle-kit writes the SQL from the schema. The SQL is read, committed, and applied by a one-shot `migrate` job before the app starts.
19
+ - A deploy runs the old and the new version side by side for a moment, so every change comes in steps the running version can live with: add first, switch over, remove later.
20
+ - A migration that deletes data, a table or a column waits for the owner. Say what is lost and how to get it back, and stop.
21
+
22
+ ## Schema
23
+
24
+ - A table is plural and in snake_case, such as `pool_members`. Columns are in snake_case and map to camelCase in TypeScript.
25
+ - A primary key is a `uuid` that defaults to `uuidv7()`.
26
+ - Every table has `created_at` and `updated_at`, as `timestamptz` in UTC.
27
+
28
+ ## Where data lives
29
+
30
+ - Each product owns one PostgreSQL 18 server, with one database and one role per app. No app reads another app's database.
31
+ - Queries go through Drizzle over node-postgres. Background jobs and schedules run in pg-boss, inside the product's own database.
32
+ - A second data store, a broker, a cache or a search engine needs a decision record first.
33
+ - An app keeps state only in the stores its `compose.yaml` declares, because the backup saves exactly those.
34
+
35
+ ## Personal data
36
+
37
+ - Personal data stays in the EU, and never reaches logs, metrics, traces or error messages.
38
+ - Deleted data is gone from every backup within 30 days.
39
+ - Seed data is invented.
40
+
41
+ ## Tests
42
+
43
+ - Tests run against a real PostgreSQL of the same major version as production, never against a mock.
@@ -0,0 +1,49 @@
1
+ ---
2
+ paths:
3
+ - "docs/**"
4
+ - "**/README.md"
5
+ ---
6
+
7
+ # Documentation rules
8
+
9
+ These rules apply to every README and to everything under `docs/`.
10
+
11
+ ## The five places
12
+
13
+ | File | The question it answers |
14
+ | ---------------------------- | ---------------------------------------------------------------------------------------------- |
15
+ | `README.md` | What is this, why does it exist, what is it built with, and how do I start it in five minutes? |
16
+ | `docs/local-first-start.md` | How do I run it on a clean laptop, step by step? |
17
+ | `docs/cloud-first-deploy.md` | How does it reach production, and how do I operate it there? |
18
+ | `docs/user-manual.md` | What can a user do, flow by flow? For a library: how do I use it from my code? |
19
+ | `docs/adr/` | Which decisions were taken, and why? One short record each |
20
+
21
+ The `docs` rule of `zigordev check` fails when one of them is missing.
22
+
23
+ ## How to write
24
+
25
+ - Write for a reader who has never seen the repo, and teach: say what a thing is, why it exists and how to use it.
26
+ - A pull request that changes behaviour changes its docs too.
27
+ - Update the page that exists. Do not add a summary, a report or notes that nobody asked for.
28
+ - Dates are absolute, such as 2026-11-22, never "yesterday".
29
+ - A diagram is a Mermaid code block, which GitHub draws.
30
+ - A link to another file leads somewhere. The `links` rule fails when one does not, and markdownlint keeps the Markdown consistent.
31
+ - The user manual of a web app lists its critical paths, and each one has a browser test.
32
+
33
+ ## Handbook pages
34
+
35
+ `toolkit` holds the handbook in `docs/handbook/`, with one page per piece of the platform. Every page has the same five headings:
36
+
37
+ 1. What it is.
38
+ 2. Why we have it, and what we would lose without it.
39
+ 3. How it works here, on the laptop and in production.
40
+ 4. How to use it, with one worked example.
41
+ 5. How to check that it works, and what to do when it does not.
42
+
43
+ A package's README follows the same five headings. `platform` holds the runbooks in `docs/runbooks/`, and every alert links to one.
44
+
45
+ ## Decision records
46
+
47
+ - One short record per significant decision: the context, the decision, the consequences and the alternatives not taken.
48
+ - Records are numbered from 0001 in each repo. An accepted record is never edited: a new record supersedes it by naming it.
49
+ - The `write-decision-record` skill holds the template and the steps.
@@ -0,0 +1,49 @@
1
+ ---
2
+ paths:
3
+ - "infra/**"
4
+ - "host/**"
5
+ - "stack/**"
6
+ - "observability/**"
7
+ - "**/compose*.yaml"
8
+ - "**/Dockerfile"
9
+ - "**/.dockerignore"
10
+ - "**/*.tofu"
11
+ - "**/*.tf"
12
+ ---
13
+
14
+ # Infrastructure rules
15
+
16
+ These rules apply to OpenTofu code, compose files, Dockerfiles and everything the host runs.
17
+
18
+ ## Changes
19
+
20
+ - Everything in AWS, Cloudflare, GitHub and Grafana Cloud is code in `platform`, changed through a pull request. Nothing is changed by hand, and a weekly run alerts when reality differs from the code.
21
+ - The plan shows in the pull request. The apply waits for the owner's approval in GitHub. A session never gives that approval, and never runs an apply itself without a yes.
22
+ - Only `platform` can change infrastructure. A product repo can do one thing in AWS: ask the host to run a version of itself.
23
+ - What exists once per product comes from data, one entry per product, never from a copied block.
24
+ - No cloud key is stored anywhere. GitHub signs in to AWS with short-lived credentials, and each repo gets one narrow role.
25
+
26
+ ## Secrets
27
+
28
+ - A production secret lives in AWS Parameter Store under `/<product>/<NAME>`, and the deploy reads it on the host. Only its name is in git, in `.env.production.example`.
29
+ - A session never sets, rotates or deletes a secret or a variable. Say exactly what is needed, and the owner sets it.
30
+ - Secrets never reach git, logs, metrics, traces or an error message. Nothing secret is printed in a workflow, because the logs are public.
31
+
32
+ ## Containers
33
+
34
+ - An image is built for arm64, runs as a non-root user, and is tagged with its commit as `ghcr.io/zigordev/<app>`. Only an image that our own pipeline built is deployed.
35
+ - `compose.yaml` describes the whole product as it runs everywhere: for each service a health check, a memory and CPU limit, its route labels and its data stores. `compose.local.yaml` and `compose.production.yaml` hold only the few differences.
36
+ - A container runs with `init: true`, `no-new-privileges` and a `stop_grace_period`, and stops cleanly within 30 seconds of a SIGTERM. No wrapper process sits between the init and the app.
37
+ - Every build context has a `.dockerignore`. A base image's major version changes only together with the Node pin and `engines`.
38
+ - An app reads its settings from environment variables only, listens on `PORT`, and has one name everywhere, `<product>-<part>`: folder, package, compose service, image, telemetry and dashboard.
39
+
40
+ ## The host
41
+
42
+ - The host opens no port to the internet. Traffic arrives through the Cloudflare Tunnel, and a shell arrives through AWS Systems Manager.
43
+ - A host job is a systemd timer, never a cron entry. A container never gets the instance role, and the metadata hop limit stays at 1.
44
+ - Config is checked the way the container receives it, with explicit variables, never with a whole env file.
45
+
46
+ ## On the laptop
47
+
48
+ - `pnpm local:up` starts the whole product in containers from the committed compose files, never from `docker run` commands. `pnpm dev` runs the one app being edited, with hot reload.
49
+ - Never stop, recreate or reconfigure a container you did not start. Test in throwaway containers with their own names, ports and volumes.
@@ -0,0 +1,40 @@
1
+ ---
2
+ paths:
3
+ - "**/*.test.ts"
4
+ - "**/*.test.tsx"
5
+ - "**/*.test.js"
6
+ - "**/*.spec.ts"
7
+ - "**/e2e/**"
8
+ - "**/vitest.config.ts"
9
+ - "**/playwright.config.ts"
10
+ ---
11
+
12
+ # Test rules
13
+
14
+ These rules apply to every test and to every change that needs one.
15
+
16
+ ## What each change needs
17
+
18
+ | Layer | Covers | How |
19
+ | ------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
20
+ | Unit | Every function or service with logic | Vitest, in `*.test.ts` beside the code |
21
+ | API | Every endpoint: success, 400 with every invalid field, 401 and 403, 404, and the error body | `buildApp()` called through `app.inject()`, on a real PostgreSQL |
22
+ | Browser | Every critical path that the app's `docs/user-manual.md` lists, with an axe check on each page | Playwright, against the production-shaped containers |
23
+
24
+ - A bug fix starts with a test that fails without the fix.
25
+ - A new rule or check comes with a test that breaks it and sees it fail.
26
+
27
+ ## What never happens
28
+
29
+ - A threshold is never lowered. Coverage counts all of `src`, with a floor of 90%.
30
+ - A test is never skipped, deleted or made green by updating its snapshot. A wrong test is fixed in its own commit, with the reason.
31
+ - A real dependency is never mocked when a container can run it. Testcontainers starts PostgreSQL, and Mailpit catches the mail.
32
+ - A test never signs in at Google. Sign-in with Google runs against a stand-in.
33
+ - A test never reads `process.env` to reach a dependency. It passes the address in through the app's validated configuration.
34
+
35
+ ## Running them
36
+
37
+ - `pnpm check` runs everything CI runs, and prints how long it took. The target is under 10 minutes.
38
+ - `pnpm check:quick` runs the part that needs no containers, and the push hook runs it.
39
+ - One file runs with `pnpm exec vitest run <path>`.
40
+ - Every test file gets its own copy of the migrated database. Tests that share one clean up after themselves or use their own rows.
@@ -0,0 +1,42 @@
1
+ ---
2
+ paths:
3
+ - "**/apps/*-web/**"
4
+ - "packages/ui/**"
5
+ - "packages/tokens/**"
6
+ - "storybook/**"
7
+ - "**/messages/*.json"
8
+ ---
9
+
10
+ # Web rules
11
+
12
+ These rules apply to every Next.js app and to the design system.
13
+
14
+ ## Building pages
15
+
16
+ - Next.js with the App Router. Server components fetch on the server. Client components load data with TanStack Query through `openapi-react-query`, on the types generated from the API's `openapi.json`.
17
+ - State stays in React: state, context and the URL. There is no global store library.
18
+ - Requests go through the generated client with `openapi-fetch`. There is no axios.
19
+ - A form uses React Hook Form, validated by a Zod schema.
20
+ - The web app and its API share one origin: the API sits under `/api/v1` on the product's own address.
21
+
22
+ ## The design system
23
+
24
+ - Every UI element comes from `@zigordev/ui`. Look for it there before building one. If it is missing, add it to the design system in its own pull request, with its story, and use the released version.
25
+ - An app component only composes design-system components with the app's data and logic. A component with no app data and no business logic belongs in the design system.
26
+ - App styles live in CSS Modules and use the tokens only: no raw colour, size or duration. There is no Tailwind and no CSS-in-JS. Fonts come from Fontsource packages.
27
+ - A component's stories are its browser tests. They pass in light and in dark, with no accessibility finding.
28
+
29
+ ## Text and languages
30
+
31
+ - Every text exists in English and in Spanish, in `messages/en.json` and `messages/es.json`, with identical keys. A key that is missing or empty in one language fails `pnpm check`.
32
+ - Language tags are short: `en`, `es`.
33
+ - Copy is short and in sentence case, with no emoji and no exclamation mark. A button is a verb.
34
+ - Nothing fetches translations at runtime. A person who is not a developer changes a text in Fink, which opens a pull request.
35
+
36
+ ## Quality
37
+
38
+ - WCAG 2.2 AA: keyboard access, visible focus, no axe finding, and `prefers-reduced-motion` respected.
39
+ - Core Web Vitals stay good: LCP up to 2.5 s, INP up to 200 ms and CLS up to 0.1.
40
+ - The content security policy is strict, with a nonce per request.
41
+ - Browser monitoring runs through `@zigordev/rum`. A new interaction joins the app's allow-list in the same pull request, and no personal data leaves the browser.
42
+ - The web app answers `GET /health` at the root, like every app.
@@ -0,0 +1,19 @@
1
+ ---
2
+ paths:
3
+ - ".github/**"
4
+ ---
5
+
6
+ # Workflow rules
7
+
8
+ These rules apply to everything under `.github/`.
9
+
10
+ - An action is pinned to a full commit SHA, with its exact version beside it, such as `# v7.0.1`. The `actions` rule of `zigordev check` fails anything else, and Renovate keeps the pins current.
11
+ - A workflow starts with `permissions: {}`. Each job then gets the least it needs, and a `timeout-minutes`.
12
+ - A value from `${{ }}` reaches a script through `env`, never inline in `run:`.
13
+ - Repos, logs and artifacts are public. Nothing secret is printed, and a job that needs AWS signs in with GitHub's short-lived credentials, never with a stored key.
14
+ - `check` is the one required check, with the same name in every repo. It passes only when every job passed. Never rename it, and never rename or remove a job without saying that the ruleset depends on it.
15
+ - The pipeline lives in `toolkit` as reusable workflows. A repo's own workflow is a short caller, pinned to a commit of `toolkit` like any action.
16
+ - The pipeline runs what `pnpm check` runs on the laptop. A check that exists only in CI is one that only GitHub can run, such as the scan of the code.
17
+ - In a shell step, fetch once into a variable and test the variable. Never pipe `curl` into `grep -q`, which fails under `pipefail`.
18
+ - `zizmor` lints every workflow inside `pnpm check`. A finding is fixed, not suppressed.
19
+ - A workflow that deploys, publishes or applies infrastructure is never dispatched or run again by hand without the owner's yes.
@@ -0,0 +1,84 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/claude-code-settings.json",
3
+ "claudeMdExcludes": ["**/shared/.claude/**"],
4
+ "permissions": {
5
+ "allow": [
6
+ "Bash(pnpm install)",
7
+ "Bash(pnpm install --frozen-lockfile)",
8
+ "Bash(pnpm check)",
9
+ "Bash(pnpm check:quick)",
10
+ "Bash(pnpm lint)",
11
+ "Bash(pnpm typecheck)",
12
+ "Bash(pnpm build)",
13
+ "Bash(pnpm test *)",
14
+ "Bash(pnpm format)",
15
+ "Bash(pnpm format:check)",
16
+ "Bash(pnpm exec vitest run *)",
17
+ "Bash(pnpm exec zigordev check *)",
18
+ "Bash(pnpm exec zigordev sync)"
19
+ ],
20
+ "ask": [
21
+ "Bash(gh repo create *)",
22
+ "Bash(gh repo delete *)",
23
+ "Bash(gh repo edit *)",
24
+ "Bash(gh repo rename *)",
25
+ "Bash(gh repo archive *)",
26
+ "Bash(gh repo unarchive *)",
27
+ "Bash(gh workflow run *)",
28
+ "Bash(gh workflow enable *)",
29
+ "Bash(gh workflow disable *)",
30
+ "Bash(gh run rerun *)",
31
+ "Bash(gh release create *)",
32
+ "Bash(gh release edit *)",
33
+ "Bash(gh release delete *)",
34
+ "Bash(gh label create *)",
35
+ "Bash(gh label edit *)",
36
+ "Bash(gh label delete *)",
37
+ "Bash(tofu apply *)",
38
+ "Bash(tofu destroy *)",
39
+ "Bash(tofu import *)",
40
+ "Bash(tofu state rm *)",
41
+ "Bash(tofu state mv *)",
42
+ "Bash(tofu state push *)",
43
+ "Bash(pnpm publish *)",
44
+ "Bash(npm publish *)"
45
+ ],
46
+ "deny": [
47
+ "Bash(gh secret set *)",
48
+ "Bash(gh secret delete *)",
49
+ "Bash(gh variable set *)",
50
+ "Bash(gh variable delete *)",
51
+ "Bash(aws * put-parameter*)",
52
+ "Bash(aws * delete-parameter*)"
53
+ ]
54
+ },
55
+ "hooks": {
56
+ "PreToolUse": [
57
+ {
58
+ "matcher": "Bash",
59
+ "hooks": [
60
+ {
61
+ "type": "command",
62
+ "command": "sh",
63
+ "args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/guard.sh"],
64
+ "timeout": 30,
65
+ "onFailure": "block"
66
+ }
67
+ ]
68
+ }
69
+ ],
70
+ "PostToolUse": [
71
+ {
72
+ "matcher": "Write|Edit|Bash",
73
+ "hooks": [
74
+ {
75
+ "type": "command",
76
+ "command": "sh",
77
+ "args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/guard.sh"],
78
+ "timeout": 60
79
+ }
80
+ ]
81
+ }
82
+ ]
83
+ }
84
+ }
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: finish-work
3
+ description: Finish a change in a zigordev repo. Formats, runs the full check, commits, pushes, opens the pull request as a draft, marks it ready when it may merge, cleans up after the merge and reports. Use when the work of a task is written, and before saying that it is done.
4
+ ---
5
+
6
+ # Finish work
7
+
8
+ Run these steps in order. Stop at the first one that fails, and say why.
9
+
10
+ 1. **Tests and docs.** The change has the tests it needs, and the docs that describe the behaviour changed with it. A bug fix has a test that failed without the fix.
11
+ 2. **Format, stage, check.** Run `pnpm format`, then `git add` the files of this change, then `pnpm check`. The order matters, because the hooks read the working tree and not the staged files. The check must pass, and it prints how long it took.
12
+ 3. **Try it for real** when the change can be observed: run the app, send the request, open the page. Note what you did and what you saw.
13
+ 4. **Read your own diff.** `git diff --cached` shows one concern, no comment, no secret, and nothing you did not mean to change.
14
+ 5. **Commit** with a Conventional Commits title. The body says why the change was needed. A breaking change gets `!` after the type and a closing `BREAKING CHANGE:` line.
15
+ 6. **Push the branch** with `git push -u origin <branch>`. Never push to `main`.
16
+ 7. **Open the pull request as a draft**, with `gh pr create --draft`. Its title is the commit title, because a squash merge turns it into the commit. Its description has these sections: What, Why, How it was tested, Observability, Docs, Follow-ups.
17
+ 8. **Wait for `check`.** A red check is yours to fix before anything else.
18
+ 9. **Mark it ready, or leave it a draft.** Marking a pull request ready means: merge it when `check` is green. Do that with `gh pr ready` and then `gh pr merge --auto --squash`. Leave it a draft instead, and say why, when the change is one that waits for the owner.
19
+ 10. **After the merge**, run `git switch main` and `git pull`, and delete the local branch. Stop every server, container and process you started.
20
+ 11. **Report.** Say what changed, with the pull request link. Say how it was checked, and what was not checked. Say what needs the owner. Show the output of anything that failed.
@@ -0,0 +1,16 @@
1
+ ---
2
+ name: start-work
3
+ description: Start a change in a zigordev repo. Checks that the folder is clean and on main, that commits and gh act as zigordev, then cuts the working branch from origin/main and installs. Use before the first edit of any task that will end in a commit.
4
+ ---
5
+
6
+ # Start work
7
+
8
+ Run these steps in order, in the repo's own folder. Stop at the first one that fails, and say why.
9
+
10
+ 1. **Look for anything that waits for the owner.** An infrastructure change, a migration that deletes data, a new tool or service, a new major version and a change to repo settings each need a yes first. Ask now, before building.
11
+ 2. **Check the folder.** `git status --short --branch` must show `main` with nothing uncommitted. If it shows anything else, stop and ask. Never stash, commit or carry changes you did not make. Never work in a worktree or in a second copy of the repo.
12
+ 3. **Check the identity.** `git config user.name` and `git config user.email` must print `zigordev` and `zigordev@gmail.com`. If either is missing or different, set both in this repo: `git config user.name zigordev` and `git config user.email zigordev@gmail.com`.
13
+ 4. **Check the account.** `gh config get user -h github.com` must print `zigordev`. If it prints another account, run `gh auth switch -u zigordev` and say that you did.
14
+ 5. **Branch.** Run `git fetch origin`, then `git switch -c <type>/<short-summary> origin/main`. The type is a Conventional Commits type, as in `fix/login-redirect`.
15
+ 6. **Install.** Run `pnpm install`, so the dependencies match the lockfile and the git hooks are active.
16
+ 7. **Read first.** Read the README and the docs of the area before changing its behaviour. Look at how the product template and the other repos already solve the same problem, and solve it the same way.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: write-decision-record
3
+ description: Write a decision record (ADR) in docs/adr. Use when a change adds, removes or replaces a tool, a service, a data store, a provider, a deploy path or a public interface, or when the owner takes a decision that a later reader will ask about.
4
+ ---
5
+
6
+ # Write a decision record
7
+
8
+ A decision record is one short page that says what was decided and why, for a reader who was not there.
9
+
10
+ 1. **Find the number.** List `docs/adr/`. The new record takes the next free four-digit number. Numbers start at 0001 in each repo.
11
+ 2. **Copy the template.** Copy [template.md](template.md), which sits beside this file, to `docs/adr/NNNN-short-title.md`. The title is a short statement of the decision, and the file name repeats it in kebab-case.
12
+ 3. **Fill it in**, in this order:
13
+ - **Context**: the problem, the facts, and what went wrong before. Give numbers and absolute dates.
14
+ - **Decision**: what we do, stated as a rule someone can check.
15
+ - **Consequences**: what becomes easier, what becomes harder, and what has to change elsewhere.
16
+ - **Alternatives considered**: each option not taken, and why. Give the price of any paid option.
17
+ 4. **Set the status.** A record is `proposed` in its pull request and `accepted` once the owner has agreed. Only the owner takes a decision: put the options to them one at a time, with the pros and cons of each.
18
+ 5. **Supersede, never edit.** An accepted record is not edited. A new record names the one it replaces under `Supersedes`, and the index marks the old one as superseded.
19
+ 6. **Add it to the index** in `docs/adr/README.md`, in the same pull request.
20
+ 7. **Keep it to one page.** Details belong in the handbook or the docs, and the record links to them.
@@ -0,0 +1,21 @@
1
+ # NNNN. Short title
2
+
3
+ - Status: proposed
4
+ - Date: YYYY-MM-DD
5
+ - Supersedes: none
6
+
7
+ ## Context
8
+
9
+ What forces the decision: the problem, the facts, and what went wrong before.
10
+
11
+ ## Decision
12
+
13
+ What we do, stated as a rule someone can check.
14
+
15
+ ## Consequences
16
+
17
+ What becomes easier, what becomes harder, and what has to change elsewhere.
18
+
19
+ ## Alternatives considered
20
+
21
+ Each option not taken, and why.
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["@zigordev/dev/commitlint"]
3
+ }
@@ -0,0 +1,23 @@
1
+ ## What
2
+
3
+ Say what this pull request changes, in a few sentences or a short table.
4
+
5
+ ## Why
6
+
7
+ Say why the change is needed, and why it is done this way.
8
+
9
+ ## How it was tested
10
+
11
+ Say what you ran and what you saw, and what was not tested.
12
+
13
+ ## Observability
14
+
15
+ Say how the change shows when it runs: its logs, metrics, traces and alerts. When nothing of it runs, say so.
16
+
17
+ ## Docs
18
+
19
+ Say which docs changed with the behaviour, or why none had to.
20
+
21
+ ## Follow-ups
22
+
23
+ List what is left for later, or write "None".
@@ -0,0 +1,8 @@
1
+ {
2
+ "config": {
3
+ "MD013": false
4
+ },
5
+ "globs": ["**/*.md"],
6
+ "ignores": ["**/pull_request_template.md"],
7
+ "gitignore": true
8
+ }
@@ -0,0 +1,2 @@
1
+ extends:
2
+ - node_modules/@zigordev/dev/lefthook.yml
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": ["github>zigordev/toolkit//renovate/default"],
4
+ "ignorePresets": ["mergeConfidence:all-badges", "mergeConfidence:age-confidence-badges"]
5
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "es2024",
5
+ "lib": ["es2024"],
6
+ "module": "nodenext",
7
+ "moduleResolution": "nodenext",
8
+ "strict": true,
9
+ "noUncheckedIndexedAccess": true,
10
+ "noImplicitOverride": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "verbatimModuleSyntax": true,
13
+ "rewriteRelativeImportExtensions": true,
14
+ "isolatedModules": true,
15
+ "erasableSyntaxOnly": true,
16
+ "resolveJsonModule": true,
17
+ "skipLibCheck": true,
18
+ "forceConsistentCasingInFileNames": true
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./node.json",
4
+ "compilerOptions": {
5
+ "declaration": true,
6
+ "declarationMap": true
7
+ },
8
+ "exclude": ["${configDir}/src/**/*.test.ts"]
9
+ }