Quick Start Guide
Get the Hexagonal Demo up and running in 5 minutes.
Table of Contents
- Prerequisites
- Installation
- What You’ll See
- Exploring the Application
- Verifying the Installation
- Common Issues
- Next Steps
- Development Mode
- Production Deployment
- Alternative: Docker Setup
- Getting Help
Prerequisites
Before you begin, ensure you have:
- PHP 8.1 or higher
- Composer (dependency manager)
- Symfony CLI (optional but recommended)
- Database (MySQL, PostgreSQL, or SQLite)
Don’t have Symfony CLI? You can use php -S localhost:8000 -t public instead.
Installation
Step 1: Clone the Repository
git clone https://github.com/ahmed-bhs/hexagonal-demo.git
cd hexagonal-demo
Step 2: Install Dependencies
composer install
This will install:
- Symfony 6.4+
- Doctrine ORM
- Symfony Messenger
- hexagonal-maker-bundle
- All other dependencies
Step 3: Configure Database
Option A: Using SQLite (Simplest)
Edit .env file:
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
Option B: Using MySQL
DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/hexagonal_demo?serverVersion=8.0"
Option C: Using PostgreSQL
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/hexagonal_demo?serverVersion=15&charset=utf8"
For production, use .env.local instead of editing .env directly.
Step 4: Create Database
php bin/console doctrine:database:create
Step 5: Create Schema
php bin/console doctrine:schema:create
This creates the tables for:
habitant(residents)cadeau(gifts)attribution(gift assignments)
Step 6: Load Sample Data
php bin/console doctrine:fixtures:load
Type yes when prompted. This loads:
- 10 residents (children, adults, seniors)
- 10 gifts (various items)
- 7 gift attributions
Step 7: Start the Server
With Symfony CLI:
symfony server:start
Without Symfony CLI:
php -S localhost:8000 -t public
Step 8: Open in Browser
Navigate to: http://localhost:8000
What You’ll See
Home Page (Dashboard)
The home page shows:
- Total Residents: Count of all residents
- Total Gifts: Count of all gifts in catalog
- Attributions Made: Number of gifts assigned
- Age Distribution: Breakdown by category
Navigation
Use the top menu to navigate:
- Home - Dashboard with statistics
- Habitants - List of all residents
- Cadeaux - Catalog of gifts
Exploring the Application
Residents List (/habitants)
Displays all residents with:
- Full name (first name + last name)
- Age with category badge:
- Child (0-17 years) - Blue badge
- Adult (18-64 years) - Green badge
- Senior (65+ years) - Yellow badge
- Email address
- Bootstrap-styled table
Gifts Catalog (/cadeaux)
Shows all gifts with:
- Gift name
- Description
- Stock quantity
- Availability status:
- Available (green) - In stock
- Out of Stock (red) - No stock
Database Content
After loading fixtures, you’ll have:
10 Residents:
- Sophie Martin (8 years old, child)
- Lucas Dubois (45 years old, adult)
- Marie Lefebvre (72 years old, senior)
- Thomas Bernard (12 years old, child)
- Emma Petit (35 years old, adult)
- And 5 more…
10 Gifts:
- Puzzle 3D (10 in stock)
- Livre de recettes (5 in stock)
- Jeu de société (3 in stock)
- And 7 more…
7 Attributions:
- Sophie → Puzzle 3D
- Lucas → Livre de recettes
- And 5 more…
Verifying the Installation
Check the Database
php bin/console doctrine:query:sql "SELECT COUNT(*) as total FROM habitant"
Expected output: total: 10
Check Doctrine Mappings
php bin/console doctrine:mapping:info
You should see:
App\Cadeau\Attribution\Domain\Model\HabitantApp\Cadeau\Attribution\Domain\Model\CadeauApp\Cadeau\Attribution\Domain\Model\Attribution
Run Tests (Optional)
php bin/phpunit
Common Issues
Port Already in Use
If port 8000 is busy:
# Symfony CLI
symfony server:start --port=8080
# PHP built-in server
php -S localhost:8080 -t public
Database Connection Failed
Check your database credentials in .env:
# Verify database is running
# MySQL:
mysql -u db_user -p
# PostgreSQL:
psql -U db_user
Composer Install Fails
Try clearing the cache:
composer clear-cache
composer install
Fixtures Already Loaded
To reload fixtures:
php bin/console doctrine:schema:drop --force
php bin/console doctrine:schema:create
php bin/console doctrine:fixtures:load
Next Steps
Now that you have the app running:
- Explore the Architecture - Understand the hexagonal structure
- Learn the Features - See what’s implemented
- Take the Code Tour - Compare generated vs manual code
- Check the API - Learn about endpoints and CQRS
Development Mode
Enable Debug Toolbar
The Symfony debug toolbar is enabled by default in dev mode. You’ll see it at the bottom of each page with:
- Request/Response info
- Database queries
- Performance metrics
- Messenger messages
Clear Cache
If you make configuration changes:
php bin/console cache:clear
Watch for Changes
For Twig template changes, no cache clear needed. For PHP changes, cache is auto-refreshed in dev mode.
Production Deployment
For production deployment:
- Set environment:
APP_ENV=prod APP_DEBUG=0 - Install production dependencies:
composer install --no-dev --optimize-autoloader - Clear and warm cache:
php bin/console cache:clear --env=prod php bin/console cache:warmup --env=prod -
Create real database (don’t use SQLite in production)
- Run migrations instead of schema:create:
php bin/console doctrine:migrations:migrate --no-interaction
Alternative: Docker Setup
Using Docker Compose
# Start services
docker-compose up -d
# Install dependencies
docker-compose exec php composer install
# Create database
docker-compose exec php php bin/console doctrine:database:create
docker-compose exec php php bin/console doctrine:schema:create
docker-compose exec php php bin/console doctrine:fixtures:load
# Access at http://localhost:8080
Getting Help
If you encounter issues:
- Check the logs:
tail -f var/log/dev.log - Verify requirements:
symfony check:requirements - Ask for help:
You’re all set! The Hexagonal Demo is now running. Explore the code, experiment with features, and learn hexagonal architecture in practice.