@cubocicloide/stack-react-fastapi 13.2.0 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubocicloide/stack-react-fastapi",
3
- "version": "13.2.0",
3
+ "version": "13.4.0",
4
4
  "description": "React (Vite) + FastAPI stack plugin for the dude CLI.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "openapi-typescript": "^7.13.0",
21
21
  "pathe": "^1.1.2",
22
22
  "yaml": "^2.6.0",
23
- "@cubocicloide/dude": "0.16.0"
23
+ "@cubocicloide/dude": "0.17.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^26.1.2",
@@ -29,7 +29,7 @@
29
29
  "vitest": "^2.1.9"
30
30
  },
31
31
  "engines": {
32
- "node": ">=20"
32
+ "node": ">=20.19"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsup",
@@ -9,13 +9,20 @@ WORKDIR /app
9
9
 
10
10
  RUN pip install --no-cache-dir uv
11
11
 
12
- COPY pyproject.toml .
12
+ # Run as an unprivileged user (trivy DS002). The user is created *before* the
13
+ # virtualenv is built so every layer is written with the right ownership — a
14
+ # trailing `chown -R /app` would instead duplicate the whole .venv into an
15
+ # extra layer.
16
+ RUN useradd -m -u 1000 appuser && chown appuser:appuser /app
17
+ USER appuser
18
+
19
+ COPY --chown=appuser:appuser pyproject.toml .
13
20
  RUN uv sync --no-cache --no-dev
14
21
 
15
- COPY app ./app
22
+ COPY --chown=appuser:appuser app ./app
16
23
  {{#if withPostgres}}
17
- COPY alembic ./alembic
18
- COPY alembic.ini ./alembic.ini
24
+ COPY --chown=appuser:appuser alembic ./alembic
25
+ COPY --chown=appuser:appuser alembic.ini ./alembic.ini
19
26
  {{/if}}
20
27
 
21
28
  EXPOSE 8000
@@ -94,6 +94,35 @@ dude iac ship --env staging
94
94
  > `dude iac deploy --env staging --tag <sha>` (use the tag from
95
95
  > `dude iac status --env dev`).
96
96
 
97
+ ## Image tags
98
+
99
+ The ECR repositories are **immutable**: a tag is written once and can never be
100
+ overwritten. That is what makes "promote the image from dev to staging" mean
101
+ something — a tag names one exact set of bytes, for as long as it exists.
102
+
103
+ So `dude iac build/push/ship` derive the tag from your git state rather than
104
+ letting you overwrite one:
105
+
106
+ | Working tree | Tag |
107
+ |--------------|-----|
108
+ | clean | `<git-short-sha>` |
109
+ | uncommitted changes | `<git-short-sha>-dirty-<hash-of-the-diff>` |
110
+
111
+ The `-dirty-<hash>` part is why iterating on a branch works: every edit changes
112
+ the digest, so every `dude iac ship` gets a fresh tag. Re-shipping a state you
113
+ have already pushed — same commit, same edits — is the one case that stops, and
114
+ it stops *before* building, with the three options spelled out:
115
+
116
+ ```
117
+ ✗ <repo>:<tag> already exists, and the repository is immutable.
118
+ • commit your work and re-run — a new SHA gives a new tag;
119
+ • push under a different tag: dude iac push --env dev --tag <tag>.1
120
+ • or deploy what is already there: dude iac deploy --env dev --tag <tag>
121
+ ```
122
+
123
+ That last one is usually what you want: the image is already in ECR, so there is
124
+ nothing to rebuild.
125
+
97
126
  ## HTTPS on a custom domain *(optional)*
98
127
 
99
128
  Set these in `iac/terraform/environments/dev/terraform.tfvars` (the Route53
@@ -1,5 +1,5 @@
1
1
  # Production image for the frontend: build the Vite app, serve the static
2
- # bundle with nginx. Used by the Helm deployment (port 80). The dev Dockerfile
2
+ # bundle with nginx. Used by the Helm deployment (port 8080). The dev Dockerfile
3
3
  # (Vite dev server) is kept for `dude up`.
4
4
  #
5
5
  # VITE_* values are baked in at build time — pass them as build args:
@@ -21,8 +21,12 @@ ENV VITE_REACT_QUERY_DEVTOOLS=$VITE_REACT_QUERY_DEVTOOLS
21
21
  COPY . .
22
22
  RUN pnpm build
23
23
 
24
- FROM nginx:1.27-alpine
24
+ # nginx-unprivileged is the stock nginx image rebuilt to run as UID 101 with no
25
+ # root master process (trivy DS002). Because it cannot bind a privileged port,
26
+ # it listens on 8080 — see nginx.conf and `frontend.port` in the Helm values.
27
+ FROM nginxinc/nginx-unprivileged:1.27-alpine
25
28
  COPY --from=build /app/dist /usr/share/nginx/html
26
29
  COPY nginx.conf /etc/nginx/conf.d/default.conf
27
- EXPOSE 80
30
+ USER nginx
31
+ EXPOSE 8080
28
32
  CMD ["nginx", "-g", "daemon off;"]
@@ -2,7 +2,8 @@
2
2
  # (path-based), so nginx only needs to serve the static bundle and fall back to
3
3
  # index.html for client-side routes.
4
4
  server {
5
- listen 80;
5
+ # 8080, not 80: the image runs unprivileged and cannot bind a port < 1024.
6
+ listen 8080;
6
7
  server_name _;
7
8
  root /usr/share/nginx/html;
8
9
  index index.html;
@@ -34,8 +34,9 @@ backend:
34
34
 
35
35
  frontend:
36
36
  replicas: 2
37
- ## nginx serving the production build (see frontend/Dockerfile.prod)
38
- port: 80
37
+ ## nginx serving the production build (see frontend/Dockerfile.prod). 8080
38
+ ## because that image runs unprivileged and cannot bind a port below 1024.
39
+ port: 8080
39
40
  resources:
40
41
  requests:
41
42
  cpu: 50m
@@ -49,12 +49,32 @@ resource "aws_s3_bucket_versioning" "state" {
49
49
  }
50
50
  }
51
51
 
52
+ # Terraform state records every attribute of every resource — including the
53
+ # generated RDS password — so it gets a customer managed key rather than the
54
+ # AWS-owned S3 key (AVD-AWS-0132). The practical difference is control: rotation
55
+ # you can schedule, a key policy you can audit, and the ability to revoke access
56
+ # to the state without touching the bucket.
57
+ resource "aws_kms_key" "state" {
58
+ description = "${var.project_name} — Terraform state encryption"
59
+ enable_key_rotation = true
60
+ deletion_window_in_days = 7
61
+ }
62
+
63
+ resource "aws_kms_alias" "state" {
64
+ name = "alias/${var.project_name}-tfstate"
65
+ target_key_id = aws_kms_key.state.key_id
66
+ }
67
+
52
68
  resource "aws_s3_bucket_server_side_encryption_configuration" "state" {
53
69
  bucket = aws_s3_bucket.state.id
54
70
  rule {
55
71
  apply_server_side_encryption_by_default {
56
- sse_algorithm = "AES256"
72
+ sse_algorithm = "aws:kms"
73
+ kms_master_key_id = aws_kms_key.state.arn
57
74
  }
75
+ # One data key per bucket rather than one per object: same protection, and
76
+ # it keeps the (billed) KMS request count flat as the state grows.
77
+ bucket_key_enabled = true
58
78
  }
59
79
  }
60
80
 
@@ -82,7 +102,7 @@ resource "aws_dynamodb_table" "lock" {
82
102
  # only here, with the rest of the shared backend.
83
103
  resource "aws_ecr_repository" "backend" {
84
104
  name = "${var.project_name}-backend"
85
- image_tag_mutability = "MUTABLE"
105
+ image_tag_mutability = "IMMUTABLE"
86
106
  force_delete = true
87
107
 
88
108
  image_scanning_configuration {
@@ -92,7 +112,7 @@ resource "aws_ecr_repository" "backend" {
92
112
 
93
113
  resource "aws_ecr_repository" "frontend" {
94
114
  name = "${var.project_name}-frontend"
95
- image_tag_mutability = "MUTABLE"
115
+ image_tag_mutability = "IMMUTABLE"
96
116
  force_delete = true
97
117
 
98
118
  image_scanning_configuration {
@@ -56,6 +56,13 @@ module "eks" {
56
56
  min_size = var.node_min_size
57
57
  max_size = var.node_max_size
58
58
  desired_size = var.node_desired_size
59
+
60
+ # IMDSv2 is not configured here on purpose: the module already defaults
61
+ # `metadata_options` to { http_endpoint = "enabled", http_tokens =
62
+ # "required", http_put_response_hop_limit = 2 }. That variable is
63
+ # replaced wholesale rather than merged, so overriding it with just
64
+ # `http_tokens` would silently drop the hop limit to the AWS default of
65
+ # 1 and cut pods off from the instance metadata endpoint.
59
66
  }
60
67
  }
61
68
  }
@@ -255,11 +262,13 @@ resource "aws_security_group" "rds" {
255
262
  cidr_blocks = [var.vpc_cidr]
256
263
  }
257
264
 
265
+ # Restrict egress to VPC only (security best practice)
258
266
  egress {
267
+ description = "Allow outbound to VPC for responses"
259
268
  from_port = 0
260
269
  to_port = 0
261
270
  protocol = "-1"
262
- cidr_blocks = ["0.0.0.0/0"]
271
+ cidr_blocks = [var.vpc_cidr]
263
272
  }
264
273
 
265
274
  lifecycle {
@@ -138,16 +138,16 @@ Run on the consolidated branch (or the single agent branch):
138
138
  dude lint
139
139
  ```
140
140
 
141
- If the project has a test command (check `Makefile`, `package.json` scripts, or
142
- `dude help`), run it next:
141
+ Run the project's own test suite next:
143
142
 
144
143
  ```bash
145
- dude test # if available
146
- # or:
147
- cd backend && python -m pytest
148
- cd frontend && pnpm test
144
+ dude test
149
145
  ```
150
146
 
147
+ `dude help test` lists the suites this project actually exposes (`--backend`,
148
+ `--e2e`, …) — they differ per stack. If the change is scoped to one suite, run
149
+ that one rather than the lot.
150
+
151
151
  If any step fails, report the output and stop — do **not** create a PR.
152
152
 
153
153
  ---
@@ -0,0 +1,34 @@
1
+ # PRJ001 — Example project rule
2
+
3
+ This file is the prose half of the example project check
4
+ (`.dude/lint/checks/PRJ/001.ts`). Rename, edit or delete both together.
5
+
6
+ ## What it does
7
+
8
+ Nothing yet — the shipped check returns no diagnostics. It exists so you have a
9
+ working pair to copy: a rule module, and the Markdown that explains it.
10
+
11
+ ## Why the file is here
12
+
13
+ `dude explain PRJ001` prints **this file**, and `dude cheatsheet` uses its first
14
+ heading as the rule's one-line title. A project rule with no Markdown beside it
15
+ still runs, but it can only ever be listed as a bare code — which tells whoever
16
+ hits the diagnostic (a teammate, or a coding agent) nothing about how to fix it.
17
+
18
+ The convention is a sibling file, matching the check's path:
19
+
20
+ ```
21
+ .dude/lint/checks/PRJ/001.ts ← the rule
22
+ .dude/lint/checks/PRJ/001.md ← this file
23
+ ```
24
+
25
+ `dude lint` ignores non-module files, so the Markdown never runs as a check.
26
+
27
+ > Stack rules follow the mirror-image convention — their prose lives under
28
+ > `.claude/rules/<GROUP>/<NNN>.md`. Both are served by `dude explain <CODE>`.
29
+
30
+ ## How to fix a violation
31
+
32
+ Describe the fix here, concretely enough that someone can act on it without
33
+ opening the check's source. Start the file with `# <CODE> — <title>` so the
34
+ title is picked up.
@@ -38,9 +38,26 @@ export default function check(root: string): RawDiagnostic[] {
38
38
  Checks are loaded with [jiti](https://github.com/unjs/jiti), so you can write
39
39
  real TypeScript and `import` any package you add to the project.
40
40
 
41
- You can document a rule with a Markdown file next to it
42
- (`PRJ/001.md`) — `dude lint` ignores non-module files. Co-located tests
43
- (`001.test.ts`) are ignored too.
41
+ ## Documenting a rule
42
+
43
+ Put a Markdown file next to the check, named after it:
44
+
45
+ ```
46
+ .dude/lint/checks/PRJ/001.ts ← the rule
47
+ .dude/lint/checks/PRJ/001.md ← what it means and how to fix it
48
+ ```
49
+
50
+ `dude explain PRJ001` prints that file, and `dude cheatsheet` uses its first
51
+ heading (`# PRJ001 — <title>`) as the rule's one-line title. Without it the rule
52
+ still runs, but it can only be reported as a bare code — which tells whoever hits
53
+ the diagnostic nothing about how to fix it. The shipped `PRJ/001.md` is a worked
54
+ example.
55
+
56
+ `dude lint` ignores non-module files, so the Markdown never runs as a check.
57
+ Co-located tests (`001.test.ts`) are ignored too.
58
+
59
+ > Stack rules use the mirror-image location, `.claude/rules/<GROUP>/<NNN>.md`.
60
+ > `dude explain <CODE>` serves both.
44
61
 
45
62
  ## Choosing codes
46
63
 
@@ -97,6 +97,7 @@ defines every service.
97
97
  | Command | Description |
98
98
  |---------|-------------|
99
99
  | `dude lint` | Run all structural lint checks (naming, layout conventions) |
100
+ | `dude explain <CODE>` | Print the prose behind a lint code — why the rule exists and how to fix it |
100
101
  | `dude format` | Format code — `ruff` (backend) + `prettier` (frontend) |
101
102
  | `dude upgrade` | Update the pinned `dude` CLI and stack versions for this project |
102
103
  | `dude review` | Run lint + ESLint + API contract review in one pass |
@@ -106,13 +107,29 @@ defines every service.
106
107
  `dude lint` also runs any rules you define under `.dude/lint/checks/` — the
107
108
  rule code is derived from the path (`.dude/lint/checks/PRJ/001.ts` → `PRJ001`)
108
109
  and the contract is the same one the stack's own checks use. See
109
- `.dude/lint/checks/README.md` and the `PRJ/001.ts` example. To disable a
110
- built-in rule, list its code in `dude.json`:
110
+ `.dude/lint/checks/README.md` and the `PRJ/001.ts` example. Document a rule with
111
+ a Markdown file next to it (`PRJ/001.md`) and `dude explain PRJ001` serves it.
112
+ To disable a built-in rule, list its code in `dude.json`:
111
113
 
112
114
  ```json
113
115
  { "lint": { "disable": ["BE003"] } }
114
116
  ```
115
117
 
118
+ ### Verifying your work mechanically
119
+
120
+ `dude lint` and `dude explain` are designed to be used together — the fastest
121
+ loop for anyone, human or coding agent, working in this project:
122
+
123
+ ```bash
124
+ dude lint --format json # what broke, where, and under which rule code
125
+ dude explain BE003 # why that rule exists and how to satisfy it
126
+ ```
127
+
128
+ `--format json` writes nothing but the JSON document to stdout, so it pipes
129
+ cleanly (`dude lint --format json | jq '.diagnostics[].code'`). Exit codes are
130
+ the same as the human format: non-zero only when there is at least one error.
131
+ Run `dude explain` with no code to list every rule that applies here.
132
+
116
133
  ### Upgrading pinned versions
117
134
 
118
135
  `dude upgrade` updates version pins only. It does **not** migrate existing
@@ -237,6 +254,25 @@ git add security/baseline.json && git commit -m "chore(security): update baselin
237
254
  `security/baseline.json` must be committed — it is the source of truth for
238
255
  accepted findings. Subsequent scans only flag findings that are **not** in the
239
256
  baseline.
257
+
258
+ **Baseline or ignore file?** Two mechanisms, deliberately different:
259
+
260
+ | | Use for | Behaviour |
261
+ |-|---------|-----------|
262
+ | `security/baseline.json` | findings you have triaged and mean to address | fingerprinted; a finding reappears as *new* if its location changes, and `dude security verify` prunes it once fixed |
263
+ | `security/.trivyignore.yaml` | findings that are correct **by design** and will never be fixed | matched by rule id + path; permanently silent, with a `statement:` recording why |
264
+
265
+ The scaffold ships one ignore entry: **DS002** (container runs as root) on
266
+ `backend/Dockerfile` and `frontend/Dockerfile`. Those are the development images
267
+ that `dude up` builds — they never leave your machine, they bind-mount your
268
+ source tree, and pinning them to a non-root UID breaks writes back into it (the
269
+ alembic revision `dude db makemigration` generates, for instance) on any host
270
+ whose UID is not 1000. The images that actually ship — `Dockerfile.prod` for
271
+ both backend and frontend — do run unprivileged.
272
+
273
+ Trivy is also pointed away from `.terraform/`: once `dude iac init` has run,
274
+ that directory holds the vendored source of every third-party Terraform module,
275
+ and its misconfigurations are not yours to fix.
240
276
  {{#if withIac}}
241
277
 
242
278
  ---
@@ -90,10 +90,10 @@ export default function HomePage() {
90
90
  <Col xs={24} md={8}>
91
91
  <Card title={<><CodeOutlined /> Quick links</>} style={{ height: '100%' }}>
92
92
  <Space wrap size="middle">
93
- <Link href="/api/docs" target="_blank">
93
+ <Link href="http://localhost:8000/api/docs" target="_blank">
94
94
  API docs (Swagger)
95
95
  </Link>
96
- <Link href="/api/redoc" target="_blank">
96
+ <Link href="http://localhost:8000/api/redoc" target="_blank">
97
97
  ReDoc
98
98
  </Link>
99
99
  <Link href="http://localhost:8001" target="_blank">
@@ -0,0 +1,49 @@
1
+ # Trivy ignore file — accepted findings, with the reason recorded next to each.
2
+ #
3
+ # This is for findings that are *by design* and will never be "fixed", so they
4
+ # would otherwise reappear on every scan. Findings you have merely triaged and
5
+ # intend to address belong in the baseline instead:
6
+ #
7
+ # dude security accept # absorb current findings
8
+ # dude security verify --rule-id <id> # confirm a fix, prune from the baseline
9
+ #
10
+ # Wired in by `dude security scan` via --ignorefile; delete this file and every
11
+ # entry below becomes a live finding again.
12
+
13
+ vulnerabilities:
14
+ - id: GHSA-qwww-vcr4-c8h2
15
+ paths:
16
+ - frontend/package-lock.json
17
+ - frontend/pnpm-lock.yaml
18
+ # Revisit rather than forget: after this date trivy reports it again.
19
+ expired_at: 2027-02-01
20
+ statement: >
21
+ Not reachable in this application. The advisory is a CSRF bypass in React
22
+ Router's RSC (React Server Components) mode; this frontend is a Vite SPA
23
+ doing client-side routing with react-router-dom, and never runs RSC. The
24
+ only published fix is react-router 8.3.0 — a major version with breaking
25
+ routing changes — so upgrading is a deliberate migration, not a patch.
26
+ Re-check when moving to react-router 8 for any other reason.
27
+
28
+ misconfigurations:
29
+ - id: DS002
30
+ paths:
31
+ - backend/Dockerfile
32
+ - frontend/Dockerfile
33
+ statement: >
34
+ Development images only. They are built by `dude up` and never leave the
35
+ developer's machine — Kubernetes runs backend/Dockerfile.prod and
36
+ frontend/Dockerfile.prod, both of which do run as an unprivileged user.
37
+ Forcing a non-root UID here breaks writes to the bind-mounted source tree
38
+ (`dude db makemigration` writing alembic/versions/, for one) on any host
39
+ whose UID is not 1000.
40
+
41
+ - id: DS002
42
+ paths:
43
+ - iac/runner/Dockerfile
44
+ statement: >
45
+ Local tooling container, not a workload. `dude iac *` runs terraform,
46
+ kubectl, helm and k9s inside it with your own ~/.aws and ~/.kube mounted
47
+ in; it is started on demand, never deployed, and never exposed. Running
48
+ as root is what lets those tools write to the mounted credential caches
49
+ whatever your host UID happens to be.