/laravel-starter-tpl

🚀 Pre-configured Laravel Project Template. Includes PHPUnit, Pest PHP, PHPStan, Larastan, PHP CS Fixer, and CI tools. Supports OpenAPI, DDD, Deptrac, Deployer, PHP 8.3, Docker, local SSL, and DNS. Enhance development with advanced features and maintain high code quality.

Primary LanguagePHPMIT LicenseMIT


WayOfDev Logo

Build
Build Status Deploy to Staging Status Deploy to Production Status

Project
Latest Stable Version Commits since latest release PHP Version Require

Quality
Codecov Mutation testing badge PHP Stan Level 8 of 9

Community
Discord Follow on Twitter (X)


Laravel Starter Template

This is an opinionated modified version of the Laravel framework which aims at providing a Domain-Driven Design (DDD) structure.

📄 About

Laravel is a popular PHP web framework that provides an easy and efficient way to build web applications. However, the default structure of Laravel, coupled with Eloquent's active record pattern, may not always fit the needs of a project that requires a Domain-Driven Design (DDD) architecture. Eloquent's active record pattern breaks DDD principles and make it difficult to separate your business logic from your infrastructure code.

This repository provides a modified file structure for Laravel that follows DDD principles and tries to adhere to best practices, such as those outlined in Spatie's Laravel Beyond CRUD. The goal is to provide a starting point for building Laravel applications using a DDD approach, while still leveraging the power and convenience of the Laravel framework.


🙏 If you find this repository useful, consider giving it a ⭐️. Thank you!


🚀 Features

This starter template includes several added, changed, and removed features:

→ Framework Modifications

  • Added:

    • Strict types declaration in all PHP files
    • Application dockerization using docker-compose and Makefile — use make help to view available commands
    • spatie/laravel-route-attributes package for route definition using PHP8 style attributes
  • Changed:

    • Marked default Laravel classes as final
    • Modified file structure to meet DDD principles (as close as possible)
    • Changed config folder files to use default PHP multi-line comment style
  • Removed:

    • Dependencies like Laravel Sanctum, Laravel Pint, and Laravel Sail
    • Broadcasting service provider and its routes. It can be added back if required for the project
    • Console routes in favor of Command classes
    • Sanctum migration files

→ Development Tools

  • Added:
    • Style checker package for custom rule-sets to php-cs-fixer — wayofdev/php-cs-fixer-config
    • Phive support for managing PHP tools
    • Application dockerization using docker-compose and Makefile — use make help to view available commands
      • docker-php-dev as PHP development environment with XDebug support out of the box

→ Testing

→ Static Analysis

→ Continuous Integration

  • Added:
    • GitHub action workflows for:
      • Continuous integration which includes coding standards checks, unit testing and static analysis
      • Automatic pull-request labeling
    • Git pre-commit hooks using pre-commit package

→ Deployments


🚩 Requirements

To use this repository, you need to meet the following requirements:


💿 Installation

Note

You should configure, set up, and run the docker-shared-services repository to ensure system-wide TLS and DNS support.

→ Docker Shared Services

Check full instructions in docker-shared-services repository.

  1. Create shared project directory:

    mkdir -p ~/projects/infra && cd ~/projects/infra
  2. Clone docker-shared-services repository:

    git clone \
    git@github.com:wayofdev/docker-shared-services.git \
    ~/projects/infra/docker-shared-services && \
    cd ~/projects/infra/docker-shared-services
  3. Create .env file:

    make env
  4. Install root certificate and generate default project certs:

    make cert-install
  5. Run shared services:

    make up

→ Laravel Starter Template

  1. Clone repository:

    After forking or creating generating repository from template, you can clone it to your local machine. In this example we will use laravel-starter-tpl repository as starting point.

    git clone \
      git@github.com:wayofdev/laravel-starter-tpl.git \
      ~/projects/laravel-starter-tpl && \
    cd ~/projects/laravel-starter-tpl
  2. Generate .env file

    Generate .env file from .env.example file using Makefile command:

    $ make env \
        APP_NAME=laravel \
        SHARED_SERVICES_NAMESPACE=ss \
        COMPOSE_PROJECT_NAME=laravel-starter-tpl

    Change generated .env file to match your needs, if needed.

    (Optional): to re-generate .env file, add FORCE=true to the end of command:

    $ make env \
        APP_NAME=laravel \
        SHARED_SERVICES_NAMESPACE=ss \
        COMPOSE_PROJECT_NAME=laravel-starter-tpl \
        FORCE=true
  3. Build, install and run. This will also generate Laravel app key:

    $ make
    
    # or run commands separately
    $ make hooks
    $ make install
    $ make key
    $ make prepare
    $ make up
  4. Open your browser and navigate to https://laravel-starter-tpl.docker to see Laravel welcome page.


🧰 Project Architecture

The project architecture of wayofdev/laravel-starter-tpl follows a structured approach with distinct layers:

  • Domain: Contains core business logic and entities.
  • Bridge: Connects the domain layer with external systems or services.
  • Infrastructure: Handles interactions with external systems, such as databases, APIs, or file systems.
  • Support: Provides general-purpose helper classes that assist various parts of the application.
  • DatabaseSeeders: Handles database seeding logic.
  • DatabaseFactories: Manages database factory definitions.
  • Tests: Contains test cases for various layers of the application.

Each layer has defined dependencies, ensuring a clear separation of concerns and facilitating maintainability and scalability.

For more information check deptrac.yaml located in repository app folder.

→ Architecture Diagram

Architecture Diagram


🤖 Deployment to Staging and Production

This repository utilizes GitHub Actions for continuous deployment to both staging and production servers. Below is a description.

→ Deployment Flow

Deployment to Staging

  1. Push to develop branch: Initiates the deployment process to the staging server. Merge PR against develop branch, to trigger deploy-staging.yml
  2. GitHub Actions: Executes the deploy-staging.yml workflow.
  3. Staging Server: Receives deployment instructions and acknowledges the deployment.

Deployment to Production

  1. Merge of develop branch into master: Triggers the deployment process to the production server on push event.
  2. GitHub Actions: Runs the create-release.yml workflow.
  3. Release Event: deploy-release.yml waits for the event release: released.
  4. GitHub Actions: Initiates the deploy-release.yml workflow.
  5. Production Server: Receives deployment instructions and acknowledges the deployment.

Conditional Deployment Status

  • Deployment Successful: Both staging and production servers send a success message back to GitHub Actions. Additionally, a success message is sent to the Slack server.

  • Deployment Failed: If an error occurs, a failure message is sent back to GitHub Actions. Additionally, a failure message is sent to the Slack server.

Diagram

deployments


🧱 Credits and Useful Resources

Useful resources about Laravel and DDD approach:


🔒 Security Policy

This project has a security policy.


🙌 Want to Contribute?

Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:

You are more than welcome. Before contributing, kindly check our contribution guidelines.

Conventional Commits


🫡 Contributors

Contributors Badge

🌐 Social Links


⚖️ License

Licence