Controller Layer
The Controller Layer serves as the HTTP API entry point for all client requests. It handles request routing, validation, authentication/authorization checks, and response formatting.
Location:
src/main/java/com/smartsupplypro/inventory/controller/
Responsibility: HTTP protocol handling, request validation, response building, error mapping
Quick Navigation
By Topic
- Routing - URL mapping and HTTP methods
- Validation - Input validation and constraints
- Authorization - Authentication and role checks
- DTO Conversion (Inbound) - JSON → Object mapping
- DTO Conversion (Outbound) - Object → JSON mapping
- Response Building - HTTP status codes and responses
- Core Controllers - SupplierController, InventoryItemController, etc.
- Error Handling Flow - Exception mapping to HTTP responses
- Best Practices - Standards and guidelines
- Request/Response Lifecycle - Complete flow through the layer
- Integration - How controller connects to service layer
- Testing - Unit and integration testing strategies
By Role
- API Developers → Start with Routing → Core Controllers
- Security Engineers → Review Authorization
- QA/Testing → Check Testing and Validation
- New Team Members → Begin with Best Practices
Architecture Overview
graph TB
Client["Client
REST Requests"] Routes["Request Routing
@GetMapping, @PostMapping, etc."] Auth["Authorization
@PreAuthorize"] Validation["Request Validation
@Valid, @NotNull"] Mapping["DTO Conversion
Request → Internal"] Service["Service Layer
Business Logic"] DTOResp["DTO Conversion
Domain → Response"] Response["HTTP Response
JSON Serialization"] Client -->|HTTP| Routes Routes --> Auth Auth -->|Check Roles| Validation Validation -->|Validate DTO| Mapping Mapping -->|Convert| Service Service -->|Execute Business Logic| DTOResp DTOResp -->|Convert| Response Response -->|JSON| Client style Client fill:#e3f2fd style Routes fill:#bbdefb style Auth fill:#90caf9 style Validation fill:#64b5f6 style Mapping fill:#42a5f5 style Service fill:#2196f3 style DTOResp fill:#1976d2 style Response fill:#1565c0
REST Requests"] Routes["Request Routing
@GetMapping, @PostMapping, etc."] Auth["Authorization
@PreAuthorize"] Validation["Request Validation
@Valid, @NotNull"] Mapping["DTO Conversion
Request → Internal"] Service["Service Layer
Business Logic"] DTOResp["DTO Conversion
Domain → Response"] Response["HTTP Response
JSON Serialization"] Client -->|HTTP| Routes Routes --> Auth Auth -->|Check Roles| Validation Validation -->|Validate DTO| Mapping Mapping -->|Convert| Service Service -->|Execute Business Logic| DTOResp DTOResp -->|Convert| Response Response -->|JSON| Client style Client fill:#e3f2fd style Routes fill:#bbdefb style Auth fill:#90caf9 style Validation fill:#64b5f6 style Mapping fill:#42a5f5 style Service fill:#2196f3 style DTOResp fill:#1976d2 style Response fill:#1565c0