Skip to content

philipphermes/symfony-layered-architecture-template

Repository files navigation

Symfony Layered Architecture Template

A modern Symfony template using a layered architecture pattern with FrankenPHP for high-performance PHP applications. Features a flexible Docker setup optimized for development and production.

CI PHP Symfony codecov

Features

  • 🚀 FrankenPHP - Modern PHP application server with built-in Caddy
  • 🐳 Multi-stage Docker - Optimized dev/prod configurations
  • 🔧 Flexible PHP Extensions - Configure via environment variables
  • 🐛 Xdebug Ready - Pre-configured for development debugging
  • 🗄️ PostgreSQL - Production-ready with health checks
  • 📦 Live Reload - Automatic file watching in development
  • 🔒 Production Optimized - OPcache, JIT

Requirements

  • Docker Desktop (Mac/Windows) or Docker Engine (Linux)
  • Docker Compose v2+

Quick Start

Setup

# Create .env
cp .env.dist .env

# Initialize project
docker/console boot docker-compose.yml #(or docker-compose.test.yml or docker-compose.prod.yml)

# Start project and install dependencies
docker/console install

# Access shell
docker/console cli

Services & Ports

Development:

Production:

  • Application: http://localhost:80 / https://localhost:443
  • PostgreSQL: Internal network only

Available Docker Commands

docker/console boot {file} # Initialize project
docker/console up          # Start project
docker/console start       # Start project
docker/console stop        # Stop project
docker/console down        # Removes containers and volumes
docker/console cli         # Access shell
docker/console install     # Start project, install dependencies and run migrations
docker/console reset       # Reset project (down & install)

Debugging with Xdebug

Xdebug is pre-configured in development mode:

  1. PHPStorm/IntelliJ:

    • Go to Settings → PHP → Servers
    • Add server: Name: app, Host: localhost, Port: 8080
    • Enable path mappings: /path/to/your/project/app
    • Start listening for debug connections
  2. VS Code:

    • Install PHP Debug extension
    • Add to .vscode/launch.json:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/app": "${workspaceFolder}"
      }
    }
  ]
}

Project Structure

├── config/
├── docker/
│   └── frankenphp/
│       ├── Dockerfile
│       ├── Caddyfile
│       ├── Caddyfile.prod
│       ├── xdebug.ini
│       ├── opcache.ini
│       └── opcache.prod.ini
├── public/
├── src/
│   ├── Backend/
│   │   └── {Module}
│   │       ├── Business/           # Facades and Business logic
│   │       ├── Communication/      # Controllers and commands
│   │       ├── Persistence/        # Entities, repositories & entity managers
│   │       └── Presentation/       # Templates and js
│   ├── Frontend/
│   │   └── {Module}
│   │       ├── Controller/         # Controllers
│   │       └── Theme/              # Templates and js
│   ├── Client/
│   │   └── {Module}
│   ├── Service/
│   │   └── {Module}
│   ├── Shared/
│   │   └── {Module}
│   │       ├── Transfers/
│   │       └── ...
│   └── Generated/                  # Migrations, Generated Transfers, ...
├── tests/
├── docker-compose.yml
├── docker-compose.prod.yml
├── docker-compose.test.yml
└── .gitattributes

Testing

vendor/bin/phpunit

# With coverage
XDEBUG_MODE=coverage,debug vendor/bin/phpunit --coverage-html coverage

Sniffers

#Deptrac
vendor/bin/deptrac

#Phpstan
vendor/bin/phpstan analyse --memory-limit=1G

Generate Transfers

symfony console transfer:generate

Migrations:

Create migration files:

php bin/console doctrine:migrations:diff

Run migration files:

php bin/console doctrine:migrations:migrate

Run migration for testing purposes:

migrations:execute --up "DoctrineMigrations\\{version}"

Revert the migration:

migrations:execute --down "DoctrineMigrations\\{version}"

About

Template for a Symfony project using a layered architecture.

Topics

Resources

License

Stars

Watchers

Forks