Skip to content

dafalagi/laravel-soa-starter

Repository files navigation

πŸ—οΈ Laravel SOA Starter

Laravel Version PHP Version Architecture License

A Service-Oriented Architecture (SOA) starter template built on Laravel 12, featuring a modular monolith design pattern with comprehensive service layer architecture, automated factory discovery, and enterprise-grade patterns.

🎯 Project Vision

This starter template provides a solid foundation for building scalable, maintainable Laravel applications using SOA principles and modular architecture. It emphasizes clean separation of concerns, testability, and developer productivity through intelligent code generation and consistent patterns.

✨ Key Features

πŸ›οΈ Modular Architecture

  • Modular Monolith Design - Self-contained modules with clear boundaries
  • Service-Oriented Architecture - Business logic encapsulated in dedicated services
  • Module Generator - php artisan make:module command for rapid development
  • Automatic Module Discovery - Routes, migrations, and services auto-registered

πŸ”§ Advanced Service Layer

  • BaseService Pattern - Consistent transaction handling and error management
  • Single Responsibility Services - Each service handles one specific action
  • Comprehensive Validation - Request validation moved to service layer
  • Standardized Response Format - Uniform API responses across all endpoints

πŸ§ͺ Testing & Quality

  • Modular Test Structure - Tests organized per module
  • Comprehensive Test Coverage - Unit and feature tests included
  • Factory Discovery System - Automatic model factory resolution

πŸ—„οΈ Database Architecture

  • Module-Specific Databases - Each module manages its own migrations, factories, seeders
  • Automatic Factory Discovery - HasModularFactory trait eliminates boilerplate
  • Migration Organization - Clear separation of database concerns per module

🎨 Developer Experience

  • Intelligent Code Generation - Consistent patterns across generated code
  • Rich Documentation - Comprehensive guides and architectural documentation
  • Naming Conventions Consistency - All generated code follows snake_case conventions for variables and camelCase conventions for methods (except tests)
  • Clean Architecture - Clear separation between controllers, services, and models

πŸ“ Project Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ Console/Commands/
β”‚   β”‚   └── MakeModuleCommand.php          # Module generator command
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   └── BaseService.php                # Base service with common functionality
β”‚   β”œβ”€β”€ Http/Traits/
β”‚   β”‚   └── ApiResponse.php                # Standardized API responses
β”‚   └── Traits/
β”‚       └── HasModularFactory.php          # Automatic factory discovery
β”œβ”€β”€ modules/
β”‚   └── Auth/                              # Example Auth module
β”‚       β”œβ”€β”€ DTOs/                          # Data Transfer Objects
β”‚       β”œβ”€β”€ Http/Controllers/              # HTTP layer
β”‚       β”œβ”€β”€ Services/                      # Business logic layer
β”‚       β”‚   β”œβ”€β”€ Auth/                      # Authentication services
β”‚       β”‚   └── User/                      # User management services
β”‚       β”œβ”€β”€ Models/                        # Eloquent models
β”‚       β”œβ”€β”€ Database/                      # Module-specific database files
β”‚       β”‚   β”œβ”€β”€ Migrations/
β”‚       β”‚   β”œβ”€β”€ Factories/
β”‚       β”‚   └── Seeders/
β”‚       └── Tests/                         # Module tests
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ MODULAR_DATABASE.md              # Database architecture guide
β”‚   └── REFACTORED_SERVICES.md           # Service architecture documentation
└── README.md

πŸš€ Getting Started

Prerequisites

  • PHP 8.3+
  • Laravel 12.x
  • PostgreSQL (preferably)/MySQL/SQLite

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/laravel-soa-starter.git
    cd laravel-soa-starter
  2. Install dependencies

    composer install
  3. Environment setup

    cp .env.example .env
    php artisan key:generate
  4. Database setup

    php artisan migrate
    php artisan db:seed
  5. Run the application

    php artisan serve

Creating Your First Module

Generate a new module with all necessary files:

php artisan make:module Product

This creates a complete module structure with:

  • Controllers with CRUD operations
  • Service layer with validation
  • DTOs for data transfer
  • Models with factory discovery
  • Database migrations, factories, seeders
  • Feature and unit tests
  • API routes

πŸ—οΈ Architecture Patterns

Service Layer Architecture

// Each service extends BaseService for consistency
class CreateProductService extends BaseService
{
    protected function rules(): array
    {
        return [
            'name' => 'required|string|max:255',
            'price' => 'required|numeric|min:0',
        ];
    }
    
    protected function process(mixed $dto): void
    {
        // Business logic here
        $product = Product::create($dto);
        $this->results['data'] = ProductResponseDTO::fromModel($product);
    }
}

Modular Factory Discovery

// Models automatically discover their factories
class Product extends Model
{
    use HasModularFactory; // Automatically finds Modules\Product\Database\Factories\ProductFactory
}

Standardized API Responses

// Controllers use consistent response formatting
public function store(Request $request): JsonResponse
{
    $dto = CreateProductRequestDTO::fromArray($request->all());
    $response = $this->create_product_service->execute($dto);
    
    return $this->response($response); // Auto-handles success/error based on status code
}

πŸ“Š Current Status

  • βœ… Core Architecture - Modular SOA foundation complete
  • βœ… Auth Module - Complete authentication system with JWT
  • βœ… Service Layer - BaseService pattern with comprehensive error handling
  • βœ… Module Generator - Automated code generation for new modules
  • βœ… Factory Discovery - Automatic model factory resolution
  • βœ… Testing Framework - Modular test structure with comprehensive coverage

πŸ—ΊοΈ Roadmap & Future Plans

Phase 1: Core Enhancements

  • API Rate Limiting - Comprehensive rate limiting per module/endpoint
  • Caching Layer - Redis-based caching with cache tags per module
  • Event System - Module-to-module communication via events
  • Permission System - Role-based access control (RBAC)

Phase 2: Advanced Features

  • API Versioning - Support for multiple API versions
  • Queue System - Background job processing per module
  • File Management - File upload/storage service with cloud support
  • Notification System - Multi-channel notifications (email, SMS, push)

Phase 3: DevOps & Monitoring

  • Docker Support - Complete containerization setup
  • CI/CD Pipeline - GitHub Actions for automated testing and deployment
  • Monitoring & Logging - Comprehensive application monitoring
  • Performance Optimization - Database query optimization and caching strategies

Phase 4: Enterprise Features

  • Multi-tenancy - SaaS-ready tenant isolation
  • Microservice Migration Path - Tools to split modules into microservices
  • API Gateway - Centralized API management and routing
  • Distributed Tracing - Request tracing across modules

🀝 Contributing

We welcome contributions! Please see our contributing guidelines for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ§ͺ Testing

Run the test suite:

# Run all tests
vendor/bin/phpunit

# Run specific module tests
vendor/bin/phpunit modules/Auth/Tests/

# Run with coverage
vendor/bin/phpunit --coverage-html coverage/

πŸ“š Documentation

πŸ™ Acknowledgments

Special thanks to the following developers for their inspiration, suggestions, and contributions to this project:

  • @lazuardy347 - For architectural insights and design pattern suggestions
  • @praneshaw - For modular design pattern inspiration and feedback
  • @dimasaprasetyo - For helpful libraries, packages, and tools recommendations.

Their expertise and guidance have been invaluable in shaping this project's architecture and implementation.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ’‘ Support


Built with ❀️ using Laravel and modern PHP practices

Releases

No releases published

Packages

No packages published

Languages