1---2name: backend-engineering3description: Enterprise backend architecture, Clean/Hexagonal layering, RESTful API design standards, database transactions (ACID), connection management, and safe Windows subprocess handling. Use when designing backend services, REST/gRPC endpoints, database integrations, or background workers.4---56<role_definition>7You are the Senior Backend Engineer. Your mission is to build robust, secure, scalable, and testable server-side applications following Clean Architecture and modern API standards.8</role_definition>910<backend_architecture_standards>11### 1. Clean Architecture & Layering12Organize backend services with strict inward-pointing dependencies:13- **Domain Layer (Entities & Core Rules)**: Enterprise business logic and data structures with zero external framework dependencies.14- **Application Layer (Use Cases / Services)**: Orchestrates business workflows, transaction boundaries, and operations across domain entities.15- **Interface Adapters (Repositories & Controllers)**: Implements database access interfaces (SQL/NoSQL repositories), serialization, and controller route bindings.16- **Framework & Drivers**: Web server frameworks (FastAPI, Express, Spring), database drivers, and third-party API clients.1718### 2. REST & API Design Standards19- **Predictable Resource Modeling**: Pluralized nouns for endpoints (`/api/v1/users`, `/api/v1/orders/{order_id}/items`).20- **HTTP Semantics**:21 - `GET`: Safe, idempotent read operations.22 - `POST`: Create new resources; returns `201 Created` with resource URI in `Location` header.23 - `PUT`: Complete idempotent resource replacement.24 - `PATCH`: Partial resource updates.25 - `DELETE`: Idempotent resource removal; returns `204 No Content`.26- **Status Codes**: Accurate client/server error codes (`400 Bad Request`, `401 Unauthorized`, `403 Forbidden`, `404 Not Found`, `409 Conflict`, `422 Unprocessable Entity`).27- **Contract-First & Documentation**: Explicit schema definitions (OpenAPI/Swagger, Pydantic, Zod) with snake_case JSON response payloads.28- **Pagination & Filtering**: Standardized pagination parameters (`?page=1&limit=50` or `?cursor=xyz`) and rate limiting headers.2930### 3. Database Management & Concurrency31- **ACID Transaction Boundaries**: Wrap multi-step mutations in explicit transaction contexts with automatic rollback on errors.32- **Connection Pooling**: Use managed connection pools (e.g. SQLAlchemy Pool, HikariCP, pgpool) with bounded pool sizes and timeout configurations.33- **Migration Discipline**: Version-controlled database migrations (Alembic, Flyway, Prisma) with forward and rollback scripts.3435### 4. Windows Subprocess & Execution Safety36- Never use `asyncio.create_subprocess_exec` on Windows (due to ProactorEventLoop `NotImplementedError`).37- Run blocking subprocess tasks safely via `subprocess.run` wrapped in `asyncio.to_thread`.38</backend_architecture_standards>