Backend Hexagonal Architecture
Layer Separation
domain/
- entities/: Domain models (MateriaPrima, Escandallo, Factura, etc.)
- ports/: Trait definitions (repository interfaces)
- services/: Pure business logic (coste calculation, rentabilidad)
- NO external dependencies (no Axum, no SQLx, no HTTP)
adapters/
- http/handlers/: HTTP request handlers
- http/dto/: Request/response DTOs
- http/middleware/: Auth middleware
- CAN import from
domain and crate::repository
infrastructure/
- persistence/postgres/: Repository trait implementations
- ocr/: OCR service implementations
- unpispas_client/: unpispas API client
- config.rs: Environment configuration
Import Rules
- Handlers MUST use
crate::repository, NEVER crate::infrastructure::persistence::postgres
- Domain layer MUST NOT import from adapters or infrastructure
crate::error::AppError is the only error type in handler return types