Project Structure & Organization
Package Structure: Using feature-based packaging instead of layer -based
( controller, service, repository ) packages. Instead organize by business
domains like ( user, order, payment ) . This makes the codebase more
maintainable reducing coupling between unrelated features
✅ Feature-based (recommended)
[Link]
├── user/
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── dto/
│ └── entity/
├── order/
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── dto/
│ └── entity/
├── payment/
└── shared/
├── exception/
├── config/
└── util/
Hybrid approach for complex features with multiple subdomains
[Link]
├── user/
│ ├── profile/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── dto/
│ ├── authentication/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── security/
│ └── [Link] // Shared across user subdomains
├── order/
Subdomain-Based Internal Organization:
user/
├── profile/
│ ├── api/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── [Link]
│ ├── domain/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── [Link]
│ └── infrastructure/
│ ├── [Link]
│ └── [Link]
├── authentication/
│ ├── api/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── [Link]
│ ├── domain/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── [Link]
│ ├── infrastructure/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── external/
│ │ └── [Link]
│ └── security/
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
├── preferences/
│ ├── api/
│ │ ├── [Link]
│ │ └── [Link]
│ ├── domain/
│ │ ├── [Link]
│ │ ├── [Link]
│ │ └── [Link]
│ └── infrastructure/
│ └── [Link]
├── shared/
│ ├── domain/
│ │ ├── [Link] # Core user entity shared across subdomains
│ │ ├── [Link] # Value object
│ │ └── [Link] # Domain events
│ ├── infrastructure/
│ │ ├── [Link] # Shared repository
│ │ ├── [Link] # JPA entity
│ │ └── [Link] # Maps between domain and JPA entities
│ └── api/
│ └── [Link] # Basic user DTO used across subdomains
└── internal/
├── [Link] # Cross-subdomain caching
├── [Link] # Internal event handling
└── audit/
├── [Link]
└── [Link]