Skip to content

designbymalina/symfony-api

Repository files navigation

Symfony Store API

This project contains a complete Symfony 7+ backend running in Docker with:

  • PHP 8.3
  • PostgreSQL
  • Nginx
  • MailHog
  • pgAdmin
  • Automatic Composer install
  • Entrypoint with caching and permissions fixes
  • JWT Auth
  • DTO architecture
  • RabbitMQ
  • Redis caching
  • N+1 query optimizations
  • Swagger / OpenAPI documentation

Quick Start

  1. Clone the project:
git clone <repo>
cd symfony
  1. Copy environment file:
cp app/.env.example app/.env
  1. Start Docker environment:
docker-compose up -d --build
  1. Install backend dependencies (if needed):
docker exec -it symfony_app composer install

Services

Service URL
API (Nginx) http://localhost:8080
MailHog http://localhost:8025
pgAdmin http://localhost:8081
Redis localhost:6379
PostgreSQL localhost:5432

File Structure

symfony/
    assets/
    bin/
    config/
    docker/
        php/
            Dockerfile
            php.ini
            entrypoint.sh
        nginx/
            nginx.conf
    public/
    src/
    templates/
    tests/
    .env
    .env.example
    composer.json
    docker-compose.yml
    docker-compose.prod.yml
    README.md

Useful Commands

Enter PHP container

docker exec -it symfony_app bash

Symfony CLI inside container

symfony console cache:clear
symfony console doctrine:migrations:migrate

Restart environment

docker-compose restart

Run tests

docker exec -it symfony_app ./vendor/bin/phpunit

Generating JWT Keys

The project uses the LexikJWTAuthenticationBundle, which requires generating a key pair:

  • private key: config/jwt/private.pem
  • public key: config/jwt/public.pem

The keys are not in the repository; they must be generated locally.

Key Generation Instructions:

Run in the project directory:

mkdir -p config/jwt
php bin/console lexik:jwt:generate-keypair

Default Configuration:

  • algorithm: RSA (RS256)
  • length: 4096 bits
  • key Location: config/jwt/

If you receive errors indicating that OpenSSL is not installed, ensure that the extension is enabled in PHP.

Key Regeneration

If you need to generate new keys:

rm config/jwt/*.pem
php bin/console lexik:jwt:generate-keypair --overwrite

Deployment (Production)

This project supports production-ready deployment using:

  • docker-compose.prod.yml
  • Nginx + PHP-FPM
  • Supervisor (workers)
  • GitHub Actions workflow (optional)

Includes:

  • Build image
  • Push to registry
  • Deploy via SSH or CI runner

Notes on Architecture

  • Uses DTO Request/Response classes for strong typing.
  • All prices stored as string for precision.
  • Redis handles:
    • product caching
    • order caching (optional)
  • N+1 queries fixed with join and optimized repositories.
  • JWT Auth with token TTL and refresh tokens.
  • Centralized API response formatter.
  • Swagger auto-generated with OpenAPI attributes.

Future Extensions

Below are suggested future improvements:

  • API Platform integration layer
  • Webhooks (payment providers)
  • OAuth2 for third‑party integrations
  • AI endpoint (/api/analyze-text)
  • Message queue (RabbitMQ / Kafka)
  • Full test coverage for checkout and payments

Troubleshooting

Composer not installed?

docker exec -it symfony_app composer install

Cache issues?

docker exec -it symfony_app symfony console cache:clear

Reset database

docker-compose down -v

License

MIT

About

Symfony Store API Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published