Skip to content

Laravel backend application template for building APIs with CycleORM support.

License

Notifications You must be signed in to change notification settings

wayofdev/laravel-cycle-starter-tpl

Repository files navigation





Laravel Starter Template

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

πŸ“„ About

Laravel is a popular PHP web framework known for its simplicity, elegance and the Active Record ORM - Eloquent. Despite its popularity and convenience, Eloquent often comes in the way of projects that require a Domain-Driven Design (DDD) structure. This is due to Eloquent's active record pattern, which in practice can cause the violation of DDD principles, most notably the separation of the business logic from infrastructure code.

Understanding this challenge, we've introduced CycleORM in place of Eloquent in this starter template. CycleORM offers a DataMapper pattern which is a better fit for DDD as it helps to maintain a clear boundary between your business logic and database. This approach ensures that your domain rules and business logic can be modelled according to your needs, and not around the constraints of the active record pattern.

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.

Our goal is to provide a starting point for building Laravel applications using a DDD approach with CycleORM, 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 inherits the following features from its upstream template wayofdev/laravel-starter-tpl:

  • Added:
    • Strict types declaration in all PHP files
    • Style checker package for custom rule-sets to php-cs-fixer β€” wayofdev/php-cs-fixer-config
    • Static analysis tool β€” PHPStan and it's extensions:
    • Pest testing framework
    • Github action workflows for:
      • Continuous integration which includes coding standards checks, unit testing and static analysis
      • Automatic pull-request labeling
      • Deployer for automatic deployments to staging and production servers with support of Github Environments
    • ergebnis/composer-normalize composer plugin for normalizing composer.json file
    • roave/securityadvisories package to ensure that application doesn't have installed dependencies with known security vulnerabilities.
    • Application dockerization using docker-compose and Makefile β€” use make help to view available commands
    • Git pre-commit hooks using pre-commit package
  • Changed:
    • Marked default Laravel classes as final
    • Modified file structure to meet DDD principles
    • 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 it's routes. It can be added back, if it will be required for project
    • Console routes in favor of Command classes.
    • Sanctum migration files

Following the inherited features, this starter template also introduces a set of additional modifications from the upstream template, wayofdev/laravel-starter-tpl:

  • Added:
    • CycleORM support via wayofdev/laravel-cycle-orm-adapter - This introduces the DataMapper pattern, which is more compatible with DDD principles, replacing Laravel's default Eloquent ORM which uses the Active Record pattern.
  • Changed:
    • Deployer script uses custom task to run Cycle ORM migrations instead of Eloquent migrations
  • Removed:
    • Default Laravel Eloquent migrations - As we're using CycleORM, the default Eloquent migrations are no longer necessary and have been removed to prevent conflicts.

🚩 Requirements

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


πŸ’Ώ Installation

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

  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-cycle-starter-tpl repository as starting point.

    $ git clone [email protected]:wayofdev/laravel-cycle-starter-tpl.git
  2. Generate .env file

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

    $ make env \
        APP_NAME=laravel \
        SHARED_SERVICES_NAMESPACE=ss \
        PROJECT_SERVICES_NAMESPACE=wod \
        COMPOSE_PROJECT_NAME=laravel-cycle-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 \
        PROJECT_SERVICES_NAMESPACE=wod \
        COMPOSE_PROJECT_NAME=laravel-cycle-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

🀝 License

Licence


🧱 Credits and Useful Resources

Useful resources about Laravel and DDD approach:


πŸ™†πŸΌβ€β™‚οΈ Author Information

This repository was created in 2022 by lotyp / wayofdev.


πŸ™Œ Want to Contribute?

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

  • πŸ€” Suggest a feature
  • πŸ› Report an issue
  • πŸ“– Improve documentation
  • πŸ‘¨β€πŸ’» Contribute to the code