Skip to content

Commit 7ba2d01

Browse files
fix: address CodeRabbit review — idempotency_key naming, contextvars import, single-writer generalization, alphabetical order
1 parent d7e5509 commit 7ba2d01

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ By creating a `.cursorrules` file in your project's root directory, you can leve
148148
- [Python (Django Best Practices)](./rules/python-django-best-practices-cursorrules-prompt-fi/.cursorrules) - Cursor rules for Python Django development with best practices.
149149
- [Python (FastAPI Best Practices)](./rules/python-fastapi-best-practices-cursorrules-prompt-f/.cursorrules) - Cursor rules for Python FastAPI development with best practices.
150150
- [Python (FastAPI Scalable API)](./rules/python-fastapi-scalable-api-cursorrules-prompt-fil/.cursorrules) - Cursor rules for Python FastAPI development with scalable API integration.
151-
- [vibecodex FastAPI Production](./rules/vibecodex-fastapi-production-cursorrules-prompt-file/.cursorrules) - Production architecture rules: Router→Service→Repository, ACL, bulkhead isolation, single-writer principle
152151
- [Python (Flask JSON Guide)](./rules/python-flask-json-guide-cursorrules-prompt-file/.cursorrules) - Cursor rules for Python Flask development with JSON guide.
153152
- [Python LLM & ML Workflow](./rules/python-llm-ml-workflow-cursorrules-prompt-file/.cursorrules) - Cursor rules for Python LLM & ML development with workflow integration.
154153
- [Salesforce (Apex)](./rules/salesforce-apex-cursorrules-prompt-file/.cursorrules.txt) - Cursor rules for Salesforce development with Apex integration.
155154
- [TypeScript (NestJS Best Practices)](./rules/typescript-nestjs-best-practices-cursorrules-promp/.cursorrules) - Cursor rules for TypeScript development with NestJS best practices.
156155
- [TYPO3 CMS Extension](./rules/typo3cms-extension-cursorrules-prompt-file/.cursorrules) - Cursor rules for TYPO3 CMS development with extension integration.
156+
- [vibecodex FastAPI Production](./rules/vibecodex-fastapi-production-cursorrules-prompt-file/.cursorrules) - Production architecture rules: Router→Service→Repository, ACL, bulkhead isolation, single-writer principle
157157
- [WordPress (PHP, Guzzle, Gutenberg)](./rules/wordpress-php-guzzle-gutenberg-cursorrules-prompt-/.cursorrules) - Cursor rules for WordPress development with PHP, Guzzle, and Gutenberg integration.
158158
- [WordPress (macOS)](./rules/cursorrules-cursor-ai-wordpress-draft-macos-prompt/.cursorrules) - Cursor rules for WordPress development on macOS.
159159

rules/vibecodex-fastapi-production-cursorrules-prompt-file/.cursorrules

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ async def charge(
2222
user_id: str = Depends(get_current_user_id),
2323
svc: WalletUserService = Depends(get_wallet_service),
2424
) -> WalletResponse:
25-
wallet = await svc.charge(user_id=user_id, amount=req.amount, key=req.idempotency_key)
25+
wallet = await svc.charge(
26+
user_id=user_id,
27+
amount=req.amount,
28+
idempotency_key=req.idempotency_key,
29+
)
2630
return WalletResponse.from_domain(wallet)
2731

2832
BAD (business logic + SQL in router):
@@ -130,13 +134,21 @@ Every side-effect operation accepts an idempotency_key: UUID. Look up before ret
130134
### Rule 4: Structured Logging with contextvars
131135
Use ContextVar to thread provider, user_id, request_id through async call stacks.
132136

133-
provider_var = contextvars.ContextVar[str | None]("provider", default=None)
134-
user_id_var = contextvars.ContextVar[str | None]("user_id", default=None)
137+
import contextvars
138+
139+
provider_var = contextvars.ContextVar[str | None]("provider", default=None)
140+
user_id_var = contextvars.ContextVar[str | None]("user_id", default=None)
141+
request_id_var = contextvars.ContextVar[str | None]("request_id", default=None)
142+
143+
# Read in logs: provider_var.get(), user_id_var.get(), request_id_var.get()
144+
# JSON formatter picks these up automatically via extra={} or ContextVar.get()
135145

136146
### Rule 5: Single-Writer Principle (Principle B10)
137-
For safety-critical state: exactly ONE function does the writing.
138-
repo.hold() may only be called from services/credits/user.py.
139-
No router, no admin service, no provider may call repo.hold() directly.
147+
For safety-critical state: exactly ONE service-layer module does the writing.
148+
Only service-layer modules may call repo.hold().
149+
Routers, providers, and admin services must NOT call repo.hold() directly.
150+
Enforce via: code-review grep check (`grep -r "repo\.hold(" --include="*.py"`)
151+
and unit tests that assert call-origin of repo.hold().
140152

141153
## ANTI-PATTERNS — REJECT ON SIGHT
142154

0 commit comments

Comments
 (0)