Skip to content

Commit 27194a4

Browse files
docs: fixed documentation
1 parent 327d9c4 commit 27194a4

42 files changed

Lines changed: 2383 additions & 1371 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ Must follow Conventional Commits:
443443
- Auth is RS256-only. JWT `sub` claim is the ctech user ID. There is no `SECRET_KEY` — do not add HS256.
444444
- JWKS keys are cached in Redis/Valkey (TTL 1h). Falls back to in-memory when `VALKEY_URL` is unset.
445445
- NF-e numbering uses `transact_write` for atomicity — never replace with separate read/write.
446-
- Organization context is passed via `PyDfe-Organization-Pk` header — never path parameters.
446+
- Organization context is passed via `Dfe-Organization-Pk` header — never path parameters.
447447
- All route errors go through `sendProblem(c, err)` — never return raw errors or `fiber.NewError`.
448448
- Services return `*problem.Problem` via `problem.BadRequest/NotFound/InternalServer` helpers.
449449
- **Every mutating endpoint binds a typed request DTO and validates it before persistence.**

DOCS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ ctech-dfe-api/
336336
│ ├── problem/ # RFC 7807 Problem type + helpers
337337
│ ├── middleware/
338338
│ │ ├── auth.go # RS256 JWT validation, JWKS cached in Redis
339-
│ │ ├── tenant.go # PyDfe-Organization-Pk header → org context
339+
│ │ ├── tenant.go # Dfe-Organization-Pk header → org context
340340
│ │ └── perm.go # RBAC permission checker (OWNER/ADMIN bypass)
341341
│ ├── cache/ # Redis + in-memory backends
342342
│ ├── ws/ # WebSocket registry (Redis pub/sub)
@@ -507,7 +507,7 @@ response / link; DynamoDB stores only its SHA-256.
507507
508508
#### Products
509509
510-
Use the `PyDfe-Organization-Pk` header for org context.
510+
Use the `Dfe-Organization-Pk` header for org context.
511511
512512
| Method | Endpoint | Description |
513513
|--------|-----------------------|--------------------------------|
@@ -665,7 +665,7 @@ When `emit_uf='RJ'` and `cst='40'` without a configured `icms_mot_des`, the syst
665665

666666
#### Vehicles
667667

668-
Organization is always resolved from the `PyDfe-Organization-Pk` header, not a path parameter.
668+
Organization is always resolved from the `Dfe-Organization-Pk` header, not a path parameter.
669669
Only `plate`/`plate_uf`/`role` are required to create a vehicle — every other field is optional
670670
and is gated per doc-type/role at emission time via the requirements endpoint below. Trailers
671671
are ordinary vehicle rows with `role=trailer`, independently selectable — not nested under a
@@ -1093,7 +1093,7 @@ app/
10931093
### ApiClient (`lib/api/client.ts`)
10941094

10951095
Type-safe Axios wrapper. Holds `access_token` in module-level memory (never localStorage). Injects
1096-
`Authorization: Bearer {token}` and `PyDfe-Organization-Pk` headers on every request. On 401, calls the registered
1096+
`Authorization: Bearer {token}` and `Dfe-Organization-Pk` headers on every request. On 401, calls the registered
10971097
`_refreshFn` to silently refresh via ctech-account before retrying once. The request interceptor also strips null
10981098
fields from POST (create) payloads (`stripNulls`/`isStrippableBody`) — see "DynamoDB storage policy — null omission".
10991099

MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ SQS Event → Lambda handler
134134

135135
- `transact_write` for NF-e numbering
136136
- DynamoDB PK format: `CNPJ_...` / `CPF_...`
137-
- `PyDfe-Organization-Pk` header name
137+
- `Dfe-Organization-Pk` header name
138138
- RS256 JWKS validation via `CTECH_JWKS_URL`
139139
- WebSocket: Redis pub/sub keyed by `org_pk`
140140

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ comunicação direta à SEFAZ.
1717

1818
## Subprojetos
1919

20+
| Diretório | Papel | README |
21+
|-----------|-------|--------|
22+
| `py-dfe/` | Biblioteca Python core — Lambda + SEFAZ SOAP (mTLS) | [py-dfe/README.md](py-dfe/README.md) |
23+
| `go-dfe/` | Cliente Go SEFAZ (mTLS, in-process) | [go-dfe/README.md](go-dfe/README.md) |
24+
| `api/` | Backend REST — Go (Fiber v3), multi-tenant | [api/README.md](api/README.md) |
25+
| `ui/` | Frontend SaaS — Next.js + TypeScript + ShadCN | [ui/README.md](ui/README.md) |
26+
| `worker/` | Workers assíncronos — Go Lambda (SQS consumers) | [worker/README.md](worker/README.md) |
27+
| `cdk/` | Infraestrutura AWS — CDK TypeScript | [cdk/README.md](cdk/README.md) |
28+
2029
```
2130
py-dfe/ # Biblioteca Python core — Lambda + SEFAZ SOAP (mTLS)
31+
go-dfe/ # Cliente Go SEFAZ (mTLS, in-process) — primário; py-dfe é fallback
2232
api/ # Backend REST — Go (Fiber v3), multi-tenant
2333
ui/ # Frontend SaaS — Next.js + TypeScript + ShadCN
2434
worker/ # Workers assíncronos — Go Lambda (SQS consumers)

api/AGENTS.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ api/
5959

6060
- All string keys, status codes, table name suffixes, header names, cache key prefixes, and env
6161
strings MUST be defined as named constants or config fields.
62-
- The `PyDfe-Organization-Pk` header name is defined once in `middleware/tenant.go` — never
63-
hardcoded in route files.
62+
- The `Dfe-Organization-Pk` header name is defined once as `OrgHeader` in
63+
`middleware/rbac.go:22` — never hardcoded in route files. It MUST stay in sync with the UI
64+
constant `ORG_HEADER` in `ui/src/lib/api/client.ts:50`.
65+
- **Never call the deprecated `GET /v1.0/distributions/nfe`** — it does not exist; use
66+
`GET /v1.0/distributions/{doc_type}/history` (`internal/api/v1/distributions.go:18-29`).
67+
- Endpoint reference: [`README.md`](README.md).
6468

6569
### Error Handling (MUST follow)
6670

@@ -132,7 +136,7 @@ Run: `go test ./... -race` from `api/`.
132136
- `InMemoryCache` TTL=300s — not shared across replicas. Redis/Valkey is authoritative for JWKS and WebSocket pub/sub.
133137
- Lambda invocation for doc issuance is async: API enqueues to SQS FIFO, returns 202, worker processes and pushes
134138
WebSocket update.
135-
- Organization context is always via `PyDfe-Organization-Pk` header — never path parameters (except org creation
139+
- Organization context is always via `Dfe-Organization-Pk` header — never path parameters (except org creation
136140
endpoints).
137141
- Profile/password management endpoints do not exist here — those belong to ctech-account.
138142
- JWKS keys cached in Redis (TTL 1h), falls back to in-memory when `VALKEY_URL` is unset.

api/CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ Run: `go test ./... -race` from `api/`.
146146
`azp` (client identity).
147147
- KID rotation in ctech-account flushes JWKS cache — Redis TTL is 1h; force-flush by restarting or clearing the
148148
`ctech:jwks` key.
149+
- `CORS_ALLOWED_ORIGINS` is configured in env but the CORS middleware is NOT wired in `app.go` (browser is
150+
same-origin, so no production impact today). Treat CORS as inactive until the middleware is added.
149151

150152
---
151153

0 commit comments

Comments
 (0)