# lalotor/fraud-detection architecture

> Architecture diagram of the GitHub repository lalotor/fraud-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lalotor/fraud-detection
- Repository: https://github.com/lalotor/fraud-detection

## Overview

##### Project Type and Purpose
- It’s a Java/Spring Boot, multi-module microservices project.
- Purpose: Process financial transactions, detect fraud, and notify clients.
- Uses standard spring-cloud patterns: API Gateway, Eureka Discovery, Config Server, several business microservices, common shared library.

##### Main Components
a. API Gateway
– Entrypoint for clients (REST).
– Routes requests to “transaction”, “fraud-analysis”, “notification” services.
b. Discovery Server (Eureka)
– Service registry.
– All services (API Gateway, business services) register here.
c. Config Server
– Centralized configuration (application-*.properties).
– Other services fetch config at startup.
d. Business Microservices
1. Transaction Service
- Exposes endpoints to initiate transactions.
- Persists to a datastore (implied by repository).
- May synchronously call Fraud-Analysis.
2. Fraud-Analysis Service
- Analyzes transaction risk.
- Caches results (ehcache).
- Publishes or returns analysis.
3. Notification Service
- Sends out fraud notifications (e-mail/SMS/etc.).
- May listen for events or be invoked by others.
e. Common Library
– Shared code: models (Transaction, FraudNotification), integration abstractions, caching, concurrency utilities.
– Included as a Maven dependency in each service.
f. Infrastructure
– Docker Compose: Boots Eureka, Config, and any external dependencies.
– Build & Run scripts: mvnw, run-all.sh

##### Relationships & Data Flow
1. Client → API Gateway
2. API Gateway → Discovery Server
3. API Gateway → Transaction Service
- Load-balanced REST call.
4. Transaction Service → Fraud-Analysis Service
- Either REST or messaging (use integration interface).
5. Fraud-Analysis Service → Notification Service
- Upon high-risk detection → Invoke Notification REST API.
6. Notification Service → Client/External Messaging System
- E-mail or SMS adapter (external service boundary).

##### Architectural Patterns & Principles
- Microservices: each domain area in its own Spring Boot app.
- Service Discovery (Eureka) + API Gateway (Spring Cloud Gateway).
- Central Config (Spring Cloud Config).
- Shared common library to reduce duplication.
- Circuit breaker, caching, and metrics (MetricConfig) are configured per service.
- BDD tests (Cucumber) for service integration.

##### Must-Have Elements
– Clear labels: service names, ports (optional), protocols.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Client (Browser/Consumer)"]:::client

    %% Gateway Layer
    APIGateway["API Gateway"]:::gateway

    %% Infrastructure
    subgraph "Infrastructure"
        Discovery["Discovery Server"]:::infra
        Config["Config Server"]:::infra
        Docker["Docker Compose & Scripts"]:::infra
    end

    %% Common Library
    CommonLib["Common Library"]:::library

    %% Business Services
    subgraph "Business Services"
        TransactionService["Transaction Service"]:::business
        FraudAnalysisService["Fraud-Analysis Service"]:::business
        NotificationService["Notification Service"]:::business
    end

    %% External Systems
    ExternalMessaging["External Messaging (Email/SMS)"]:::external

    %% Data Flows
    Client -->|"HTTPS/REST request"| APIGateway
    APIGateway -->|"Service Discovery"| Discovery
    APIGateway -->|"REST call"| TransactionService
    TransactionService -->|"REST call or Messaging"| FraudAnalysisService
    FraudAnalysisService -->|"REST call on high-risk"| NotificationService
    NotificationService -->|"Sends via"| ExternalMessaging

    %% Service Registration
    APIGateway -->|registers| Discovery
    TransactionService -->|registers| Discovery
    FraudAnalysisService -->|registers| Discovery
    NotificationService -->|registers| Discovery

    %% Config Fetch
    APIGateway -->|fetch config| Config
    TransactionService -->|fetch config| Config
    FraudAnalysisService -->|fetch config| Config
    NotificationService -->|fetch config| Config

    %% Shared Code Dependency
    CommonLib --> APIGateway
    CommonLib --> TransactionService
    CommonLib --> FraudAnalysisService
    CommonLib --> NotificationService

    %% Infrastructure Startup
    Docker --> Discovery
    Docker --> Config

    %% Click Events
    click APIGateway "https://github.com/lalotor/fraud-detection/tree/main/api-gateway/"
    click Discovery "https://github.com/lalotor/fraud-detection/tree/main/discovery-server/"
    click Config "https://github.com/lalotor/fraud-detection/tree/main/config-server/"
    click TransactionService "https://github.com/lalotor/fraud-detection/tree/main/transaction/"
    click FraudAnalysisService "https://github.com/lalotor/fraud-detection/tree/main/fraud-analysis/"
    click NotificationService "https://github.com/lalotor/fraud-detection/tree/main/notification/"
    click CommonLib "https://github.com/lalotor/fraud-detection/tree/main/common/"

    %% Styles
    classDef infra fill:#cfe2ff,stroke:#000;
    classDef gateway fill:#ffcc99,stroke:#000;
    classDef business fill:#ccffcc,stroke:#000;
    classDef library fill:#d9d2e9,stroke:#000;
    classDef client fill:#ffd699,stroke:#000;
    classDef external fill:#ffe5b4,stroke:#000;
```
