@mrciphersmith/keryx 0.4.29 → 0.4.30

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 (123) hide show
  1. package/dist/cli.js +2408 -1369
  2. package/dist/core.js +90 -27
  3. package/dist/keryx-general-worker-entry.js +82 -25
  4. package/package.json +1 -1
  5. package/src/gdskills/bundled/install-manifest.json +2 -0
  6. package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
  7. package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
  8. package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
  9. package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
  10. package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
  11. package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
  12. package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
  13. package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
  14. package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
  15. package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
  16. package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
  17. package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
  18. package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
  19. package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
  20. package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
  21. package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
  22. package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
  23. package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
  24. package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
  25. package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
  26. package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
  27. package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
  28. package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
  29. package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
  30. package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
  31. package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
  32. package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
  33. package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
  34. package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
  35. package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
  36. package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
  37. package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
  38. package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
  39. package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
  40. package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
  41. package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
  42. package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
  43. package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
  44. package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
  45. package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
  46. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
  47. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
  48. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
  49. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
  50. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
  51. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
  52. package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
  53. package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
  54. package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
  55. package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
  56. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
  57. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
  58. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
  59. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
  60. package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
  61. package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
  62. package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
  63. package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
  64. package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
  65. package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
  66. package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
  67. package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
  68. package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
  69. package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
  70. package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
  71. package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
  72. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
  73. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
  74. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
  75. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
  76. package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
  77. package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
  78. package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
  79. package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
  80. package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
  81. package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
  82. package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
  83. package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
  84. package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
  85. package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
  86. package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
  87. package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
  88. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
  89. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
  90. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
  91. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
  92. package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
  93. package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
  94. package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
  95. package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
  96. package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
  97. package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
  98. package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
  99. package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
  100. package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
  101. package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
  102. package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
  103. package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
  104. package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
  105. package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
  106. package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
  107. package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
  108. package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
  109. package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
  110. package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
  111. package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
  112. package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
  113. package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
  114. package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
  115. package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
  116. package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
  117. package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
  118. package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
  119. package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
  120. package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
  121. package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
  122. package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
  123. package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
@@ -7,62 +7,28 @@ metadata:
7
7
 
8
8
  # FastAPI coding style
9
9
 
10
- Narrows `python`'s coding style to FastAPI's own project conventions. A
11
- FastAPI project is still a Python project — everything not specific to
12
- FastAPI's own idiom still comes from `python`'s `rules/coding-style.mdc`,
13
- which this file extends.
10
+ Narrows `python`'s coding style to FastAPI conventions; everything not FastAPI-specific comes from `python`'s `rules/coding-style.mdc`.
14
11
 
15
12
  ## Path operations
16
13
 
17
- - Name path operation functions for the action they perform
18
- (`read_item`, `create_user`), not for the HTTP method alone — the
19
- decorator (`@app.get(...)`, `@app.post(...)`) already states the method.
20
- - Group related path operations behind an `APIRouter` per resource/domain
21
- (`routers/items.py` exposing `router = APIRouter(prefix="/items",
22
- tags=["items"])`) rather than registering every route directly on a single
23
- `app` instance once the project has more than a handful of endpoints.
24
- - Declare an explicit `response_model` (or a return type annotation FastAPI
25
- can use as one) on every path operation that returns a Pydantic model or
26
- ORM object — this is what filters the response to the declared fields and
27
- keeps an internal-only field (a password hash, an audit flag) from
28
- leaking into the API response.
29
- - Use `Annotated[<type>, Depends(...)]`/`Annotated[<type>, Query(...)]` etc.
30
- for parameter declarations (the current recommended style) rather than
31
- the bare `= Depends(...)`/`= Query(...)` default-value form, unless the
32
- project's own code still uses the older form consistently.
14
+ - Name path operation functions for the action (`read_item`, `create_user`), not the HTTP method.
15
+ - Group routes behind an `APIRouter` per resource (`router = APIRouter(prefix="/items", tags=["items"])`) once the project has more than a handful of endpoints.
16
+ - Declare an explicit `response_model` (or a return type annotation FastAPI can use as one) on every path operation that returns a Pydantic model or ORM object.
17
+ - Declare parameters with `Annotated[<type>, Depends(...)]`/`Annotated[<type>, Query(...)]`, not the bare `= Depends(...)` default form, unless the project consistently uses the older form.
33
18
 
34
19
  ## Pydantic models
35
20
 
36
- - Define request/response schemas as Pydantic `BaseModel` subclasses, not
37
- as bare `dict`/`Any` parameters — see `rules/patterns.mdc` for why this is
38
- also the project's injection defense, not just a style preference.
39
- - Keep a model's field constraints on the field itself (`Field(gt=0,
40
- le=100)`, `Literal[...]` for a closed set of values) instead of
41
- re-validating the same constraint by hand in the path operation body.
42
- - Separate the model used for input (what a client may send) from the model
43
- used for output (what the API returns) when they differ by even one field
44
- — do not reuse a single model for both and rely on route logic to strip
45
- the extra field before responding.
46
- - Configure a model with `model_config = ConfigDict(...)` (Pydantic v2), not
47
- the v1 inner `class Config:` — the project's Pydantic version is declared
48
- in `pyproject.toml`; confirm it before assuming v2-only syntax.
21
+ - Define request/response schemas as Pydantic `BaseModel` subclasses, not bare `dict`/`Any` parameters (see `rules/patterns.mdc`).
22
+ - Keep field constraints on the field (`Field(gt=0, le=100)`, `Literal[...]`), not re-validated in the path operation body.
23
+ - Use separate input and output models when they differ by even one field.
24
+ - Configure with `model_config = ConfigDict(...)` (Pydantic v2), not the v1 `class Config:`; confirm the version in `pyproject.toml` first.
49
25
 
50
26
  ## Dependencies
51
27
 
52
- - Keep a dependency function small and single-purpose (fetch the current
53
- user, open a DB session, parse a header) — a dependency that both
54
- authenticates and performs business logic should split so the auth part
55
- is reusable on its own.
56
- - Prefer a `yield`-based dependency (`def get_db(): ... yield session ...
57
- finally: session.close()`) for anything that needs teardown, over a
58
- plain-return dependency plus a manual close call in the path operation.
28
+ - Keep a dependency small and single-purpose; split one that both authenticates and performs business logic.
29
+ - Prefer a `yield`-based dependency for anything needing teardown over a plain-return dependency plus a manual close.
59
30
 
60
31
  ## Project layout
61
32
 
62
- - Match the project's existing layout — a `src/<package>/`
63
- `routers/`, `models/`/`schemas/`, `dependencies.py`, `main.py` split for a
64
- multi-router app, or a single `main.py` for a small service — rather than
65
- introducing a different structure alongside it.
66
- - Keep the FastAPI `app = FastAPI(...)` instantiation and top-level
67
- middleware/router registration in one place (typically `main.py`); do not
68
- scatter `app.include_router(...)` calls across unrelated modules.
33
+ - Match the project's existing layout (`src/<package>/` with `routers/`, `models/`/`schemas/`, `dependencies.py`, `main.py`, or a single `main.py` for a small service); do not introduce a second structure.
34
+ - Keep `app = FastAPI(...)` and top-level middleware/router registration in one place (typically `main.py`).
@@ -7,102 +7,39 @@ metadata:
7
7
 
8
8
  # FastAPI patterns
9
9
 
10
- Narrows `python`'s stack-agnostic design guidance (and its own
11
- `asyncio`/resource patterns) to FastAPI's own request lifecycle: dependency
12
- injection, async vs. sync path operations, response modeling, and
13
- background work. Applies only to FastAPI project files.
10
+ Narrows `python`'s design guidance to FastAPI's request lifecycle: dependency injection, async vs. sync path operations, response modeling and background work. Applies only to FastAPI project files.
14
11
 
15
12
  ## Async vs. sync path operations
16
13
 
17
- - Declare a path operation `async def` only when its body actually awaits
18
- something async (an async DB driver, `httpx.AsyncClient`, another
19
- awaitable). An `async def` path operation runs directly on the event
20
- loop, so a blocking call inside it (a sync DB driver, `requests.get`,
21
- `time.sleep`, blocking file I/O, a CPU-bound loop) stalls every other
22
- in-flight request on that worker.
23
- - Declare a path operation with plain `def` when its body calls a blocking
24
- library with no async equivalent. FastAPI runs a `def` path operation in
25
- an external threadpool automatically — this is current, documented
26
- behavior, not a workaround — so a blocking call inside it does not block
27
- the event loop.
28
- - The same rule applies to dependencies: a `def` dependency runs in the
29
- threadpool, an `async def` dependency runs on the loop and must not
30
- block. FastAPI accepts either kind of dependency under either kind of
31
- path operation (an `async def` dependency under a `def` path operation
32
- and vice versa), so choose per-dependency based on what its own body
33
- does, not to match the path operation's own declaration.
34
- - For a compute-only path operation with no I/O at all, prefer `async def`
35
- — it avoids the threadpool's scheduling overhead for work that was never
36
- going to block anything.
14
+ - Declare a path operation `async def` only when its body awaits something async; never call a blocking function (sync DB driver, `requests.get`, `time.sleep`, blocking file I/O, a CPU-bound loop) inside it.
15
+ - Declare a path operation with plain `def` when its body calls a blocking library with no async equivalent; FastAPI runs it in a threadpool.
16
+ - The same applies to dependencies: a `def` dependency runs in the threadpool, an `async def` one on the loop and must not block. Choose per dependency by its own body, not to match the path operation.
17
+ - Prefer `async def` for a compute-only path operation with no I/O.
37
18
 
38
19
  ## Dependency injection
39
20
 
40
- - Use `Depends(...)` (or `Security(...)` for an auth dependency that also
41
- carries OAuth2 scopes) to inject anything a path operation needs but
42
- should not construct itself: a DB session, the current authenticated
43
- user, pagination parameters, a feature flag. This is what makes each
44
- piece independently testable via FastAPI's `app.dependency_overrides`.
45
- - Chain dependencies (a dependency that itself depends on another) instead
46
- of duplicating the same setup logic across sibling dependencies — FastAPI
47
- caches a dependency's result per request by default, so a shared
48
- sub-dependency runs once even when several path-level dependencies need
49
- it.
50
- - Use `yield` in a dependency that owns a resource needing teardown (a DB
51
- session, a lock, an open connection); the code after `yield` runs after
52
- the response is sent, even when the path operation raised — this is
53
- FastAPI's own resource-lifecycle pattern for a request-scoped resource,
54
- not a manual `try`/`finally` bolted onto a plain-return dependency.
21
+ - Use `Depends(...)` (or `Security(...)` for an auth dependency carrying OAuth2 scopes) to inject a DB session, the current user, pagination parameters or a feature flag; test with `app.dependency_overrides`.
22
+ - Chain dependencies instead of duplicating setup logic.
23
+ - Use `yield` in a dependency that owns a resource needing teardown (DB session, lock, connection).
55
24
 
56
25
  ## Request/response modeling
57
26
 
58
- - Model every request body as a Pydantic `BaseModel`, never as a raw
59
- `dict`/`Any` parameter — FastAPI validates the incoming JSON against the
60
- model before the path operation body runs, which is the framework's own
61
- first line of defense against malformed or malicious input (see
62
- `rules/security.mdc`).
63
- - Use `field_validator`/`model_validator` (Pydantic v2) for a constraint
64
- that spans multiple fields or needs custom logic beyond `Field(...)`'s
65
- declarative constraints (`gt`, `max_length`, `pattern`), not a manual
66
- `if`-check inside the path operation body after the model has already
67
- validated.
68
- - Declare `response_model` (or a return-type annotation FastAPI can infer
69
- one from) so the response is filtered to the declared fields even when
70
- the object returned from the path operation carries more — this is a
71
- correctness property, not just documentation: it is what keeps an
72
- internal-only field out of the response body.
27
+ - Model every request body as a Pydantic `BaseModel`, never a raw `dict`/`Any` (see `rules/security.mdc`).
28
+ - Use `field_validator`/`model_validator` (Pydantic v2) for multi-field or custom constraints beyond `Field(...)`, not an `if`-check in the path operation body.
29
+ - Declare `response_model` (or a return-type annotation FastAPI can infer one from) to filter the response to the declared fields.
73
30
 
74
31
  ## Background work
75
32
 
76
- - Use `BackgroundTasks` (injected the same way as any other dependency)
77
- for work that must run after the response is sent but is short, best-
78
- effort, and does not need retries, a result, or cross-process durability
79
- (writing a log line, sending a best-effort notification).
80
- - Reach for a real task queue (Celery, arq, a message broker) instead of
81
- `BackgroundTasks` once the work needs retries, visibility into failure,
82
- distribution across multiple worker processes, or survival past the
83
- serving process' lifetime — `BackgroundTasks` runs in-process and is lost
84
- if the process restarts before it completes.
33
+ - Use `BackgroundTasks` only for short, best-effort work needing no retries, result or cross-process durability (a log line, a best-effort notification).
34
+ - Use a real task queue (Celery, arq, a message broker) once the work needs retries, failure visibility, multi-process distribution or survival past a restart.
85
35
 
86
36
  ## OpenAPI and schema
87
37
 
88
- - Let FastAPI generate the OpenAPI schema from type hints, `response_model`,
89
- and `Field(...)` constraints rather than hand-maintaining a separate
90
- OpenAPI YAML/JSON file alongside the code — the generated schema is what
91
- keeps documentation and implementation from drifting apart.
92
- - Use `tags=[...]` on each `APIRouter`/path operation and a `summary`/
93
- `description` (or a docstring, which FastAPI uses as the description)
94
- for anything beyond an obvious CRUD endpoint, so the generated docs stay
95
- usable as the API grows.
38
+ - Let FastAPI generate the OpenAPI schema from type hints, `response_model` and `Field(...)`; do not hand-maintain a separate OpenAPI file.
39
+ - Use `tags=[...]` on each `APIRouter`/path operation and a `summary`/`description` (or docstring) for anything beyond an obvious CRUD endpoint.
96
40
 
97
41
  ## Anti-patterns to flag, not introduce
98
42
 
99
- - An `async def` path operation that calls a synchronous DB driver or
100
- `requests.get` directly — this silently degrades every concurrent request
101
- on that worker instead of raising an obvious error.
102
- - Accepting the request body as `request: Request` and manually calling
103
- `await request.json()` to bypass Pydantic validation — this discards
104
- FastAPI's own validation, error responses, and OpenAPI schema generation
105
- for that endpoint.
106
- - Using `BackgroundTasks` for work that must not be lost (payment capture,
107
- an email a user is relying on) instead of a real task queue with
108
- retries.
43
+ - An `async def` path operation that calls a synchronous DB driver or `requests.get` directly.
44
+ - Reading the body via `request: Request` and `await request.json()` to bypass Pydantic validation.
45
+ - `BackgroundTasks` for work that must not be lost (payment capture, an email a user relies on).
@@ -7,93 +7,31 @@ metadata:
7
7
 
8
8
  # FastAPI security
9
9
 
10
- Narrows `python`'s security guidance to where FastAPI's own attack surface
11
- actually lives: path operations, dependencies, and request-body/response
12
- models — the code an unauthenticated or under-authenticated client can
13
- reach directly. In practice that means `routers/`/`api/` modules,
14
- `dependencies.py`, and `schemas/`/`models/` request-body definitions, not
15
- test files, where the same patterns (a hard-coded test JWT, a permissive
16
- CORS config asserted against) are often deliberately exercised rather than
17
- shipped.
10
+ Narrows `python`'s security guidance to FastAPI's attack surface: path operations, dependencies and request-body/response models (`routers/`/`api/` modules, `dependencies.py`, `schemas/`/`models/`), not test files.
18
11
 
19
12
  ## Input validation
20
13
 
21
- - Type every request body, query, and path parameter through Pydantic (a
22
- `BaseModel` for the body, typed function parameters for query/path
23
- params) rather than reading raw JSON off `Request` — Pydantic validation
24
- is FastAPI's primary injection defense: a field typed `int` cannot carry
25
- a SQL-injection string or an oversized payload past validation the way an
26
- untyped `dict`/`Any` parameter can.
27
- - Use `Field(...)` constraints (`max_length`, `gt`/`le`, `pattern`) on any
28
- field whose size or shape matters for downstream safety (a filename, a
29
- free-text field written to a file path, a numeric field used in a
30
- calculation) — validating shape at the model is cheaper and more
31
- reliable than validating it again deeper in the call stack.
32
- - Never accept a client-supplied value as a filesystem path, shell
33
- argument, or SQL fragment without the same validation/parameterization
34
- `python`'s `rules/security.mdc` already requires — FastAPI's own
35
- validation does not substitute for parameterized SQL or `shell=True`
36
- avoidance once the value leaves the Pydantic model.
14
+ - Type every request body, query and path parameter through Pydantic (a `BaseModel` for the body, typed parameters for query/path), not raw JSON off `Request`.
15
+ - Use `Field(...)` constraints (`max_length`, `gt`/`le`, `pattern`) on any field whose size or shape matters downstream (a filename, a file-path text field, a numeric field in a calculation).
16
+ - Never accept a client-supplied value as a filesystem path, shell argument or SQL fragment without the validation/parameterization `python`'s `rules/security.mdc` requires.
37
17
 
38
18
  ## Authentication and authorization
39
19
 
40
- - Put an auth check in a `Depends(...)` (or `Security(...)` for scoped
41
- OAuth2) dependency shared across every path operation that needs it, not
42
- duplicated inline in each path operation body — a dependency added once
43
- and reused is much harder to accidentally omit from a new endpoint than
44
- a copy-pasted inline check.
45
- - Use `OAuth2PasswordBearer`/`OAuth2PasswordRequestForm` (or the project's
46
- existing auth scheme) with a real JWT library (`pyjwt`) and a password
47
- hashing library (`pwdlib`/`passlib`) for credential handling — never
48
- compare a plaintext password directly or hash it with a fast general-
49
- purpose hash (`md5`, `sha256` with no salt/work factor).
50
- - Run the password-verify step even on a failed username lookup (compare
51
- against a dummy hash) — skipping verification when the username is
52
- unknown lets an attacker time the difference between "unknown user" and
53
- "wrong password" and enumerate valid usernames.
54
- - Never trust a client-supplied role/permission field on the request body
55
- to grant elevated access — authorization decisions come from the
56
- authenticated user record (via the auth dependency) or a trusted store,
57
- never from data the same request also supplies.
20
+ - Put the auth check in a shared `Depends(...)` (or `Security(...)` for scoped OAuth2) dependency, not inline in each path operation.
21
+ - Use `OAuth2PasswordBearer`/`OAuth2PasswordRequestForm` (or the project's auth scheme) with a real JWT library (`pyjwt`) and a password hashing library (`pwdlib`/`passlib`); never compare a plaintext password or hash with `md5` or unsalted `sha256`.
22
+ - Run the password-verify step even on a failed username lookup (compare against a dummy hash).
23
+ - Never trust a client-supplied role/permission field on the request body; take authorization from the authenticated user record or a trusted store.
58
24
 
59
25
  ## CORS
60
26
 
61
- - Configure `CORSMiddleware`'s `allow_origins` with an explicit list of
62
- trusted origins for any API that accepts cookies/credentialed requests;
63
- never combine `allow_origins=["*"]` with `allow_credentials=True` —
64
- browsers reject that combination, and if a proxy or older client allowed
65
- it anyway it would let any origin make authenticated requests on the
66
- user's behalf.
67
- - Scope `allow_methods`/`allow_headers` to what the API actually needs
68
- rather than defaulting every project to `["*"]`/`["*"]` out of habit.
27
+ - Configure `CORSMiddleware`'s `allow_origins` with an explicit list of trusted origins for any API accepting credentialed requests; never combine `allow_origins=["*"]` with `allow_credentials=True`.
28
+ - Scope `allow_methods`/`allow_headers` to what the API needs, not `["*"]`.
69
29
 
70
30
  ## Secrets and configuration
71
31
 
72
- - Read secrets (`SECRET_KEY`, database URLs, third-party API keys) through
73
- `pydantic-settings`' `BaseSettings` (or the project's existing settings
74
- module) backed by environment variables, never hard-coded in source —
75
- including in an example/tutorial-style constant left over from scaffolding.
76
- - Generate a real `SECRET_KEY` per environment (e.g. `openssl rand -hex
77
- 32`) and never reuse a tutorial/example key found in documentation or a
78
- starter template in anything beyond local experimentation.
32
+ - Read secrets (`SECRET_KEY`, database URLs, API keys) through `pydantic-settings`' `BaseSettings` (or the project's settings module) backed by environment variables, never hard-coded, including scaffolding example constants.
33
+ - Generate a real `SECRET_KEY` per environment (e.g. `openssl rand -hex 32`); never reuse a tutorial or starter-template key beyond local experimentation.
79
34
 
80
35
  ## Data access
81
36
 
82
- - Build SQL through the ORM's query builder or parameterized raw queries,
83
- never by interpolating a Pydantic model's field into a SQL string — the
84
- same rule `python`'s `rules/security.mdc` states for any Python code,
85
- restated here because a validated Pydantic field is still just a string
86
- once it reaches a raw query.
87
-
88
- ## Red flags
89
-
90
- - "I'll read the body with `await request.json()` here, the Pydantic model
91
- felt like overkill for one field" — skips validation entirely for that
92
- endpoint; use a `BaseModel`, even a one-field one.
93
- - "`allow_origins=[\"*\"]` is fine, we don't use cookies" — true only until
94
- the API adds a credentialed endpoint later; scope origins explicitly from
95
- the start rather than relying on the current absence of cookies.
96
- - "This SECRET_KEY from the FastAPI tutorial is just a placeholder, I'll
97
- swap it before we ship" — a placeholder committed to source control is a
98
- leaked secret the moment the repository is; generate the real one at
99
- deploy time from the environment instead.
37
+ - Build SQL through the ORM's query builder or parameterized raw queries, never by interpolating a Pydantic field into a SQL string.
@@ -7,79 +7,35 @@ metadata:
7
7
 
8
8
  # FastAPI testing
9
9
 
10
- Narrows `python`'s `pytest` conventions to FastAPI's own test client and
11
- dependency-override patterns. Applies only to FastAPI project files; see
12
- `skills/fastapi-testing/SKILL.md` for the full test-authoring workflow this
13
- rule file backs.
10
+ Narrows `python`'s `pytest` conventions to FastAPI's test client and dependency overrides. Applies only to FastAPI project files; see `skills/fastapi-testing/SKILL.md` for the test-authoring workflow this rule file backs.
14
11
 
15
12
  ## Test client
16
13
 
17
- - Test path operations through `fastapi.testclient.TestClient` (sync tests)
18
- or `httpx.AsyncClient` with `ASGITransport` (async tests) against the
19
- real `app` instance, rather than calling the path operation function
20
- directly — calling the function directly skips FastAPI's own request
21
- parsing, dependency resolution, and response-model filtering, which is
22
- exactly what most bugs in a path operation live in.
23
- - Build the `TestClient`/`AsyncClient` from a fixture shared across a test
24
- module (or `conftest.py` once a second module needs it), not
25
- re-instantiated per test, unless a test needs a differently configured
26
- app instance.
14
+ - Test path operations through `fastapi.testclient.TestClient` (sync) or `httpx.AsyncClient` with `ASGITransport` (async) against the real `app`, not by calling the path operation function directly.
15
+ - Build the client from a fixture shared across a test module (or `conftest.py` once a second module needs it), not per test, unless a test needs a differently configured app.
27
16
 
28
17
  ## Dependency overrides
29
18
 
30
- - Override a dependency for a test with `app.dependency_overrides[real_dep]
31
- = fake_dep`, not by monkeypatching the dependency function's module
32
- attribute — `dependency_overrides` is FastAPI's own supported mechanism
33
- and is what keeps the override scoped to the app instance under test.
34
- - Clear `app.dependency_overrides` after each test that sets one (a fixture
35
- `yield`ing the override and clearing it in teardown, or `.clear()` in the
36
- test itself) — an override left in place leaks into unrelated tests run
37
- afterward in the same process.
38
- - Use a dependency override for the current-user/auth dependency to test
39
- both an authenticated and an unauthenticated path without standing up
40
- real credential handling in every test.
19
+ - Override a dependency with `app.dependency_overrides[real_dep] = fake_dep`, not by monkeypatching the function's module attribute.
20
+ - Clear `app.dependency_overrides` after each test that sets one (a `yield` fixture or `.clear()`).
21
+ - Override the current-user/auth dependency to test authenticated and unauthenticated paths.
41
22
 
42
23
  ## Request/response assertions
43
24
 
44
- - Assert on the parsed response body (`response.json()`) and
45
- `response.status_code`, not just that the call didn't raise — a path
46
- operation that returns the wrong status code or a malformed body with no
47
- exception is a real bug a bare "it didn't crash" assertion misses.
48
- - For a validation-error case, assert the `422` status FastAPI returns for
49
- a Pydantic validation failure, not a generic exception — a request that
50
- fails Pydantic validation never reaches the path operation body at all.
51
- - When `response_model` is declared, assert that a field the model
52
- excludes (e.g. `hashed_password`) is actually absent from the response
53
- body for at least one test — this is the behavior `response_model`
54
- exists to guarantee, and a typo in the model's field list would
55
- otherwise ship unnoticed.
25
+ - Assert on `response.json()` and `response.status_code`, not just that the call did not raise.
26
+ - For a validation-error case, assert the `422` status.
27
+ - When `response_model` is declared, assert in at least one test that an excluded field (e.g. `hashed_password`) is absent from the response body.
56
28
 
57
29
  ## Database and external dependencies
58
30
 
59
- - Use a real test database (a throwaway SQLite file, a test-scoped
60
- Postgres schema, or the project's own configured test-DB fixture) behind
61
- a `get_db`-style dependency override, not a hand-rolled mock of the ORM
62
- session, for anything beyond the simplest unit test — an ORM session
63
- mock only checks that the code called the mock the way the mock expects.
64
- - Mock genuinely external services (a third-party HTTP API, an email
65
- provider) at the client boundary (`httpx`/`requests` mock, or the
66
- project's configured HTTP mocking library), matching `python`'s own
67
- testing rule: mock external dependencies, not internal collaborators.
31
+ - Use a real test database (throwaway SQLite file, test-scoped Postgres schema, or the project's test-DB fixture) behind a `get_db`-style dependency override, not a mocked ORM session, beyond the simplest unit test.
32
+ - Mock external services (a third-party HTTP API, an email provider) at the client boundary (`httpx`/`requests` mock or the project's HTTP mocking library); mock external dependencies, not internal collaborators.
68
33
 
69
34
  ## Async tests
70
35
 
71
- - Mark an async test `pytest.mark.asyncio` (or the project's configured
72
- async plugin/mode) exactly as `python`'s testing rule requires; this
73
- applies the same way to a test that awaits `AsyncClient` calls against a
74
- FastAPI app.
36
+ - Mark an async test `pytest.mark.asyncio` (or the project's configured async plugin/mode), including tests that await `AsyncClient` calls.
75
37
 
76
38
  ## Coverage expectations
77
39
 
78
- - Every new or touched path operation gets at least one test for its
79
- success path, its validation-failure path (a `422` for bad input when
80
- the body is a Pydantic model), and, when it requires auth, both an
81
- authenticated and an unauthenticated case.
82
- - A dependency with nontrivial logic (parses a header, decodes a token,
83
- applies a business rule) gets its own test independent of any path
84
- operation that happens to use it, in addition to the path operation's
85
- own integration-level test.
40
+ - Every new or touched path operation gets a test for its success path, its validation-failure path (`422` for bad input when the body is a Pydantic model) and, when it requires auth, both an authenticated and an unauthenticated case.
41
+ - A dependency with nontrivial logic (parses a header, decodes a token, applies a business rule) gets its own test independent of any path operation.
@@ -7,92 +7,54 @@ metadata:
7
7
 
8
8
  # Flutter/Dart coding style
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic style rules to modern Dart
11
- (3.x, sound null safety — mandatory since Dart 3, it cannot be disabled)
12
- and Flutter widget idiom. Applies only to `*.dart` files — everything not
13
- Dart/Flutter-specific still comes from the common rules this file
14
- `extends`.
10
+ Narrows `core-common-rules`' style rules to Effective Dart (Dart 3.x, sound null safety) and Flutter widget idiom.
15
11
 
16
12
  ## Naming and structure
17
13
 
18
- - `UpperCamelCase` for classes, enums, extensions, typedefs, and widgets;
19
- `lowerCamelCase` for variables, parameters, and methods;
20
- `lowercase_with_underscores` for file names and package/directory names —
21
- never `snake_case` identifiers or `PascalCase` file names.
22
- - A widget file is named after the widget it defines
23
- (`order_summary_card.dart` for `OrderSummaryCard`), one primary public
24
- widget per file, matching how the project already splits `lib/`.
25
- - Keep a `build()` method reading top-to-bottom as layout, not a mix of
26
- layout and business logic — push data fetching, formatting, and
27
- validation into a controller/view-model/state object the widget reads
28
- from, not inline inside `build()`.
29
- - An identifier's name shrinks with its scope: a short-lived loop index is
30
- `i`, a public widget or service class gets a full descriptive name.
14
+ - A widget file is named after the widget it defines (`order_summary_card.dart`
15
+ for `OrderSummaryCard`), one primary public widget per file, matching how the
16
+ project already splits `lib/`.
17
+ - `build()` is layout only; data fetching, formatting and validation live in a
18
+ controller/view-model/state object the widget reads from.
31
19
 
32
20
  ## Const constructors and rebuild cost
33
21
 
34
- - Mark every widget constructor `const` when all of its fields can be
35
- `final` and const-constructible — a `const` widget is skipped entirely
36
- by `build()` on a parent rebuild instead of being rebuilt and diffed,
37
- which is a real, measurable performance difference in a widget tree
38
- that rebuilds often (a list item, an animated ancestor).
39
- - Prefer `const` at the call site too (`const SizedBox(height: 8)`, `const
40
- Divider()`), not just on the constructor declaration — the analyzer's
41
- `prefer_const_constructors` lint exists to catch the call sites that
42
- could be const but are not; do not disable that lint to avoid fixing
43
- them.
44
- - A widget with a non-const field (a callback closure built fresh each
45
- `build()`, for instance) cannot be const — when that field does not
46
- actually need to vary per-build, hoist it out (a `static` handler, a
47
- field on the enclosing `State`) so the widget itself can go back to
48
- being const.
22
+ - Mark every widget constructor `const` when all fields can be `final` and
23
+ const-constructible.
24
+ - Use `const` at call sites too (`const SizedBox(height: 8)`); do not disable
25
+ `prefer_const_constructors` to avoid fixing them.
26
+ - A widget with a non-const field that need not vary per build (a callback closure
27
+ built each `build()`) hoists it out (a `static` handler, a field on the `State`)
28
+ so the widget can be const.
49
29
 
50
30
  ## Sound null safety idiom
51
31
 
52
- - Prefer `?.`/`??`/`??=` over the bang operator (`!`) — reach for `!` only
53
- when the value's non-nullability is guaranteed by code the analyzer
54
- cannot see (already checked a few lines above with no intervening
55
- `await`, or a documented invariant), and say why in a comment when it is
56
- not obvious.
57
- - Never use `!` on a value that crossed an `await` since it was last
58
- checked, or on a field read from a widget/state that could have been
59
- disposed in between — re-check (`if (value == null) return;` or
60
- `context.mounted`) after the async gap instead of re-asserting non-null.
61
- - Declare a field `late` only when it is genuinely always initialized
62
- before first read (e.g. in `initState`) — a `late` field that can
63
- legitimately be unset just trades a compile-time nullability warning for
64
- a runtime `LateInitializationError`, which is strictly worse.
65
- - Give a nullable parameter a sensible default via `??` at the point of
66
- use rather than threading a null check through every downstream
67
- consumer of that parameter.
32
+ - Prefer `?.`/`??`/`??=` over `!`; use `!` only when non-nullability is guaranteed
33
+ by code the analyzer cannot see (checked just above with no intervening `await`,
34
+ or a documented invariant), with a comment when not obvious.
35
+ - Never use `!` on a value that crossed an `await` since it was last checked, or on
36
+ a field of a widget/state that could have been disposed; re-check
37
+ (`if (value == null) return;` or `context.mounted`) after the async gap.
38
+ - Declare a field `late` only when it is always initialized before first read
39
+ (e.g. in `initState`).
40
+ - Give a nullable parameter a default via `??` at the point of use rather than
41
+ threading a null check through every consumer.
68
42
 
69
43
  ## Composition over deep nesting
70
44
 
71
- - Extract a widget into its own class (or a private `_SectionWidget`
72
- below the file's main widget) once a single `build()` method's nesting
73
- becomes hard to scan — composition of small, focused widgets is the
74
- idiomatic Flutter equivalent of extracting a function, and each
75
- extracted piece can independently be `const` and independently testable
76
- with `testWidgets`.
77
- - Prefer a `Column`/`Row`/`Wrap` plus a handful of small child widgets
78
- over one large widget expression with many positional/named-argument
79
- levels of `Padding(child: Container(child: Column(children: [...])))` —
80
- flatten with `SizedBox`/`Padding` siblings and extracted widgets instead
81
- of nesting purely to achieve a visual effect a flatter tree would give
82
- just as well.
83
- - A `build()` method that branches on more than two or three conditions to
84
- decide what to render is a sign the widget is doing too much — extract
85
- each branch into its own small widget so each one is readable and
86
- testable in isolation.
45
+ - Extract a widget into its own class (or a private `_SectionWidget` below the
46
+ main widget) once a `build()` method's nesting is hard to scan.
47
+ - Flatten with `SizedBox`/`Padding` siblings and extracted widgets rather than
48
+ nesting `Padding(child: Container(child: Column(...)))` for a visual effect a
49
+ flatter tree gives.
50
+ - A `build()` that branches on more than two or three conditions extracts each
51
+ branch into its own widget.
87
52
 
88
53
  ## Formatting and imports
89
54
 
90
- - Format with `dart format` before finishing a change — do not hand-format
91
- around a formatter that is already configured; CI enforces `dart format
92
- --set-exit-if-changed .` in most Flutter repos.
93
- - Order imports `dart:` / `package:flutter` / other `package:` / relative,
94
- with a blank line between groups, matching whatever the project's
95
- `analysis_options.yaml` (e.g. `directives_ordering`) already enforces.
96
- - Prefer relative imports within the same package's `lib/` tree and
97
- `package:` imports for anything outside it, matching the project's
98
- existing convention rather than switching styles mid-file.
55
+ - Format with `dart format`; do not hand-format around a configured formatter.
56
+ - Order imports `dart:` / `package:flutter` / other `package:` / relative, a blank
57
+ line between groups, matching the project's `analysis_options.yaml`
58
+ (`directives_ordering`).
59
+ - Relative imports within the same package's `lib/` tree, `package:` imports for
60
+ anything outside it, matching the project's convention.