create-tigra 4.0.0 → 4.1.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/README.md +236 -82
  3. package/bin/create-tigra.js +74 -1
  4. package/lib/patchers/diagnostics.patcher.js +149 -0
  5. package/lib/patchers/metrics.patcher.js +145 -0
  6. package/modules/diagnostics/diagnostics.md +65 -0
  7. package/modules/diagnostics/prisma/diagnostic-bucket.prisma +22 -0
  8. package/modules/diagnostics/prisma/migration.sql +43 -0
  9. package/modules/diagnostics/server/__tests__/diagnostics.collector.test.ts +72 -0
  10. package/modules/diagnostics/server/__tests__/diagnostics.context.test.ts +51 -0
  11. package/modules/diagnostics/server/__tests__/diagnostics.integration.test.ts +107 -0
  12. package/modules/diagnostics/server/__tests__/diagnostics.service.test.ts +31 -0
  13. package/modules/diagnostics/server/diagnostics.collector.ts +95 -0
  14. package/modules/diagnostics/server/diagnostics.context.ts +73 -0
  15. package/modules/diagnostics/server/diagnostics.repo.ts +69 -0
  16. package/modules/diagnostics/server/diagnostics.routes.ts +17 -0
  17. package/modules/diagnostics/server/diagnostics.sample.ts +92 -0
  18. package/modules/diagnostics/server/diagnostics.schemas.ts +33 -0
  19. package/modules/diagnostics/server/diagnostics.service.ts +44 -0
  20. package/modules/metrics/client/WebVitalsReporter.tsx +35 -0
  21. package/modules/metrics/client/__tests__/WebVitalsReporter.test.ts +65 -0
  22. package/modules/metrics/client/metrics.pages.ts +5 -0
  23. package/modules/metrics/performance.md +56 -0
  24. package/modules/metrics/prisma/metric-bucket.prisma +18 -0
  25. package/modules/metrics/prisma/migration.sql +17 -0
  26. package/modules/metrics/server/__tests__/metrics.collector.test.ts +75 -0
  27. package/modules/metrics/server/__tests__/metrics.integration.test.ts +88 -0
  28. package/modules/metrics/server/__tests__/metrics.schemas.test.ts +36 -0
  29. package/modules/metrics/server/__tests__/metrics.service.test.ts +84 -0
  30. package/modules/metrics/server/metrics.collector.ts +130 -0
  31. package/modules/metrics/server/metrics.pages.ts +3 -0
  32. package/modules/metrics/server/metrics.repo.ts +45 -0
  33. package/modules/metrics/server/metrics.routes.ts +46 -0
  34. package/modules/metrics/server/metrics.schemas.ts +57 -0
  35. package/modules/metrics/server/metrics.service.ts +100 -0
  36. package/package.json +3 -2
  37. package/template/AGENTS.md +17 -10
  38. package/template/README.md +79 -0
  39. package/template/client/README.md +92 -21
  40. package/template/client/src/app/focus-rings.policy.test.ts +88 -0
  41. package/template/client/src/app/globals.css +46 -0
  42. package/template/client/src/app/layout.tsx +5 -0
  43. package/template/client/src/app/page.tsx +2 -2
  44. package/template/client/src/components/common/InputModalityTracker.tsx +12 -0
  45. package/template/client/src/components/ui/input.tsx +3 -2
  46. package/template/client/src/lib/input-modality.test.ts +79 -0
  47. package/template/client/src/lib/input-modality.ts +52 -0
  48. package/template/server/README.md +108 -0
  49. package/template/server/docs/logging.md +16 -2
  50. package/template/server/docs/testing.md +20 -2
package/CHANGELOG.md ADDED
@@ -0,0 +1,178 @@
1
+ # Changelog
2
+
3
+ A generated project never changes after it is created: these notes say what new projects get. To bring an older
4
+ project along, port the changes you need; the guides in [docs/](docs/) cover the ones that need care.
5
+
6
+ ## 4.1.0 (2026-11-10)
7
+
8
+ - Add optional performance metrics for Fastify requests, Node runtime health, named operations, and Next.js Web Vitals. The module stores five-minute aggregates in MySQL and provides a read-only admin API.
9
+ - Add optional error and warning tracking with sanitized diagnostic samples, an hourly MySQL view, and a read-only admin API for agent investigations.
10
+ - Choose either module independently in the wizard or install it later with `npx create-tigra add metrics` or `npx create-tigra add diagnostics`. Each module adds its own migration and maintenance guidance.
11
+ - Expand generated agent guidance on architecture and reuse. Search the relevant client or server code for the closest behavior and follow imports and callers before adding a new implementation.
12
+
13
+ - Focus rings show only for keyboard users. Radix menus and selects cancel the mouse press on their trigger and then
14
+ move focus by script, so Chrome treated mouse use as keyboard use and drew focus rings (for example on a menu item
15
+ under the pointer) until the first ordinary click. The client now keeps `<html data-input="pointer" | "keyboard">`
16
+ (`lib/input-modality.ts`, mounted by `components/common/InputModalityTracker.tsx` in the root layout), Tailwind's
17
+ `focus-visible:` variant stays off in pointer mode, and a global rule drops plain-CSS focus outlines in pointer
18
+ mode. Text fields still show focus for mouse users too.
19
+ - Keyboard focus has one quiet style everywhere: a 1px accent line on the element's own edge and a faint accent tint
20
+ inside, with nothing drawn outside the element (it replaces the 3px half-transparent rings). Accent-filled controls
21
+ (primary and destructive buttons, hand-styled `bg-primary` / `bg-destructive` links) get the edge plus a 1px
22
+ page-coloured line inside it, since their fill is the accent; menu items and select options keep their highlight
23
+ only.
24
+ - Text fields lose the 3px glow too: focus turns the field's own border accent, an invalid field's border is red, and a
25
+ focused invalid field also gets a faint red tint inside, so focus stays visible on a field with an error.
26
+ - To port into an older project: copy those two files, add `data-input="pointer"` to `<html>` and mount the tracker
27
+ in `app/layout.tsx`, copy the `@custom-variant focus-visible` line and the four focus rules at the end of
28
+ `app/globals.css` ("Focus rings", "Keyboard focus", "Filled controls", "Text fields"), and change any `focus:ring`
29
+ (for example a dialog's close button) to `focus-visible:ring`. In `components/ui/input.tsx` (and a textarea, if
30
+ you have one) keep only `focus-visible:border-ring` and `aria-invalid:border-destructive` from the focus and
31
+ invalid classes. Remove any own `:focus-visible { outline }` a menu item or option has.
32
+
33
+ ## 4.0.1 (2026-10-20)
34
+
35
+ Documentation only, no code changes.
36
+
37
+ - The README explains what create-tigra builds, area by area, how a request travels, the pages you add yourself,
38
+ the everyday commands, `create-tigra add`, and where every guide lives.
39
+ - Generated projects get a root `README.md`, a `server/README.md` and a rewritten `client/README.md` (it was
40
+ create-next-app's default text).
41
+ - `server/docs/testing.md` covers the client tests and the route-contract rule; `server/docs/logging.md` covers
42
+ secret redaction.
43
+ - This changelog, now shipped in the npm package.
44
+ - The CLI fills the project's name, database and local ports into its new README.
45
+
46
+ ## 4.0.0 (2026-10-20)
47
+
48
+ A full review of the template, area by area. Every change was tested on fresh projects with and without the
49
+ email-verification module, and the Docker images were built and run on Coolify.
50
+
51
+ ### Breaking for new projects
52
+
53
+ - Generated apps need **Node 24 and npm 11.19+** (the 3.3.0 images ran Node 20). The images use `node:24-alpine`
54
+ pinned by digest, and the tested lockfiles ship with every project and install with `npm ci`.
55
+ - Local and test MySQL is **8.4**.
56
+ - In production the server refuses to start without any migration, without `REDIS_URL`, or when Redis cannot be
57
+ reached within 10 s of starting.
58
+ - `TRUST_CLOUDFLARE`, `DATABASE_POOL_MIN` and `DATABASE_POOL_MAX` are gone; `CLOUDFLARE_ORIGIN_SECRET` is new.
59
+ - Wrong input always answers `422 VALIDATION_FAILED` with the list of fields.
60
+ - The public `/api/v1/health` answers only its status; the full report moved to `GET /api/v1/admin/health`.
61
+ - Client: `src/middleware.ts` is now `src/proxy.ts` (Next 16's name), and the Redux store is created per visitor
62
+ with `makeStore()` instead of being one exported `store`.
63
+ - `create-tigra add email-verification` is meant for 4.x projects: it copies tests that use the 4.x test helpers.
64
+
65
+ ### Generator
66
+
67
+ - New projects ship their first migration (`0_init`); a check keeps it equal to the schema.
68
+ - The README no longer tells you to copy `.env.example` over the `.env` that holds the generated secrets.
69
+ - The CLI warns when Node is older than 24 or npm older than 11.19.
70
+
71
+ ### Foundation and configuration
72
+
73
+ - `REDIS_URL` is required in production; on/off switches accept only `true` or `false`.
74
+ - `CLIENT_URL` is required in production only when emails can go out.
75
+ - Email verification is off unless the email module is installed.
76
+ - The production example uses `PORT=8000` and caps the database pool (`?connection_limit=5`).
77
+
78
+ ### Request pipeline
79
+
80
+ - The client IP is verified before it is believed: behind Cloudflare, behind Coolify's Traefik, or direct
81
+ ([guide](docs/client-ip-behind-proxies.md)).
82
+ - Rate limits for public use: clear wait times (`retryAfterSeconds`), a per-address email cap, overrides through
83
+ env (`RATE_LIMIT_OVERRIDES`, `RATE_LIMIT_MULTIPLIER`); token flows answer a clear 503 while Redis is down.
84
+ - `CORS_ORIGIN` is checked at boot (bare origins only, with the fix printed).
85
+ - Auth cookies are never `SameSite=None`: the tokens are Strict and the session marker is Lax, so a link from
86
+ another site no longer bounces a signed-in user to `/login`.
87
+ - A warning when production runs on plain http (the browser would drop the login cookies).
88
+ - Log redaction covers secrets at every level it promises; an inbound `X-Request-Id` is kept only when short and
89
+ plain.
90
+
91
+ ### Sessions and accounts
92
+
93
+ - Two tabs refreshing at once: exactly one wins and the other keeps its session.
94
+ - Refresh, reset and verification tokens are stored as SHA-256 fingerprints only.
95
+ - Signing out, signing out everywhere, a password reset and an admin revoke end the access token at once; a banned
96
+ user's token answers `403 ACCOUNT_DEACTIVATED` at once.
97
+ - A password-reset link works once, even when used twice at the same moment.
98
+ - A wrong password on change-password or delete-account answers 422, not 401; changing your own password keeps
99
+ this device signed in.
100
+ - Strangers can no longer use up a user's verification emails.
101
+
102
+ ### Users and files
103
+
104
+ - Multipart fields are capped, so one upload cannot hold about 1 GB of memory; a file cut at the size limit
105
+ answers 413.
106
+ - Avatar formats are judged by their bytes (JPEG, PNG, WebP, HEIC, AVIF); HEIC is proven to decode in the image
107
+ build. Every avatar gets a new file name, and the old file goes only after the swap.
108
+ - A deleted account's photo stops being public at once; names are trimmed before their length is checked.
109
+ - The server warns at boot when uploads are not on a persistent volume.
110
+
111
+ ### Admin API
112
+
113
+ - An admin cannot ban themselves, and the last admin cannot delete their own account.
114
+ - IP blocks use one canonical spelling, match however they were written, and cannot block an admin's own or a
115
+ private address.
116
+ - Deleted accounts can be listed and restored during their 30 days.
117
+ - `make-admin` promotes an existing account to admin (the first admin, or recovery).
118
+ - User detail says `lastActiveAt`; the user list's filters work again.
119
+
120
+ ### Background jobs
121
+
122
+ - Jobs run about a minute after every start, then on their schedule, so frequent deploys never postpone them
123
+ (before, an app deployed at least daily never purged deleted accounts).
124
+ - Expired automatic IP blocks are pruned hourly; an account another process already purged is not a failure.
125
+
126
+ ### Outbound requests and email
127
+
128
+ - `safeHttpClient` for URLs a user supplied: it refuses internal addresses on every redirect hop. The
129
+ internal-address check no longer misses hex IPv4-mapped forms.
130
+ - Outbound URLs are logged redacted; failures carry their status and kind.
131
+ - Sending email gives up after 10 s, and recipients are logged masked. Production refuses the placeholder Resend
132
+ key and sender.
133
+
134
+ ### Health, logs and shutdown
135
+
136
+ - Memory is judged against the heap limit; a failing check logs the real error.
137
+ - The database and Redis are checked at most once per 5 s for all probes together.
138
+ - Request lines carry JSON fields in production and never keep the query string.
139
+ - Crashes and failed starts exit 1, and shutdown has an 8 s deadline (inside Docker's 10 s).
140
+
141
+ ### Testing and CI
142
+
143
+ - The critical advisories in the shipped dependencies are cleared.
144
+ - Integration tests ship with every project (166, or 172 with the email module): every route's contract, plus identity, users, admin, jobs, health
145
+ and email behaviour, against a real MySQL and Redis (Testcontainers, or services you already run). The route
146
+ contract fails when a new route is never called.
147
+ - An honest coverage floor counts every file, on the server and now on the client.
148
+ - The server's lint refuses unawaited and misused promises.
149
+ - New projects ship CI, a weekly audit of production dependencies and Dependabot (security updates for npm and
150
+ Actions, monthly base-image updates).
151
+
152
+ ### Deployment
153
+
154
+ - The images run on any x86-64 CPU: sharp is built on a pinned libvips, so VPSes without x86-64-v2 work.
155
+ - curl health checks; plain (uncoloured) production logs.
156
+ - The client image build stops when `NEXT_PUBLIC_API_BASE_URL` is missing; the client health check is `/healthz`,
157
+ which works even when the home page redirects.
158
+ - A Coolify checklist in the README and `server/docs/deployment.md`: what a deploy does, safe migrations (expand,
159
+ deploy, contract), rollback, and the libvips build time.
160
+
161
+ ### Guidance for AI agents
162
+
163
+ - The completion check reviews the patch actually handed over (`git diff HEAD` plus new files). Claude Code's
164
+ `/security-review` is not that check: it only sees commits.
165
+ - The root `AGENTS.md` tells Codex to read the server and client files, which it does not load by itself.
166
+ - The agent files now carry the migration, job, deployment and test rules, and the security workflow covers the
167
+ client's security code.
168
+
169
+ ### Client
170
+
171
+ - A Vitest unit suite (session rules, the proxy, redirect safety, error parsing) runs in CI with a coverage floor.
172
+ - A refresh race lost to another tab is replayed instead of signing out; a ban mid-session signs out at once.
173
+ - Anonymous visitors make no API calls (it was two failing calls per page view).
174
+ - Protected paths match whole segments (`/administrator` is no longer treated as `/admin`).
175
+ - The server's field errors show under their fields; the register rules mirror the server's.
176
+ - The header is right on the first render, and hydration uses the server's state (a second tab could hit a
177
+ hydration mismatch).
178
+ - The welcome page links to this repository.
package/README.md CHANGED
@@ -1,108 +1,191 @@
1
1
  # create-tigra
2
2
 
3
- Scaffold a production-ready full-stack application with **Next.js 16** + **Fastify 5** + **Prisma** + **Redis**.
3
+ `create-tigra` generates a full-stack TypeScript app that is ready for production on day one: a **Fastify 5** API
4
+ with **Prisma** (MySQL 8.4) and **Redis 7**, and a **Next.js 16** client. Sign-in and sessions, abuse protection,
5
+ uploads, an admin API, background jobs, health checks, tests, CI and Docker images for Coolify are already built,
6
+ tested and documented, so a new project starts at its own features instead of its plumbing.
4
7
 
5
- ## Quick Start
8
+ The client ships the wiring, not the screens. Every app looks different, so you write the pages; the template gives
9
+ them the API client, the sign-in flow, the forms and the security headers they need.
6
10
 
7
11
  ```bash
8
12
  npx create-tigra my-app
9
13
  ```
10
14
 
11
- ## What's Included
15
+ The CLI asks for a project name and whether new users must verify their email, then writes the project with fresh
16
+ secrets in its git-ignored `.env` files.
17
+
18
+ - [What you get](#what-you-get)
19
+ - [Quick start](#quick-start)
20
+ - [Everyday commands](#everyday-commands)
21
+ - [Testing and CI](#testing-and-ci)
22
+ - [Deploying to Coolify](#deploying-to-coolify)
23
+ - [Adding a module later](#adding-a-module-later)
24
+ - [Documentation](#documentation)
25
+ - [Upgrading from 3.x](#upgrading-from-3x)
26
+
27
+ ## What you get
28
+
29
+ ```text
30
+ my-app/
31
+ ├── server/ Fastify 5 API: TypeScript, Prisma, MySQL 8.4, Redis 7, Vitest, Dockerfile
32
+ ├── client/ Next.js 16 app: App Router, React 19, Tailwind v4, shadcn/ui, Vitest, Dockerfile
33
+ ├── .github/ CI on every push, a weekly dependency audit, Dependabot
34
+ ├── AGENTS.md rules for AI coding agents (one more in server/ and client/), CLAUDE.md imports them
35
+ └── .agents/ the security-audit skill the agents use before they finish a change
36
+ ```
37
+
38
+ How a request travels:
39
+
40
+ ```text
41
+ Browser
42
+ │ client/src/proxy.ts: a fresh CSP nonce per request, security headers,
43
+ │ signed-out visitors sent away from protected pages
44
+ ▼
45
+ Next.js client ── axios, httpOnly cookies ──▶ Fastify API /api/v1/...
46
+ one refresh per tab; a refresh race │ CORS allowlist + origin check, real visitor IP,
47
+ between tabs is replayed, not a sign-out │ IP blocks, per-route rate limits, Zod input checks
48
+ ▼
49
+ route → controller → service → repository → Prisma → MySQL
50
+ │ Redis: rate limits, lockout, IP blocks
51
+ └─ background jobs · Resend email · health probes
52
+ ```
12
53
 
13
- ### Client (Next.js 16)
54
+ ### Server
14
55
 
15
- | Feature | Technology |
56
+ | Area | What is built |
16
57
  |---|---|
17
- | Framework | Next.js 16 (App Router, React 19) |
18
- | Styling | Tailwind CSS v4, shadcn/ui, OKLCH color system |
19
- | State | Redux Toolkit (auth), React Query v5 (server data) |
20
- | Forms | React Hook Form + Zod validation |
21
- | HTTP | Axios with httpOnly cookie auth + auto refresh |
22
- | Auth UI | Login, register and forgot-password form components (no pages: add your own `/login` and `/register` pages. The proxy, `src/proxy.ts`, sends signed-out visitors of `/dashboard`, `/profile` and `/admin` to `/login`) |
23
- | Components | Header, Footer, Loading, Error, Empty states |
24
- | Theme | Light/Dark mode with next-themes |
25
- | Testing | Vitest unit tests of the client's logic: the API client's session rules (refresh, a lost refresh race between tabs, a ban mid-session), the proxy's CSP and redirects, redirect safety, error and field-error parsing; a coverage floor in CI |
26
-
27
- ### Server (Fastify 5)
28
-
29
- | Feature | Technology |
58
+ | Accounts and sign-in | Register, sign in, sign out, sign out everywhere, the list of your sessions, forgot and reset password by email. Tokens live in httpOnly cookies (access 15 min, refresh 7 days by default); passwords are hashed with Argon2id. |
59
+ | Sessions | Every refresh rotates the token. When two tabs refresh at once, exactly one wins and the other keeps its session. Tokens are stored only as SHA-256 fingerprints. Signing out, a password reset, a ban or an admin revoke ends the access token at once, not 15 minutes later. |
60
+ | Abuse protection | Rate limits per route and per IP, tuned from env (`RATE_LIMIT_MULTIPLIER`, `RATE_LIMIT_OVERRIDES`). A login lockout per email and IP (the 15th failure locks for 15 min, the 30th for 1 h) that a stranger cannot use against the real user. An automatic IP block for repeat offenders, a manual block list, and a per-address cap on emails anyone can trigger. Every "slow down" answer says how long to wait. |
61
+ | Real visitor address | Verified behind Cloudflare and Coolify's Traefik before it is believed, so nobody can pick their own rate-limit key or get someone else blocked. Check it any time at `GET /api/v1/admin/client-ip`. |
62
+ | Input and errors | Zod validates every input. Wrong input always answers `422 VALIDATION_FAILED` with the list of fields (never the submitted values); an unexpected error answers a generic 500 and is logged in full on the server. |
63
+ | Users and files | Profile, password change, account deletion (30 days to change your mind, then purged). Avatars are judged by their bytes (JPEG, PNG, WebP, HEIC, AVIF), stored as WebP with location data stripped, capped at 10 MB and 50 megapixels. Private files are served only to their owner. |
64
+ | Admin API | Stats, the user list (search, role, status, deleted accounts), user detail, ban and unban, role change, restoring a deleted account, the session list and revoke, IP blocks. An admin cannot ban themselves and the last admin cannot delete their account. The first admin is promoted with `make-admin`. |
65
+ | Outbound requests | One shared HTTP client with timeouts and redacted logs, plus `safeHttpClient` for URLs a user supplied: it refuses internal addresses (localhost, private networks, cloud metadata) on every redirect hop. |
66
+ | Email | Resend, with a 10 s timeout and masked addresses in the logs. Optional email verification for new users. |
67
+ | Background jobs | Run inside the server process, no extra service: expired sessions and tokens hourly, deleted accounts past 30 days daily, Cloudflare's IP list daily. Each first runs about a minute after the server starts, so frequent deploys never postpone them. |
68
+ | Health and logs | `/api/v1/live`, `/ready` and `/health` for probes, and the full report for admins at `/api/v1/admin/health`. One log line per request (JSON fields in production, never the query string) with passwords, tokens, cookies and keys redacted. A crash exits 1; shutdown finishes in-flight requests within 8 s. |
69
+ | Database and Redis | MySQL 8.4 with Prisma 6. New projects ship their first migration; production applies migrations at start and refuses to start without one. Production also refuses to start without Redis, because the limits, the lockout and the IP blocks depend on it. |
70
+ | Local infrastructure | Docker Compose for MySQL and Redis, reachable from your machine only; phpMyAdmin and Redis Commander when you ask for them. Each project gets its own ports, so several can run side by side. |
71
+
72
+ ### Client
73
+
74
+ | Area | What is built |
30
75
  |---|---|
31
- | Framework | Fastify 5 with TypeScript (strict) |
32
- | Database | MySQL 8.4 + Prisma 6 ORM |
33
- | Cache | Redis 7 (ioredis) |
34
- | Auth | JWT (httpOnly cookies), session management |
35
- | Validation | Zod schemas on all inputs |
36
- | Security | Helmet, CORS, rate limiting (per route, per IP, set through ENV), login lockout, IP auto-block, password hashing (Argon2). If Redis goes down, the limits, lockout and blocks are off until it is back |
37
- | File uploads | Multipart + Sharp image optimization |
38
- | Logging | Pino with pretty dev output |
39
- | Testing | Vitest: unit tests (no database needed) and integration tests of every route against a real MySQL and Redis (Testcontainers, or services you already run); a coverage ratchet; CI, a weekly dependency audit and Dependabot security updates for GitHub included |
40
- | Dev tools | Docker Compose (MySQL, phpMyAdmin, Redis, Redis Commander) |
41
- | Production images | Node 24 Alpine Dockerfiles (server and client) with sharp built on a pinned libvips, so they run on any x86-64 CPU, including VPSes without x86-64-v2, plus curl for Coolify's health check |
76
+ | Framework | Next.js 16 (App Router, Server Components by default), React 19, TypeScript strict. |
77
+ | Security | `src/proxy.ts` (Next 16's name for middleware): a fresh CSP nonce per request with `strict-dynamic`, security headers, and a redirect to sign-in for protected pages. Tokens never reach JavaScript. |
78
+ | API client | Axios with httpOnly cookies. Parallel 401s share one refresh; a refresh race lost to another tab is replayed instead of signing out; a ban mid-session signs out at once; "slow down" answers show one toast with the wait time. |
79
+ | Sign-in wiring | `useAuth`, `useCurrentUser`, `AuthInitializer`, and the login, register and forgot-password form components: inline limit messages, the server's field errors under their fields, and a `?from=` redirect that only ever lands on your own site. Anonymous visitors make no API calls. |
80
+ | Admin wiring | Hooks and services for stats, users and sessions, ready for your own admin screens. |
81
+ | State | Redux Toolkit only for the signed-in user (one store per visitor), React Query for server data. |
82
+ | Design system | Tailwind CSS v4, shadcn/ui, OKLCH colour tokens with light and dark themes (next-themes). |
83
+ | Components | Header, footer, layouts, links with smooth navigation, a safe image, confirm dialog, empty state, pagination, loading states, error and not-found pages. |
84
+ | Testing | Vitest unit tests of the client's logic (session rules, the proxy, redirect safety, error parsing) with a coverage floor in CI. |
85
+
86
+ ### Pages are yours
87
+
88
+ Besides a welcome page and the `/healthz` health check, the client ships no pages, on purpose. Add yours at the
89
+ paths in `client/src/lib/constants/routes.ts`; the proxy, the API client and the emails already send people there:
90
+
91
+ | Path | Your page | What to use |
92
+ |---|---|---|
93
+ | `/login` | sign in | `LoginForm` (reads `?from=`) |
94
+ | `/register` | sign up | `RegisterForm` |
95
+ | any path you like | forgot password | `ForgotPasswordForm` |
96
+ | `/reset-password?token=…` | new password, from the emailed link | `useResetPassword` |
97
+ | `/verify-account?token=…` | email verification (email module) | `useVerifyAccount`, `useSendVerification` |
98
+ | `/dashboard`, `/profile`, `/admin` and below | signed-in areas, protected by the proxy | `useCurrentUser`, the admin hooks |
42
99
 
43
- ### Codex Development
100
+ The protected list lives next to the routes (`PROTECTED_PATHS`); add your own areas there.
44
101
 
45
- Includes concise `AGENTS.md` guidance at the project root and scoped guidance inside `client/` and `server/`, with matching `CLAUDE.md` files that import them so Claude Code reads the same rules. Generated projects also include Cloudflare's MIT-licensed `security-audit` repository skill (in `.agents/skills/` for Codex, with a thin pointer in `.claude/skills/` for Claude Code). Meaningful server changes must use its focused guidance and, before completion, scan the working-tree patch: `security-diff-scan` when the Codex Security plugin is installed, or `/security-review` in Claude Code.
102
+ ### Built for AI agents
46
103
 
47
- The security workflow falls back to the bundled skill when Codex Security is unavailable, while full or deep repository audits remain explicit operations rather than an automatic cost on every edit.
104
+ - `AGENTS.md` at the root and in `server/` and `client/`, with `CLAUDE.md` files that import them, so Codex and
105
+ Claude Code read the same rules: the architecture, the sources of truth, safe migrations, deployment and tests.
106
+ - Cloudflare's MIT-licensed `security-audit` skill (`.agents/skills/`, with a pointer in `.claude/skills/`). Before
107
+ finishing a meaningful change, the agent reviews the patch it is handing over (`git diff HEAD` plus new files):
108
+ with the Codex Security plugin's diff scan when it is installed, otherwise with this skill. Full audits stay an
109
+ explicit request.
110
+ - The code itself is the guide: one layout per module, one response and error shape, one rate-limit config, and a
111
+ route-contract test that fails when a new route has no test.
48
112
 
49
- ## Prerequisites
113
+ ## Quick start
50
114
 
51
- - **Node.js** 24+ with **npm** 11.19+ for the generated apps (the CLI itself runs on Node 22.12+). Early Node 24 releases ship an older npm 11 whose lockfiles the Docker images reject; check `npm -v` and update with `npm install -g npm@11`.
52
- - **Docker** (for MySQL and Redis)
115
+ Prerequisites:
53
116
 
54
- ## After Scaffolding
117
+ - **Node.js 24+** with **npm 11.19+** for the generated apps (the CLI itself runs on Node 22.12+). Early Node 24
118
+ releases ship an older npm 11 whose lockfiles the Docker images reject: check `npm -v`, update with
119
+ `npm install -g npm@11`.
120
+ - **Docker**, for the local MySQL and Redis.
55
121
 
56
122
  ```bash
57
- # 1. Start infrastructure
58
- cd my-app/server
59
- docker compose up -d
123
+ npx create-tigra my-app
60
124
 
61
- # 2. Install server dependencies & set up database
62
- # (npm ci installs the shipped package-lock.json exactly, without rewriting it;
63
- # the CLI already wrote server/.env and client/.env with fresh secrets, so do
64
- # not copy .env.example over them: the server refuses its placeholder secret)
65
- npm ci
125
+ # Server: infrastructure, database, API
126
+ cd my-app/server
127
+ npm ci # installs the shipped lockfile exactly
128
+ npm run docker:up # MySQL and Redis for this project
66
129
  npm run prisma:generate
67
- npm run prisma:migrate:dev # creates the tables from the shipped 0_init migration
68
-
69
- # 3. Start the server
70
- npm run dev
130
+ npm run prisma:migrate:dev # creates the tables from the shipped first migration
131
+ npm run dev # http://localhost:8000
71
132
 
72
- # 4. In a new terminal, set up the client
133
+ # Client, in a second terminal
73
134
  cd my-app/client
74
135
  npm ci
75
- npm run dev
136
+ npm run dev # http://localhost:3000
76
137
  ```
77
138
 
78
- - Server: http://localhost:8000
79
- - Client: http://localhost:3000
80
- - phpMyAdmin and Redis Commander (optional, see below): each project gets its own ports, so several projects can run side by side. The CLI prints them when it finishes; they are also in `server/docker-compose.yml`.
139
+ The CLI already wrote `server/.env` and `client/.env` with fresh secrets. Do not copy `.env.example` over them: the
140
+ server refuses the example's placeholder secret.
81
141
 
82
- The admin UIs (phpMyAdmin, Redis Commander) are behind the docker-compose `tools` profile and do **not** start with plain `docker compose up -d`. Start them with:
142
+ The database admin tools are off by default. `npm run docker:tools` starts phpMyAdmin and Redis Commander on the
143
+ ports the CLI printed (also in `server/docker-compose.yml`); `npm run docker:down` stops everything.
83
144
 
84
- ```bash
85
- cd my-app/server
86
- docker compose --profile tools up -d
87
- ```
145
+ ## Everyday commands
146
+
147
+ | In `server/` | What it does |
148
+ |---|---|
149
+ | `npm run dev` | API with reload on save |
150
+ | `npm test` / `npm run test:coverage` | unit tests (no database); with the coverage floor |
151
+ | `npm run test:integration` | every route against a real MySQL and Redis |
152
+ | `npm run lint` / `npm run typecheck` | ESLint / TypeScript |
153
+ | `npm run build` / `npm start` | production build / run it |
154
+ | `npm run prisma:migrate:dev` | create and apply a migration after a schema change |
155
+ | `npm run prisma:studio` | browse the database |
156
+ | `npm run make-admin -- you@example.com` | promote an existing account to admin |
157
+ | `npm run docker:up` / `docker:tools` / `docker:down` | local MySQL and Redis / plus the admin UIs / stop |
158
+
159
+ | In `client/` | What it does |
160
+ |---|---|
161
+ | `npm run dev` | the app with fast refresh |
162
+ | `npm test` / `npm run test:coverage` | unit tests / with the coverage floor |
163
+ | `npm run lint` / `npm run typecheck` | ESLint / TypeScript |
164
+ | `npm run build` / `npm start` | production build / run it locally (the Docker image runs the standalone `server.js`) |
88
165
 
89
166
  ## Testing and CI
90
167
 
91
168
  ```bash
92
169
  cd my-app/server
93
170
  npm test # unit tests: no database, no Docker
94
- npm run test:coverage # the same, with the coverage ratchet (vitest.config.ts)
171
+ npm run test:coverage # the same, failing below the coverage floor
95
172
  npm run test:integration # every route against a real MySQL + Redis
173
+
174
+ cd ../client
175
+ npm test # the client's logic: session rules, proxy, redirects, error parsing
176
+ npm run test:coverage
96
177
  ```
97
178
 
98
179
  The integration tests start a throwaway MySQL and Redis with Testcontainers (Docker must run). To use services you
99
180
  already run instead, set `INTEGRATION_DATABASE_URL` (a database whose name ends in `_test`) and
100
- `INTEGRATION_REDIS_URL` (a Redis database 1-15): the suite empties both first. Details and how to write new tests:
181
+ `INTEGRATION_REDIS_URL` (a Redis database from 1 to 15): the suite empties both first. Every route has a contract
182
+ test (who may call it, wrong input, success), and that file fails when a new route is never called. Details:
101
183
  `server/docs/testing.md`.
102
184
 
103
- New projects ship with GitHub workflows in `.github/`:
104
- - `ci.yml`, on every push and pull request: typecheck, lint, unit tests with coverage, the server build, the
105
- integration tests (Testcontainers on GitHub's runners) and the client build. It never deploys.
185
+ New projects ship GitHub workflows in `.github/`:
186
+
187
+ - `ci.yml`, on every push and pull request: typecheck, lint, unit tests with coverage and build for both apps, and
188
+ the server's integration tests (Testcontainers on GitHub's runners). It never deploys.
106
189
  - `audit.yml`, weekly: `npm audit` of what production installs, red on a critical advisory. It does not block merges.
107
190
  - `dependabot.yml`: security-update pull requests for npm packages and Actions (turn them on once in the
108
191
  repository's Settings → Advanced Security → Dependabot security updates), and a monthly pull request that
@@ -110,7 +193,8 @@ New projects ship with GitHub workflows in `.github/`:
110
193
 
111
194
  ## Deploying to Coolify
112
195
 
113
- Server and client deploy as two separate Coolify applications, each from its own Dockerfile (`server/Dockerfile`, `client/Dockerfile`).
196
+ Server and client deploy as two separate Coolify applications, each from its own Dockerfile (`server/Dockerfile`,
197
+ `client/Dockerfile`).
114
198
 
115
199
  **Coolify checklist.** One Coolify project with two applications (from the same Git repository), a MySQL and a Redis:
116
200
 
@@ -125,13 +209,18 @@ Server and client deploy as two separate Coolify applications, each from its own
125
209
  | Storage | a volume at `/app/uploads` (below) | none |
126
210
 
127
211
  How the domains map to the variables:
128
- - `NEXT_PUBLIC_API_BASE_URL` (client) = the API domain + `/api/v1`, e.g. `https://api.example.com/api/v1`.
129
- - `CORS_ORIGIN` (server) = the site's origin exactly, e.g. `https://example.com` (no path, no trailing slash).
130
- - `CLIENT_URL` (server) = the site's address, used in the links of emails.
131
- - `COOKIE_DOMAIN` (server) = `.example.com` when site and API are sibling subdomains; unset when they share one host.
132
- - `DATABASE_URL` and `REDIS_URL` (server) = the internal URLs shown on the MySQL and Redis pages in Coolify, with
133
- `?connection_limit=5` on the database URL. A wrong database URL fails the deploy at its migration step, and
134
- production refuses to start when it cannot reach Redis within 10 s.
212
+
213
+ ```text
214
+ NEXT_PUBLIC_API_BASE_URL (client) https://api.example.com/api/v1 the API domain + /api/v1
215
+ CORS_ORIGIN (server) https://example.com the site's origin exactly: no path, no trailing slash
216
+ CLIENT_URL (server) https://example.com used in the links of emails
217
+ COOKIE_DOMAIN (server) .example.com when site and API are sibling subdomains; unset on one host
218
+ DATABASE_URL (server) mysql://…internal…/app?connection_limit=5
219
+ REDIS_URL (server) redis://…internal… the internal URLs from Coolify's MySQL and Redis pages
220
+ ```
221
+
222
+ A wrong database URL fails the deploy at its migration step, and production refuses to start when it cannot reach
223
+ Redis within 10 s. Either way the old container keeps serving.
135
224
 
136
225
  Deploy the server first (it applies the migrations), then the client. Afterwards sign in as an admin and open
137
226
  `/api/v1/admin/health`: every check should be up. Coolify switches traffic to a new container only once its Dockerfile
@@ -140,22 +229,87 @@ container still serves; before one that drops or renames anything, read `server/
140
229
  [template/server/docs/deployment.md](template/server/docs/deployment.md)), which also explains why a build without
141
230
  Docker's cache takes about 6 to 7 minutes longer (it compiles libvips).
142
231
 
143
- **The server needs a persistent volume for uploads.** Avatars (and any other uploaded files) are written to `/app/uploads` inside the container, and every deploy starts a fresh container. Without a volume, all uploaded files are lost on each redeploy. In the server application: **Storages → Add Volume Mount**, leave *Source Path* empty (Coolify manages the volume), *Destination Path* `/app/uploads`. The server warns at boot (`[STORAGE] … is not on a mounted volume`) when it runs in production without one. Details: `server/.env.example.production`, section FILE UPLOAD.
232
+ **The server needs a persistent volume for uploads.** Avatars and other uploaded files are written to `/app/uploads`
233
+ inside the container, and every deploy starts a fresh container, so without a volume they are lost on each redeploy.
234
+ In the server application: **Storages → Add Volume Mount**, leave *Source Path* empty (Coolify manages the volume),
235
+ *Destination Path* `/app/uploads`. The server warns at boot (`[STORAGE] … is not on a mounted volume`) when it runs in
236
+ production without one.
237
+
238
+ **First admin.** Sign up in the app with the account that should be the admin (verify its email if the email module
239
+ is on). Then open the server application's **Terminal** in Coolify and run:
240
+
241
+ ```bash
242
+ node dist/scripts/make-admin.js you@example.com
243
+ ```
244
+
245
+ It only changes that account's role and marks its email verified: no password is asked for or printed. Locally:
246
+ `npm run make-admin -- you@example.com` in `server/`. The same command recovers a project whose last admin was
247
+ demoted or banned by mistake.
144
248
 
145
- **First admin.** Sign up in the app with the account that should be the admin (your own password; verify the email if the email module is on). Then open the server application's **Terminal** in Coolify and run `node dist/scripts/make-admin.js you@example.com`. It only changes that account's role and marks its email verified: no password is asked for or printed. Locally: `cd server && npm run make-admin -- you@example.com`. The same command recovers a project whose last admin was demoted or banned by mistake.
249
+ **Background jobs** run inside the server process, so no extra Coolify service is needed, and with more than one
250
+ server replica each runs them too, which is safe.
146
251
 
147
- **Background jobs** run inside the server process, so no extra Coolify service is needed. Each first runs about a minute after the server starts, then on its own schedule:
148
- - expired sessions and tokens: hourly;
149
- - deleted accounts past their 30 days: daily;
150
- - Cloudflare's IP list: daily.
252
+ ## Adding a module later
151
253
 
152
- A deploy never postpones them. With more than one server replica, each runs them too, which is safe.
254
+ Modules add a feature to an existing project. The creation wizard asks about
255
+ email verification, performance metrics, and error and warning tracking independently:
153
256
 
154
- ## Security and Migration Notes
257
+ ```bash
258
+ cd my-app # the folder that holds server/ and client/
259
+ npx create-tigra add email-verification
260
+ npx create-tigra add metrics
261
+ npx create-tigra add diagnostics
262
+ ```
263
+
264
+ The email verification module adds the routes (`POST /auth/send-verification`, `POST /auth/verify-account`), their integration
265
+ tests, the client's `useVerifyAccount` / `useSendVerification` hooks and service, and sets `REQUIRE_USER_VERIFICATION=true` in `server/.env`.
266
+ Then set `RESEND_API_KEY` in `server/.env` and restart the server. Answering "yes" to the email question when you
267
+ create a project does the same. Run it on projects made with 4.x: it copies tests that use the 4.x test helpers.
268
+
269
+ The metrics module collects request and operation timings, Node runtime
270
+ measurements, and browser Web Vitals into five-minute MySQL buckets. Apply the
271
+ added Prisma migration and regenerate the Prisma client before starting the
272
+ server. The generated `server/docs/performance.md` explains the admin API,
273
+ sampling, and how to extend coverage when adding features.
155
274
 
156
- - [Account deactivation login reactivation: issue, fix, and existing-project migration](docs/account-deactivation-login-reactivation.md)
157
- - [Client IP behind proxies and Cloudflare: how the visitor address is verified, and existing-project porting](docs/client-ip-behind-proxies.md)
158
- - [Rate limits, login lockout, email cap and IP blocks: every limit, ENV overrides, Redis-down behaviour, and existing-project porting](template/server/docs/rate-limits.md)
275
+ The diagnostics module groups unexpected server errors and actionable warnings
276
+ with safe messages and source frames. Apply the additive Prisma migration and
277
+ regenerate the client before starting the server. The generated
278
+ `server/docs/diagnostics.md` gives agents copyable commands for the read-only
279
+ MySQL view and the admin API. Diagnostic history has no automatic expiry.
280
+
281
+ ## Documentation
282
+
283
+ In every generated project:
284
+
285
+ | File | What it explains |
286
+ |---|---|
287
+ | `README.md`, `server/README.md`, `client/README.md` | what is where, how to run it |
288
+ | `server/docs/deployment.md` | what a deploy does, safe migrations (expand, deploy, contract), rollback, build time |
289
+ | `server/docs/rate-limits.md` | every limit, the login lockout, IP blocks, email caps, env overrides, Redis outages |
290
+ | `server/docs/testing.md` | unit and integration tests, writing new ones, CI, coverage |
291
+ | `server/docs/logging.md` | request logs, redaction, health checks |
292
+ | `server/.env.example`, `server/.env.example.production`, `client/.env.example*` | every setting, with notes |
293
+ | `AGENTS.md`, `server/AGENTS.md`, `client/AGENTS.md` | the rules agents (and people) follow when changing the code |
294
+
295
+ In this repository:
296
+
297
+ - [CHANGELOG.md](CHANGELOG.md): what changed in each release.
298
+ - [Client IP behind proxies and Cloudflare](docs/client-ip-behind-proxies.md): how the visitor address is verified,
299
+ and how to port it to an older project.
300
+ - [Account ban vs email verification](docs/account-ban-vs-email-verification.md) and
301
+ [Account deactivation and login](docs/account-deactivation-login-reactivation.md): two account-state fixes, with
302
+ porting steps.
303
+ - [Rate limits](template/server/docs/rate-limits.md), [deployment](template/server/docs/deployment.md),
304
+ [testing](template/server/docs/testing.md) and [logging](template/server/docs/logging.md): the same guides a
305
+ generated project ships.
306
+
307
+ ## Upgrading from 3.x
308
+
309
+ A generated project never updates itself: it is your code from the moment it is created. 4.0 changed most of the
310
+ template (sessions, rate limits, uploads, the admin API, jobs, health checks, tests, the Docker images, the agent
311
+ rules and the client). [CHANGELOG.md](CHANGELOG.md) lists every change by area; the guides in `docs/` show how to port
312
+ the ones that need care. New projects need Node 24 and npm 11.19+ (the 3.3.0 images ran Node 20).
159
313
 
160
314
  ## License
161
315