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
-
Design Patterns README ποΈ
- Quick reference and architecture overview
- Pattern endpoints and testing guide
- Code structure and organization
-
Multi-Tenant Platform Guide π’
- 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.