Real Production Folder Structure
Serious teams organise a Spring Boot 3 service by feature, then layer inside each feature.
Introduction
Serious teams organise a Spring Boot 3 service by feature, then layer inside each feature. TechLearningPRO Orders grows painful when everything lives in controller/, service/, repository/ packages that sprawl across domains.
Package-by-feature keeps orders, billing, and catalog changes local. Clean-architecture folders inside a feature (api, application, domain, infrastructure) keep HTTP, use cases, and persistence honest.
This lesson shows a production layout you can paste into a Boot 3 / Java 21 Orders repo today.
Purpose of this lesson
Restructure Orders into feature packages with internal clean-architecture layers suitable for Boot 3 production teams.
Understanding the topic
Feature first; layers second; shared means truly shared.
- Feature packages —
orders/,billing/,catalog/. - Internal layers — api → application → domain → infrastructure.
- config/ — Security, Kafka, Observability beans.
- shared/ — money, ids, problem-details — not a dumping ground.
- Tests — mirror the feature tree; Testcontainers at the feature edge.
Step-by-step explanation
- Create
com.techlearningpro.orders.orderswith api/application/domain/infrastructure. - Move controllers/DTOs into
api, use cases intoapplication, aggregates intodomain. - Keep JPA entities and Kafka publishers under
infrastructure. - Delete cross-feature imports that pierce domain boundaries; route via application services.
Syntax reference
Production Orders tree (package-by-feature).
com.techlearningpro.orders/├── OrdersApplication.java├── config/│ ├── SecurityConfig.java│ ├── KafkaConfig.java│ └── ObservabilityConfig.java├── orders/│ ├── api/│ │ ├── OrderController.java│ │ ├── dto/│ │ └── ApiExceptionHandler.java│ ├── application/│ │ ├── PlaceOrderUseCase.java│ │ ├── CancelOrderUseCase.java│ │ └── OrderQueries.java│ ├── domain/│ │ ├── Order.java│ │ ├── OrderItem.java│ │ └── events/OrderPlaced.java│ └── infrastructure/│ ├── persistence/