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.
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.
- Modular Monolith Design - Self-contained modules with clear boundaries
- Service-Oriented Architecture - Business logic encapsulated in dedicated services
- Module Generator -
php artisan make:modulecommand for rapid development - Automatic Module Discovery - Routes, migrations, and services auto-registered
- 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
- Modular Test Structure - Tests organized per module
- Comprehensive Test Coverage - Unit and feature tests included
- Factory Discovery System - Automatic model factory resolution
- Module-Specific Databases - Each module manages its own migrations, factories, seeders
- Automatic Factory Discovery -
HasModularFactorytrait eliminates boilerplate - Migration Organization - Clear separation of database concerns per module
- 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
βββ 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
- PHP 8.3+
- Laravel 12.x
- PostgreSQL (preferably)/MySQL/SQLite
-
Clone the repository
git clone https://github.com/yourusername/laravel-soa-starter.git cd laravel-soa-starter -
Install dependencies
composer install
-
Environment setup
cp .env.example .env php artisan key:generate
-
Database setup
php artisan migrate php artisan db:seed
-
Run the application
php artisan serve
Generate a new module with all necessary files:
php artisan make:module ProductThis 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
// 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);
}
}// Models automatically discover their factories
class Product extends Model
{
use HasModularFactory; // Automatically finds Modules\Product\Database\Factories\ProductFactory
}// 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
}- β 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
- 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)
- 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)
- 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
- 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
We welcome contributions! Please see our contributing guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
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/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.
This project is licensed under the MIT License - see the LICENSE file for details.
- π§ Email: dafarizky34@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
Built with β€οΈ using Laravel and modern PHP practices