How thrhamza/commission-fee-calculator works
Project Type and Purpose
• Type: Symfony 6.4 console (CLI) application, no persistent database.
• Purpose: Read transactions from CSV, validate and convert currencies, calculate commission fees, output results to console.
High‐Level Components
a. Entry Point
– bin/console (Symfony Console Kernel → src/Kernel.php)
b. Application Layer (Commands)
– CalculateCommissionCommand (app:calculate-commission)
– TestCsvReaderCommand (app:test:csv-reader)
– TestExchangeRateCommand (app:test:exchange-rate)
c. Service Layer
– CsvReader (parses CSV to Operation entities)
– ExchangeRateService (calls external API)
– CommissionCalculator (orchestrates fee calculation)
– FeeCalculatorInterface implementations:
• DepositCalculator
• BusinessWithdrawCalculator
• PrivateWithdrawCalculator
– WeeklyWithdrawalChecker / Tracker (enforce private client free‐limit)
– FeeRounder (currency–specific rounding)
d. Domain Layer
– Entities: Operation, Money
– Enums: OperationType, UserType
– Validators: OperationValidator (validates dates, amounts, currencies, types)
e. Infrastructure & External Services
– HTTP Client → https://api.exchangerate.host/latest
– File System (reads input CSV, writes to STDOUT)
f. Configuration
– .env / .env.dev / .env.test (EXCHANGE_RATE_API_URL)
– config/packages/*.yaml (cache, validator, routing)
– config/services.yaml (service definitions & autowiring)
Relationships & Data Flow
1. User invokes “bin/console app:calculate‐commission input.csv.”
2. Symfony Console Kernel loads the CalculateCommissionCommand.
3. Command calls CsvReader → emits a list of Operation objects.
4. For each Operation:
a. OperationValidator ensures data integrity.
b. CommissionCalculator delegates to:
– ExchangeRateService (if currency ≠ EUR)
– DepositCalculator or WithdrawCalculator (based on OperationType & UserType)
– WeeklyWithdrawalChecker/Tracker (for private withdrawals)
– FeeRounder to round final amount.
5. Command collects each fee result and writes to STDOUT (console).
Architectural Patterns & Principles
• Layered Architecture: CLI (Presentation) → Commands (Application) → Services & Validators (Domain) → External (Infrastructure).
• Dependency Injection & Autowiring (Symfony Service Container).
• Strategy Pattern: FeeCalculatorInterface with multiple implementations.
• Single Responsibility: each service/validator handles one concern.
• In‐memory tracking (no DB) via Tracker classes for weekly limits.
6. Below or aside, show “WeeklyWithdrawalChecker” and “WeeklyWithdrawalTracker” linked to PrivateWithdrawCalculator.