# FastAPI Rules

Full coding rules for this stack. Read this in full before writing or modifying any FastAPI code in this project — not just once, keep applying it to every edit in the session, not only the first.

---

## Project Structure

```
app/
├── main.py          # App entry point & routing configuration
├── api/             # API routes (divided by feature)
├── core/            # App-wide settings, security, and utils
├── crud/            # Database operations (Create, Read, Update, Delete)
├── models/          # Database models (SQLAlchemy/SQLModel)
├── schemas/         # Pydantic schemas (Request/Response models)
├── db/              # Database session & engine configuration
└── tests/           # Pytest suite
```

---

## FastAPI Rules

- Use **Async/Await** for all I/O bound operations (database calls, external APIs).
- Always use **Pydantic** schemas for request body validation and response serialization.
- Use **Dependency Injection** (via `Depends`) for database sessions, authentication, and reusable logic.
- Document every endpoint using FastAPI's built-in OpenAPI support (Docstrings and Pydantic field descriptions).

---

## Testing Rules

- Use **Pytest** and `httpx` (AsyncClient) for integration testing.
- Test both success and failure cases for each endpoint.
