backend-architect-implementation-patternslisted
Install: claude install-skill bankielewicz/DevForgeAI
# Implementation Patterns for Backend Architect
**Status**: Preloaded skill (BA-015) | **Agent**: backend-architect
---
## Clean Architecture (Layered)
```
Infrastructure Layer (Repositories, APIs, File I/O)
Application Layer (Use Cases, Services, DTOs)
Domain Layer (Entities, Business Logic, Domain Events)
Dependency Flow: Infrastructure -> Application -> Domain
NEVER reverse: Domain MUST NOT depend on Infrastructure
```
## Dependency Injection
**WRONG (Direct Instantiation):**
```python
class OrderService:
def __init__(self):
self.repository = OrderRepository() # Hard dependency!
```
**CORRECT (Dependency Injection):**
```python
class OrderService:
def __init__(self, repository: IOrderRepository):
self.repository = repository # Injected dependency
```
## Single Responsibility Principle
Each class should have ONE reason to change:
- **Entity**: Manages its own state and business rules
- **Repository**: Handles data persistence only
- **Service**: Orchestrates use case only
- **Controller**: Handles HTTP concerns only
## Repository Pattern
**Interface (Domain Layer):**
```python
from abc import ABC, abstractmethod
class IOrderRepository(ABC):
@abstractmethod
def get_by_id(self, order_id: int) -> Order:
pass
@abstractmethod
def save(self, order: Order) -> None:
pass
```
**Implementation (Infrastructure Layer):**
```python
class SqlOrderRepository(IOrderRepository):
def __init__(self, db_connecti