safe-agentic-workflow / rules
Cursor rule419 starsChanged 4 months agoMITView on GitHub
Backend Python development rules for FastAPI, SQLAlchemy 2.x, async patterns, and Alembic migrations.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository60 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/00-core-principles.mdcCursor rule
- .cursor/rules/01-git-workflow.mdcCursor rule
- .cursor/rules/02-pattern-discovery.mdcCursor rule
- .cursor/rules/03-safe-ai-dlc.mdcCursor rule
- .cursor/rules/04-knowledge-vault.mdcCursor rule
- .cursor/rules/11-frontend-react.mdcCursor rule
- .cursor/rules/12-database-sql.mdcCursor rule
- .cursor/rules/13-testing.mdcCursor rule
- .cursor/rules/14-spec-creation.mdcCursor rule
- .cursor/rules/15-deployment.mdcCursor rule
- .cursor/rules/16-stripe-payments.mdcCursor rule
- .cursor/rules/20-agent-architect.mdcCursor rule
- .cursor/rules/21-agent-backend.mdcCursor rule
- .cursor/rules/22-agent-qas.mdcCursor rule
- .cursor/rules/23-agent-security.mdcCursor rule
- .cursor/rules/30-background-agents.mdcCursor rule
- .cursor/rules/31-mcp-integration.mdcCursor rule
- .cursor/rules/README.mdCursor rule
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
The file
Show its rules and text
We split this 10-backend-python.mdc into the rules it gives an agent
13 rules. About 0 are common, 8 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 21
Use ruff for linting and formatting (config in pyproject.toml)
- Very specific: line 22
Always run ruff check . before committing
- Very specific: line 23
Use mypy for type checking
- Distinctive: line 25
Use async/await patterns for all FastAPI endpoints
- Distinctive: line 29
CRITICAL: All database operations MUST use RLS context helpers.
- Distinctive: line 45
Never use direct session calls without RLS context wrappers.
- Distinctive: line 58
Always create proper Alembic migrations (never skip)
- Distinctive: line 60
Add RLS policies for any new tables
- Distinctive: line 65
Use dependency injection for database sessions
- Distinctive: line 66
Use Pydantic v2 models for request/response validation
- Distinctive: line 67
Use proper HTTP status codes
- Very specific: line 73
Use pytest with async support (pytest-asyncio)
- Very specific: line 74
Run pytest tests/ before committing
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Backend Python development rules for FastAPI, SQLAlchemy 2.x, async patterns, and Alembic migrations."
globs: "core/**/*.py,edgekit/**/*.py"
alwaysApply: false
---
# Backend Python Rules
These rules apply when working on backend Python code in `core/` and `edgekit/`.
## Technology Stack
- **Framework**: FastAPI (Python 3.11+)
- **ORM**: SQLAlchemy 2.x with async session patterns
- **Migrations**: Alembic
- **Database**: PostgreSQL 16
- **Authentication**: JWT (custom implementation)
## Coding Standards
- Use `ruff` for linting and formatting (config in `pyproject.toml`)
- Always run `ruff check .` before committing
- Use `mypy` for type checking
- Python 3.11+ features are allowed (StrEnum, etc.)
- Use async/await patterns for all FastAPI endpoints
## Database Operations
**CRITICAL**: All database operations MUST use RLS context helpers.
```python
# User operations
async with with_user_context(session, user_id) as ctx:
result = await ctx.execute(select(Model).where(Model.user_id == user_id))
# Admin operations
async with with_admin_context(session, user_id) as ctx:
result = await ctx.execute(select(Model))
# System/background operations
async with with_system_context(session, "source_name") as ctx:
result = await ctx.execute(insert(Model).values(data))
```
Never use direct session calls without RLS context wrappers.
## Migration Workflow
```bash
alembic revision --autogenerate -m "description" # Create migration
alembic upgrade head # Apply locally
# Review the generated migration file before committing
git add alembic/versions/
git commit -m "feat(db): add migration description [{{TICKET_PREFIX}}-XXX]"
```
Rules:
- Always create proper Alembic migrations (never skip)
- Review auto-generated migrations for correctness
- Add RLS policies for any new tables
- Schema changes require System Architect approval
## FastAPI Patterns
- Use dependency injection for database sessions
- Use Pydantic v2 models for request/response validation
- Use proper HTTP status codes
- Include OpenAPI documentation (FastAPI generates this)
- Use structured logging
## Testing
- Use `pytest` with async support (`pytest-asyncio`)
- Run `pytest tests/` before committing
- Integration tests go in `tests/integration/`
- E2E tests go in `tests/e2e/`
## Key References
- See `patterns_library/api/` for API route patterns
- See `docs/database/DATA_DICTIONARY.md` for schema reference
- See `docs/database/RLS_IMPLEMENTATION_GUIDE.md` for RLS patterns
- See `CONTRIBUTING.md` for full workflow details
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

