# reateguidiego/fraud-detector architecture

> Architecture diagram of the GitHub repository reateguidiego/fraud-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/reateguidiego/fraud-detector
- Repository: https://github.com/reateguidiego/fraud-detector

## Overview

##### Project Type and Purpose
- This is a CLI-only application (“Fraud Detector”) built with Symfony 7.4 and PHP 8.2+.
- It follows Clean Architecture (a hexagonal/ports-and-adapters style) to detect suspicious readings from CSV or XML input files.
- The primary use case: load readings, run a fraud‐detection algorithm, and print results to the console.

##### File Structure
- Top-level directories:
- bin/ – Symfony console entrypoint scripts (console, phpunit).
- config/ – Symfony framework, routing, service definitions.
- src/ – core application code, organized into Application, Domain, Infrastructure, UserInterface.
- tests/ – unit tests and fixtures.
- Dockerfile & docker-compose.yml – optional containerized environment.
- src/Application: “Use Case” layer, defines DetectSuspiciousReadingsUseCase.
- src/Domain:
- Model – Reading entity/value object.
- Port – ReadingsLoaderInterface (input port).
- Service – FraudDetector (domain logic).
- src/Infrastructure/Adapter: concrete implementations of ReadingsLoaderInterface for CSV and XML.
- src/UserInterface/Command: DetectFraudCommand (Symfony console command bootstrap).
- Dependency inversion: the UseCase depends on Domain Port, and adapters implement that port in the Infrastructure layer.

##### Insights from README
- Emphasis on Symfony best practices, testability, maintainability.
- Describes a single CLI command `app:detect-fraud` that accepts a filepath.
- Shows project layout matching Clean/Hexagonal Architecture.

##### Main Components
a. UserInterface Layer
- Symfony Console (DetectFraudCommand)
- Input: file path argument (CSV or XML)
- Output: printed fraud results
b. Application Layer
- DetectSuspiciousReadingsUseCase
- Coordinates Domain Port and Domain Service
c. Domain Layer
- Reading model
- ReadingsLoaderInterface (port)
- FraudDetector service (core algorithm)
d. Infrastructure Layer
- CsvReadingsAdapter (implements ReadingsLoaderInterface)
- XmlReadingsAdapter (implements ReadingsLoaderInterface)
e. External Systems
- Input files (CSV, XML)
- Optional Docker container for execution environment

##### Relationships and Data Flow
1. User runs `php bin/console app:detect-fraud <file>`
2. Symfony Console Command instantiates DetectSuspiciousReadingsUseCase via service container
3. UseCase calls ReadingsLoaderInterface → resolved to Csv or Xml adapter
4. Adapter reads external file → returns collection of Reading objects
5. UseCase invokes FraudDetector with readings → returns suspicious subset
6. DetectFraudCommand formats & prints results to STDOUT

##### Architectural Patterns and Principles
- Clean/Hexagonal Architecture: clear separation of layers, dependency inversion (domain ports), pure domain logic.
- Single Responsibility: each adapter handles one format; domain service only contains fraud logic.
- Testable: domain logic is isolated and covered by unit tests (FraudDetectorTest).

##### Technologies, Frameworks, Libraries
- PHP 8.2+, Symfony 7.4 Console Component
- Composer for dependency management
- PHPUnit Bridge for testing
- Docker & Docker Compose (optional container)

##### Essential Elements to Capture
- Components: Command, UseCase, Ports, Adapters, Model, Service
- Interfaces and implementations (port/adapters)
- Data flow from file input to console output
- External file sources and optional Docker container boundary.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Docker Container (optional)"
        subgraph "PHP Application"
            subgraph "UserInterface Layer"
                CLI["bin/console\n(Entry Point)"]:::external
                CMD["DetectFraudCommand"]:::ui
            end
            subgraph "Application Layer"
                UC["DetectSuspiciousReadingsUseCase"]:::app
            end
            subgraph "Domain Layer"
                RL["ReadingsLoaderInterface"]:::domain
                MD["Reading"]:::domain
                FD["FraudDetector"]:::domain
            end
            subgraph "Infrastructure Layer"
                CSV["CsvReadingsAdapter"]:::infra
                XML["XmlReadingsAdapter"]:::infra
            end
        end
    end

    subgraph "External Resources"
        CSVFile["2016-readings.csv"]:::external
        XMLFile["2016-readings.xml"]:::external
        Tests["FraudDetectorTest"]:::external
    end

    CLI -->|"runs command"| CMD
    CMD -->|"execute()"| UC
    UC -->|"calls loadReadings() (port)"| RL
    RL -->|"implements"| CSV
    RL -->|"implements"| XML
    CSVFile -->|"reads file"| CSV
    XMLFile -->|"reads file"| XML
    CSV -->|"returns Reading[]"| UC
    XML -->|"returns Reading[]"| UC
    UC -->|"detect()"| FD
    FD -->|"returns suspicious readings"| UC
    UC -->|"returns results"| CMD
    CMD -->|"prints to console"| CLI

    click CLI "https://github.com/reateguidiego/fraud-detector/tree/main/bin/console"
    click CMD "https://github.com/reateguidiego/fraud-detector/blob/main/src/UserInterface/Command/DetectFraudCommand.php"
    click UC "https://github.com/reateguidiego/fraud-detector/blob/main/src/Application/Service/DetectSuspiciousReadingsUseCase.php"
    click RL "https://github.com/reateguidiego/fraud-detector/blob/main/src/Domain/Port/ReadingsLoaderInterface.php"
    click MD "https://github.com/reateguidiego/fraud-detector/blob/main/src/Domain/Model/Reading.php"
    click FD "https://github.com/reateguidiego/fraud-detector/blob/main/src/Domain/Service/FraudDetector.php"
    click CSV "https://github.com/reateguidiego/fraud-detector/blob/main/src/Infrastructure/Adapter/CsvReadingsAdapter.php"
    click XML "https://github.com/reateguidiego/fraud-detector/blob/main/src/Infrastructure/Adapter/XmlReadingsAdapter.php"
    click Tests "https://github.com/reateguidiego/fraud-detector/blob/main/tests/Domain/Service/FraudDetectorTest.php"
    click CSVFile "https://github.com/reateguidiego/fraud-detector/blob/main/tests/Fixtures/2016-readings.csv"
    click XMLFile "https://github.com/reateguidiego/fraud-detector/blob/main/tests/Fixtures/2016-readings.xml"

    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef app fill:#90EE90,stroke:#333,stroke-width:1px
    classDef domain fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef infra fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
