How xsga/filmaffinity-api works
Main Components
• API/Web Server Layer:
– Public entry point: The “public/index.php” file that routes incoming HTTP requests.
– Slim framework routing defined in “config/routes/Routes.php”.
– .htaccess configuration (in “public/”) for rewriting URLs.
• Dependency Injection (DI) & Configuration:
– DI container configuration in “config/container/Container.php”.
– Environment configuration files in “config/env/Settings.php” and “config/.env”.
– Global error and logging settings found in “config/errors/” and “config/logger/”.
• Application Modules (Organized in DDD style under “src/Xsga/FilmAffinityApi/Modules”):
– Films Module – Contains application services, domain models, repositories, controllers, mappers, parsers, and console commands.
– Errors Module – Handles API error responses and related domain exceptions.
– Users Module – Manages user authentication, user creation, token generation, and security aspects.
– Shared Module – Provides common functionalities such as JWT handling, HTTP Client wrappers, JSON utilities, persistence and security utilities.
• Logging Subsystem:
– Custom logging provided under “src/Log4Php” that includes appenders, filters, layouts, and configuration adapters.
• Database & Persistence:
– The project uses MySQL (database scripts located in “scripts/”) along with Doctrine entities (e.g., “src/Xsga/FilmAffinityApi/Modules/Shared/Persistence/Infrastructure/Doctrine/UsersEntity.php”).
• CLI (Console Commands):
– Executable via “bin/console” (and related console classes under the modules) for tasks such as user creation/deletion, token generation, and backup operations.
• Containerization and DevOps:
– Docker support via “Dockerfile” and the “docker-compose.yml” file.
– Continuous integration configurations in “.circleci/” and “.github/workflows/”.
Component Relationships and Interactions
• External clients (or users) send HTTP requests to the RESTful API endpoints.
• The web server (via public/index.php) channels these requests to the Slim framework’s routing defined in “config/routes/Routes.php”.
• Controllers (under each module’s Infrastructure/Controllers) receive requests and then delegate tasks to application services.
• The services perform business logic by invoking domain models and coordinating with repositories (data access operations and third-party integrations).
• The DI container (configured in “config/container/Container.php”) wires all dependencies together.
• The API returns responses through the controllers, with error handling, logging (using Log4Php) and JSON serialization.
• Additionally, backend processes (via CLI commands) enable administrative tasks such as user management and data backup.
• Docker and CI/CD components encapsulate and manage environments.
Architectural Patterns and Design Principles
• Layered Architecture / Domain-Driven Design (DDD): Separation among Application, Domain, and Infrastructure layers.
• Dependency Injection: Using the container for loose coupling.
• Modularity: Each core feature (Films, Errors, Users, Shared) is encapsulated in its own module.
• Logging Abstraction: A dedicated Log4Php sub-system allows flexible logging strategies.
• RESTful API design: Clear endpoints, HTTP methods, and JSON schema-based input validation (with schemas defined under “config/schemas”).
• Containerization: Docker integration ensuring a consistent deployment environment.
Relevant Technologies, Frameworks, and Libraries
• PHP 8.3+ and Slim Framework 4.
• Composer for dependency management.
• Doctrine ORM for database interactions.
• Log4Php for logging.
• Guzzle (or similar) HTTP Client support in the Shared module.
• JWT (FirebaseJwtService for secure token handling).