# subrata-samanta/langgraph_aml_detection architecture

> Architecture diagram of the GitHub repository subrata-samanta/langgraph_aml_detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/subrata-samanta/langgraph_aml_detection
- Repository: https://github.com/subrata-samanta/langgraph_aml_detection

## Overview

##### Project Type & Purpose
- This is a specialized fraud detection/AML system built using the LangGraph framework. Its goal is to analyze financial transactions using a state-based graph workflow to detect suspicious activities based on multiple risk factors.
- The system orchestrates several “risk assessment nodes” like Document Analysis, Geographic Risk, Behavioral Analysis, Crypto Risk, Sanctions Screening, and PEP Screening.

##### Analyzing the File Structure
- The repository includes a few key files:
- README.md for system overview and setup instructions.
- aml_langgraph.py (with a complementary aml_langgraph.ipynb notebook for experimentation).
- sample_cases.json containing test data.
- requirements.txt listing dependencies (including LangGraph and langchain-groq).
- While the README references an AMLState class in “aml.py”, this likely contains state management and configuration logic for risk parameters.
- The relatively flat file tree (instead of a complex multi-directory structure) suggests that the core system is implemented as a set of modular scripts integrated together, allowing for quick prototyping and deployment.

##### Main Components
a. Core Components:
- Entry/Analysis Module: Represented by aml_langgraph.py, which serves as the entry point for running the analysis.
- State Management: The AMLState class (from aml.py) managing the transaction data, risk thresholds, and aggregation of analysis results.
- Risk Assessment Nodes: Each key node – Document Analysis, Geographic Risk Assessment, Behavioral Analysis, Crypto Risk Analysis, Sanctions Screening, and PEP Screening – should be represented as an individual component. Indicate that these are modular processing nodes connected in a graph workflow.
- Decision Routing: This component manages the transition between nodes based on calculated risk levels and factors. Illustrate smart routing or path selection based on outcomes from each node.
- Data Input: A component representing incoming transaction and customer data (for example, data provided via the sample_cases.json or programmatic calls).
- Output and Reporting: The analysis results, including risk scores, decision paths, alerts, and SAR (Suspicious Activity Report) generation.

b. Relationships Between Components:
- From the Entry Module, the transaction is passed to the State Management component (AMLState) and then into the graph of Risk Assessment Nodes.
- Finally, indicate that data from these nodes is aggregated back into a reporting/output module.

##### Architectural Patterns & Technical Stack
- That the system employs a graph-based workflow—each node acts as a processing unit that both receives input and passes along outcomes.
- Use of state management (AMLState) and decision routing displays modular, loosely-coupled design.
- Mention the integration with external libraries (LangGraph for graph workflow, langchain-groq for language processing) which are essential to the processing mechanisms.
- That a potential configuration module (as mentioned in aml.py) allows risk parameters to be set and tuned, essential for dynamic system behavior.

##### Final Touches
- Every element has a clear title.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration and Documentation
    DocNode["System Overview & Setup (README.md)"]:::doc
    Dep["Dependencies (requirements.txt)"]:::dep

    %% External Libraries
    LangGraph["LangGraph Framework"]:::external
    LangChain["langchain-groq Library"]:::external

    %% Input Component
    DataInput["Data Input (sample_cases.json)"]:::data

    %% Core Entry Point and Experimentation
    Entry["Entry Module (aml_langgraph.py)"]:::core
    ExpNotebook["Experimentation Notebook (aml_langgraph.ipynb)"]:::notebook

    %% State Management
    StateMgmt["State Management (AMLState)"]:::state

    %% Risk Assessment Nodes Cluster
    subgraph "Risk Assessment Engine"
        Document["Document Analysis Node"]:::risk
        Geo["Geographic Risk Assessment Node"]:::risk
        Behavioral["Behavioral Analysis Node"]:::risk
        Crypto["Crypto Risk Analysis Node"]:::risk
        Sanctions["Sanctions Screening Node"]:::risk
        PEP["PEP Screening Node"]:::risk
    end

    %% Decision and Routing
    Decision["Decision Routing"]:::routing

    %% Output and Reporting
    Output["Output & Reporting"]:::output

    %% Data Flow Connections
    DataInput -- "TransactionData" --> Entry
    DocNode -- "Documentation" --> Entry
    Dep -- "Dependencies" --> Entry
    Entry -- "StartsProcessing" --> StateMgmt
    StateMgmt -- "Triggers" --> Document
    StateMgmt -- "Triggers" --> Geo
    StateMgmt -- "Triggers" --> Behavioral
    StateMgmt -- "Triggers" --> Crypto
    StateMgmt -- "Triggers" --> Sanctions
    StateMgmt -- "Triggers" --> PEP
    Document -- "Analysis" --> Decision
    Geo -- "Analysis" --> Decision
    Behavioral -- "Analysis" --> Decision
    Crypto -- "Analysis" --> Decision
    Sanctions -- "Analysis" --> Decision
    PEP -- "Analysis" --> Decision
    Decision -- "Aggregates" --> Output

    %% External Integrations
    Entry -- "Uses" --> LangGraph
    StateMgmt -- "Configures" --> LangChain

    %% Click Events
    click Entry "https://github.com/subrata-samanta/langgraph_aml_detection/blob/main/aml_langgraph.py"
    click ExpNotebook "https://github.com/subrata-samanta/langgraph_aml_detection/blob/main/aml_langgraph.ipynb"
    click DataInput "https://github.com/subrata-samanta/langgraph_aml_detection/blob/main/sample_cases.json"
    click DocNode "https://github.com/subrata-samanta/langgraph_aml_detection/blob/main/README.md"
    click Dep "https://github.com/subrata-samanta/langgraph_aml_detection/blob/main/requirements.txt"

    %% Styles
    classDef core fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef state fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef risk fill:#FFA07A,stroke:#D33,stroke-width:2px;
    classDef routing fill:#90EE90,stroke:#393,stroke-width:2px;
    classDef output fill:#98FB98,stroke:#393,stroke-width:2px;
    classDef data fill:#AFEEEE,stroke:#333,stroke-width:2px;
    classDef external fill:#EEE8AA,stroke:#333,stroke-width:2px;
    classDef doc fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef dep fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef notebook fill:#F5DEB3,stroke:#333,stroke-width:2px;
```
