A comprehensive Spring Boot 3 application demonstrating enterprise architecture patterns, 16 design patterns, and a production-ready multi-tenant order & audit platform with SOLID principles and Java best practices.
This project combines two major components:
- Design Patterns Playground - 16 design patterns with enterprise-grade implementations
- Multi-Tenant Order & Audit Platform - Production-ready enterprise application with OAuth2, JWT, MySQL, MongoDB, and comprehensive audit logging
This repository includes comprehensive documentation for all aspects of the project:
-
Design Patterns Complete Guide 📖
- Comprehensive guide with all 16 patterns
- When to use/not use each pattern
- SOLID principles examples
- API documentation and examples
-
- Quick reference and architecture overview
- Pattern endpoints and testing guide
- Code structure and organization
-
- Complete architecture documentation
- OAuth2 + JWT security setup
- Database schema and migrations
- API endpoints and examples
- Production considerations
-
Internationalization (i18n) Guide 🌍
- i18n implementation details
- Message resource management
- Locale detection and switching
- Adding new languages
- API Testing: requests/patterns.http - Design pattern endpoints
- API Testing: requests/orders.http - Multi-tenant platform endpoints
- Swagger UI:
http://localhost:8080/swagger-ui.html(when running)
- Java 17+
- Maven 3.6+
- MySQL 8.0+ (for multi-tenant platform)
- MongoDB (for multi-tenant platform)
# Clone the repository
git clone <repository-url>
cd spring-boot-enterprise-patterns
# Build the project
./mvnw clean install
# For Design Patterns only (no database required)
./mvnw spring-boot:run
# For Multi-Tenant Platform (requires MySQL & MongoDB)
export DB_HOST=127.0.0.1
export DB_USER=root
export DB_PASSWORD=your_password
export MONGODB_URI=mongodb://localhost:27071/order_platform
./mvnw spring-boot:run- API Base URL:
http://localhost:8080 - Swagger UI:
http://localhost:8080/swagger-ui.html - API Documentation:
http://localhost:8080/v3/api-docs - Actuator Health:
http://localhost:8080/actuator/health
| Pattern | Category | Use Case | Endpoint |
|---|---|---|---|
| Singleton | Creational | Configuration Service | /api/patterns/singleton |
| Factory Method | Creational | Order Validator Factory | /api/patterns/factory-method |
| Abstract Factory | Creational | Payment Gateway Families | /api/patterns/abstract-factory |
| Builder | Creational | Order Construction | /api/patterns/builder |
| Prototype | Creational | Order Snapshots | /api/patterns/prototype |
| Adapter | Structural | Legacy System Integration | /api/patterns/adapter |
| Decorator | Structural | Cross-cutting Concerns | /api/patterns/decorator |
| Facade | Structural | Simplified Trading API | /api/patterns/facade |
| Strategy | Behavioral | Payment Processing | /api/patterns/strategy |
| Command | Behavioral | Order Management (Undo/Redo) | /api/patterns/command |
| Observer | Behavioral | Domain Events (Pub-Sub) | /api/patterns/observer |
| Chain of Responsibility | Behavioral | Order Validation Pipeline | /api/patterns/chain-of-responsibility |
| State | Behavioral | Order Lifecycle State Machine | /api/patterns/state |
| Mediator | Behavioral | Order Processing Workflow | /api/patterns/mediator |
| Repository | Architectural | Data Access Abstraction | /api/patterns/repository |
📖 Learn More: See Design Patterns Complete Guide
Enterprise-grade platform featuring:
- Hexagonal Architecture (Ports & Adapters)
- OAuth2 + JWT security with Spring Authorization Server
- Multi-tenancy with tenant isolation
- MySQL (system of record) + MongoDB (audit logs)
- Comprehensive audit trail with snapshots
- Flyway migrations for database schema
- Production-ready configuration
API Endpoints:
POST /api/v1/orders- Create orderPUT /api/v1/orders/{id}- Update orderGET /api/v1/orders/{id}- Get orderGET /api/v1/orders- Search ordersGET /api/v1/audit- Get audit trailGET /api/v1/orders/{id}/snapshots- Get snapshots
📖 Learn More: See Multi-Tenant Platform Guide
src/main/java/com/mohsindev/springbootenterprisepatterns/
├── controller/ # REST Controllers (organized by pattern)
├── services/ # Pattern implementations
├── dto/ # Data Transfer Objects
├── domain/ # Domain models and shared DTOs
├── config/ # Configuration classes
├── exception/ # Exception handling
├── infrastructure/ # Cross-cutting concerns
└── interceptor/ # Request interceptors
src/main/java/com/mohsindev/springbootenterprisepatterns/
├── application/ # Use cases / orchestration
├── controller/ # REST controllers
├── domain/ # Domain layer (entities, ports)
├── adapters/ # Adapter implementations
│ ├── persistence/ # MySQL & MongoDB
│ └── security/ # JWT claim extraction
├── dto/ # Data Transfer Objects
├── config/ # Security & configuration
└── infrastructure/ # Cross-cutting concerns
📖 Learn More: See Design Patterns README and Multi-Tenant Platform Guide
# Test all patterns
curl http://localhost:8080/api/patterns/singleton/demo
curl http://localhost:8080/api/patterns/factory-method/demo
# ... see requests/patterns.http for all endpoints📖 Learn More: See requests/patterns.http
# Get OAuth2 token first, then:
curl -X POST http://localhost:8080/api/v1/orders \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"items": [{"sku": "SKU001", "quantity": 2, "price": 10.50}]}'📖 Learn More: See requests/orders.http
This project demonstrates all five SOLID principles:
- Single Responsibility Principle - Each class has one clear purpose
- Open/Closed Principle - Open for extension, closed for modification
- Liskov Substitution Principle - Implementations are interchangeable
- Interface Segregation Principle - Focused, minimal interfaces
- Dependency Inversion Principle - Depend on abstractions, not concretions
📖 Learn More: See Design Patterns Complete Guide
- ✅ Global Exception Handling (
@ControllerAdvice) - ✅ Request Interceptors (logging, correlation IDs)
- ✅ Metrics Integration (Micrometer/Prometheus)
- ✅ CORS Configuration
- ✅ Input Validation (Bean Validation)
- ✅ Comprehensive Logging
- ✅ API Documentation (Swagger/OpenAPI)
- ✅ Internationalization (i18n) - Multi-language support
- ✅ OAuth2 + JWT Security
- ✅ Tenant Isolation Enforcement
- ✅ Scope-based Authorization
- ✅ Database Migrations (Flyway)
- ✅ Audit Trail & Snapshots
- ✅ Correlation ID Tracking
- ✅ Production-ready Configuration
📖 Learn More:
- Start with README.md (this file) - Project overview
- Read Design Patterns Complete Guide - Learn patterns
- Explore Design Patterns README - Quick reference
- Test patterns using requests/patterns.http
- Study Multi-Tenant Platform Guide - Enterprise architecture
- Review I18N Implementation Guide - Internationalization
- Test platform using requests/orders.http
- Explore the codebase structure
- Study Hexagonal Architecture implementation
- Review OAuth2 + JWT security setup
- Analyze database schema and migrations
- Review production considerations
- Patterns solve common problems - Don't force patterns where they don't fit
- SOLID principles guide design - Patterns help achieve SOLID goals
- Architecture matters - Hexagonal architecture provides clean boundaries
- Security is critical - OAuth2 + JWT with tenant isolation
- Practice makes perfect - Implement patterns in your own projects
- ✅ Comprehensive JavaDoc documentation
- ✅ SOLID principles throughout
- ✅ Professional code structure
- ✅ Error handling
- ✅ Unit test coverage
- ✅ Best practices followed
- ✅ Production-ready configuration
This is a learning/teaching repository demonstrating enterprise Spring Boot patterns and practices. Feel free to:
- Explore the codebase
- Run the application
- Test the endpoints
- Study the patterns
- Use as a reference for your projects
| Document | Description |
|---|---|
| README.md | Main entry point (you are here) |
| DESIGN_PATTERNS_COMPLETE.md | Complete design patterns guide |
| DESIGN_PATTERNS_README.md | Design patterns quick reference |
| MULTI_TENANT_PLATFORM_README.md | Multi-tenant platform guide |
| I18N_IMPLEMENTATION.md | Internationalization guide |
| requests/patterns.http | Design pattern API requests |
| requests/orders.http | Multi-tenant platform API requests |
This project is for educational purposes.
Happy Learning! 🚀
For questions or contributions, please refer to the individual documentation files linked above.