How reateguidiego/mytheresa-promotions works
Project Type & Purpose
• Type: A backend REST API microservice built on Symfony 6.4
• Purpose: Expose a single endpoint (GET /products) that returns up to 5 products with calculated promotions, reading from a JSON dataset.
Main Architectural Layers & Components
a. HTTP/API Layer
– public/index.php → Symfony HTTP Kernel initialization
– Routing → resolves /products to ProductController
b. Controller Layer
– src/Controller/ProductController: parses query params, calls application service, returns JSON response
c. Application Layer
– src/Application/ProductService: contains promotion logic, filtering, limiting results
d. Domain Layer
– src/Domain/Product: product DTO (SKU, name, category, price data with original/final/discount)
e. Infrastructure Layer
– src/Infrastructure/Data/ProductDataSourceInterface
• JsonFileProductDataSource: reads data/products.json
• InMemoryProductDataSource: used in tests
f. Configuration & Bootstrapping
– config/*: Symfony bundles, services, routes
– .env, .env.dev, .env.test: environment variables (APP_SECRET)
g. CI/CD & Testing
– .github/workflows/ci.yml: GitHub Actions pipeline
– phpunit.xml.dist & tests/: unit tests (ProductServiceTest), functional tests (ProductControllerTest)
Interactions & Data Flow
1) Client sends HTTP GET /products?category=…&priceLessThan=…
2) public/index.php → Kernel → Router → ProductController
3) ProductController extracts filters, calls ProductService
4) ProductService asks injected ProductDataSourceInterface for raw product list
5) JSON data source reads data/products.json, returns Product DTOs
6) ProductService applies pre‐discount filter → calculates discount (30%, 15%, etc.) → builds final price DTO → enforces 5‐item limit
7) Controller serializes result to JSON response and returns to client
8) CI pipeline runs on each commit: installs dependencies, runs tests
Architectural Patterns & Design Principles
• Clean Architecture / Layered: clear separation between transport (Controller), business logic (Application), domain model (Domain), and data sources (Infrastructure)
• Dependency Injection: Symfony’s service container injects the chosen data source implementation
• Strategy Pattern (future): discount policies could be refactored into interchangeable strategies
• Single Responsibility: each class has a focused purpose (data access, business logic, transport)