# thrhamza/commission-fee-calculator architecture

> Architecture diagram of the GitHub repository thrhamza/commission-fee-calculator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thrhamza/commission-fee-calculator
- Repository: https://github.com/thrhamza/commission-fee-calculator

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry and Kernel
    InputCSV["📄 Input CSV"]:::external
    Entry["bin/console"]:::cli
    Kernel["Symfony Kernel"]:::cli
    Output["🖥️ Console Output"]:::external

    %% Commands
    subgraph "Commands"
        CC["CalculateCommissionCommand"]:::cli
        TCsv["TestCsvReaderCommand"]:::cli
        TEx["TestExchangeRateCommand"]:::cli
    end

    %% Services and Domain
    subgraph "Services & Domain"
        CsvR["CsvReader Service"]:::service
        Validator["OperationValidator"]:::validator
        CommCalc["CommissionCalculator"]:::service
        FeeRounder["FeeRounder"]:::service
        IFace["FeeCalculatorInterface"]:::service
        subgraph "Calculators"
            DepCalc["DepositCalculator"]:::service
            BusWCalc["BusinessWithdrawCalculator"]:::service
            PrivWCalc["PrivateWithdrawCalculator"]:::service
        end
        subgraph "Weekly Checker"
            Checker["WeeklyWithdrawalChecker"]:::service
            Tracker["WeeklyWithdrawalTracker"]:::service
        end
        Operation["Operation Entity"]:::domain
        Money["Money Entity"]:::domain
        OperationType["OperationType Enum"]:::domain
        UserType["UserType Enum"]:::domain
    end

    %% External Services & Config
    ERS["ExchangeRateService\n(external API)"]:::external
    subgraph "Configuration"
        Env[".env/.env.dev/.env.test"]:::infra
        ServicesYAML["services.yaml"]:::infra
        FrameworkYAML["framework.yaml"]:::infra
        ValidatorYAML["validator.yaml"]:::infra
        RoutesYAML["routes.yaml"]:::infra
        RoutesFWYAML["framework.yaml"]:::infra
    end

    %% Flow
    InputCSV --> CsvR
    Entry --> Kernel
    Entry --> CC
    Entry --> TCsv
    Entry --> TEx

    CC --> CsvR
    CC --> Validator
    CC --> CommCalc
    CC --> Output

    TCsv --> CsvR
    TEx --> ERS

    CsvR --> Validator
    Validator --> CommCalc

    CommCalc --> DepCalc
    CommCalc --> BusWCalc
    CommCalc --> PrivWCalc
    DepCalc --> IFace
    BusWCalc --> IFace
    PrivWCalc --> IFace

    PrivWCalc --> Checker
    PrivWCalc --> Tracker

    CommCalc --> ERS
    CommCalc --> FeeRounder
    FeeRounder --> CommCalc

    %% Click Events
    click Entry "https://github.com/thrhamza/commission-fee-calculator/tree/main/bin/console"
    click Kernel "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Kernel.php"
    click CC "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Command/CalculateCommissionCommand.php"
    click TCsv "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Command/TestCsvReaderCommand.php"
    click TEx "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Command/TestExchangeRateCommand.php"
    click CsvR "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/CsvReader.php"
    click ERS "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/ExchangeRateService.php"
    click CommCalc "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/CommissionCalculator.php"
    click IFace "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/Calculator/FeeCalculatorInterface.php"
    click DepCalc "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/Calculator/DepositCalculator.php"
    click BusWCalc "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/Calculator/BusinessWithdrawCalculator.php"
    click PrivWCalc "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/Calculator/PrivateWithdrawCalculator.php"
    click Checker "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/Checker/WeeklyWithdrawalChecker.php"
    click Tracker "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/Tracker/WeeklyWithdrawalTracker.php"
    click FeeRounder "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Service/FeeRounder.php"
    click Operation "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Entity/Operation.php"
    click Money "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Entity/Money.php"
    click OperationType "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Enum/OperationType.php"
    click UserType "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Enum/UserType.php"
    click Validator "https://github.com/thrhamza/commission-fee-calculator/blob/main/src/Validator/OperationValidator.php"
    click Env "https://github.com/thrhamza/commission-fee-calculator/blob/main/.env"
    click ServicesYAML "https://github.com/thrhamza/commission-fee-calculator/blob/main/config/services.yaml"
    click FrameworkYAML "https://github.com/thrhamza/commission-fee-calculator/blob/main/config/packages/framework.yaml"
    click ValidatorYAML "https://github.com/thrhamza/commission-fee-calculator/blob/main/config/packages/validator.yaml"
    click RoutesYAML "https://github.com/thrhamza/commission-fee-calculator/blob/main/config/routes.yaml"
    click RoutesFWYAML "https://github.com/thrhamza/commission-fee-calculator/blob/main/config/routes/framework.yaml"

    %% Styles
    classDef cli fill:#bbdefb,stroke:#1e88e5,color:#0d47a1;
    classDef service fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20;
    classDef domain fill:#eeeeee,stroke:#9e9e9e,color:#424242;
    classDef validator fill:#f5f5f5,stroke:#bdbdbd,color:#616161;
    classDef infra fill:#ffe0b2,stroke:#ef6c00,color:#e65100;
    classDef external fill:#ffe0b2,stroke:#ef6c00,color:#e65100;
```
