Skip to content

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Refactor your legacy code using SOLID principles

Tests PHP Laravel License

This is a Laravel application used for demo purposes — a pseudo application that illustrates how SOLID principles can be applied in a PHP/Laravel codebase.

Prerequisites

Recommended (Docker):

No local PHP or Composer installation is required when using Docker.

Application stack:

Component Version
PHP 8.4
Laravel 13.x
MySQL 8.4

PHP extensions (included in the Docker image; required if running without Docker):

  • pdo_mysql, mbstring, openssl, tokenizer, xml, ctype, json, bcmath, gd, zip

Installation

  1. Clone the repository:

    git clone git@github.com:SumonMSelim/solid-principles-example-laravel.git
    cd solid-principles-example-laravel
  2. Create your environment file:

    cp .env.example .env
  3. Configure Docker database settings in .env (defaults match docker-compose.yml):

    APP_URL=http://localhost:8081
    
    DB_CONNECTION=mysql
    DB_HOST=mysql
    DB_PORT=3306
    DB_DATABASE=solid
    DB_USERNAME=solid
    DB_PASSWORD=secret
  4. Build and start the containers:

    docker compose up --build -d
  5. Run database migrations:

    docker compose exec app php artisan migrate
  6. (Optional) Verify the installation:

    docker compose exec app php artisan test

Running the application

Start all services:

docker compose up -d

Stop services:

docker compose down

View logs:

docker compose logs -f app

Open the app at http://localhost:8081.

Health check: http://localhost:8081/up

Testing

Run the full test suite locally:

docker compose exec app php artisan test

Continuous integration runs on every pull request and push to main via GitHub Actions.

Docker services

Service URL / Port
App (nginx) http://localhost:8081
MySQL localhost:3307

Default database credentials (override in .env):

  • Database: solid
  • Username: solid
  • Password: secret

Example requests

Register a user via the API:

curl -X POST http://localhost:8081/api/users/create \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"first_name":"Jane","last_name":"Doe","email":"jane@example.com","password":"secret123"}'

Check payment status:

curl http://localhost:8081/status

Routes

Method Path Description
GET / Welcome page
POST /register Register a user (web)
POST /users/create Create a user (admin)
GET /users/index List users from yesterday (admin)
POST /pay Process a payment (user)
GET /status Payment status (user)
POST /api/register Register a user (API)
POST /api/users/create Create a user (API)

SOLID map

Principle Examples in this codebase
SRP PaymentOrchestrator, NotificationService, CreateUserRequest
OCP Payment gateways registered in config/payments.php; resolved via PaymentGatewayResolver
LSP All payment classes implement PayableInterface; status services implement PaymentStatusInterface
ISP Focused contracts: PayableInterface, NotifiableInterface, PaymentStatusInterface
DIP Controllers depend on interfaces; bindings in AppServiceProvider

Resources

About

Source code for Live session: "Refactor your legacy code using SOLID principles". Organized by Facebook Developer Circle Berlin.

Resources

Stars

32 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages