ProLesson 3.1Intermediate3 min readUpdated 31 October 2026
Microservice Project Structure & Layered Architecture
Structure production Spring Boot 3 microservices with strict separation between Controllers, Services, Repositories, Entities, and DTOs.
A production microservice must be clean, maintainable, and resilient to change.
When teams rush to ship features without a clear package and layer convention, controllers start querying databases directly, domain logic leaks into HTTP handlers, and database entities are returned directly to mobile apps—leaking sensitive internal fields like password hashes or credit card tokens.
In this lesson, we establish the standard Spring Boot 3 microservice architecture.
01The Standard Package Structure
Here is the battle-tested package layout used by senior Spring Boot engineers:
text
com.veltoryx.order/
├── OrderServiceApplication.java # Spring Boot 3 main class
├── controller/ # Web Layer: REST endpoints & DTO mappings
│ ├── OrderController.java
│ └── dto/
│ ├── CreateOrderRequest.java # Java 17+ Record
│ └── OrderResponse.java # Java 17+ Record
├── service/ # Domain / Application Business Layer
│ ├── OrderService.java # Interface
│ └── impl/
│ └── OrderServiceImpl.java # Business rules & @Transactional boundaries
├── repository/ # Persistence Layer: Spring Data JPA
│ └── OrderRepository.java
├── model/
│ ├── entity/ # JPA Database Entities (Internal schema)
│ │ ├── OrderEntity.java
│ │ └── OrderItemEntity.java
│ └── enums/
│ └── OrderStatus.java
└── exception/ # Error Handling
├── GlobalExceptionHandler.java # @RestControllerAdvice (RFC 7807)
└── OrderNotFoundException.javaLoading the rest of the lesson…