Skip to content

Latest commit

 

History

History
294 lines (223 loc) · 10.9 KB

File metadata and controls

294 lines (223 loc) · 10.9 KB

Spring Boot Enterprise Platform

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.

🎯 Project Overview

This project combines two major components:

  1. Design Patterns Playground - 16 design patterns with enterprise-grade implementations
  2. Multi-Tenant Order & Audit Platform - Production-ready enterprise application with OAuth2, JWT, MySQL, MongoDB, and comprehensive audit logging

📚 Documentation Index

This repository includes comprehensive documentation for all aspects of the project:

Core Documentation

  • 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

Quick Links

🚀 Quick Start

Prerequisites

  • Java 17+
  • Maven 3.6+
  • MySQL 8.0+ (for multi-tenant platform)
  • MongoDB (for multi-tenant platform)

Running the Application

# 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

Access Points

  • 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

📖 What's Included

1. Design Patterns (16 Patterns)

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

2. Multi-Tenant Order & Audit Platform

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 order
  • PUT /api/v1/orders/{id} - Update order
  • GET /api/v1/orders/{id} - Get order
  • GET /api/v1/orders - Search orders
  • GET /api/v1/audit - Get audit trail
  • GET /api/v1/orders/{id}/snapshots - Get snapshots

📖 Learn More: See Multi-Tenant Platform Guide

🏗️ Architecture

Design Patterns Architecture

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

Multi-Tenant Platform Architecture

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

🧪 Testing

Design Patterns Testing

# 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

Multi-Tenant Platform Testing

# 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

📋 SOLID Principles

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

🔧 Enterprise Features

Design Patterns Features

  • ✅ 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

Multi-Tenant Platform Features

  • ✅ OAuth2 + JWT Security
  • ✅ Tenant Isolation Enforcement
  • ✅ Scope-based Authorization
  • ✅ Database Migrations (Flyway)
  • ✅ Audit Trail & Snapshots
  • ✅ Correlation ID Tracking
  • ✅ Production-ready Configuration

📖 Learn More:

📚 Learning Path

For Beginners

  1. Start with README.md (this file) - Project overview
  2. Read Design Patterns Complete Guide - Learn patterns
  3. Explore Design Patterns README - Quick reference
  4. Test patterns using requests/patterns.http

For Intermediate

  1. Study Multi-Tenant Platform Guide - Enterprise architecture
  2. Review I18N Implementation Guide - Internationalization
  3. Test platform using requests/orders.http
  4. Explore the codebase structure

For Advanced

  1. Study Hexagonal Architecture implementation
  2. Review OAuth2 + JWT security setup
  3. Analyze database schema and migrations
  4. Review production considerations

🎓 Key Takeaways

  1. Patterns solve common problems - Don't force patterns where they don't fit
  2. SOLID principles guide design - Patterns help achieve SOLID goals
  3. Architecture matters - Hexagonal architecture provides clean boundaries
  4. Security is critical - OAuth2 + JWT with tenant isolation
  5. Practice makes perfect - Implement patterns in your own projects

📝 Code Quality

  • ✅ Comprehensive JavaDoc documentation
  • ✅ SOLID principles throughout
  • ✅ Professional code structure
  • ✅ Error handling
  • ✅ Unit test coverage
  • ✅ Best practices followed
  • ✅ Production-ready configuration

🧑‍💻 Contributing

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

📚 Documentation Quick Links

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

📄 License

This project is for educational purposes.


Happy Learning! 🚀

For questions or contributions, please refer to the individual documentation files linked above.