How reateguidiego/fraud-detector works
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.