# arpitshourya/creditcardfrauddetection architecture

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

- Interactive diagram: https://gitdiagram.com/arpitshourya/creditcardfrauddetection
- Repository: https://github.com/arpitshourya/creditcardfrauddetection

## Overview

##### Project type and purpose
- This is an end-to-end credit‐card fraud detection system combining both streaming and batch ML pipelines plus an online inference API.
- Key features:
- Data ingestion from external sources into Kafka
- Real‐time scoring via Faust stream processor
- Batch training and batch prediction pipelines
- Model artifact storage and sync with AWS S3
- Online inference exposed via FastAPI
- Persistence of results (e.g., MongoDB)

##### File structure
- Top‐level service & orchestration:
- docker-compose.yml
- Dockerfile-fastapi (for API service)
- Dockerfile-faust (for stream processor)
- Streaming components (FraudDetection/components):
- kafka_producer.py / extract_push_data.py → produces transactions to Kafka
- faust_app.py / kafka_consumer.py → stream processing and real‐time inference
- kafka_producer / consumer wrappers
- Batch pipelines (FraudDetection/pipeline):
- training_pipeline.py → data ingestion → transformation → model training → artifact creation
- batch_prediction_pipeline.py → batch scoring on new data
- Model artifacts & schema:
- final_models/*.pkl
- data_schema/schema.yaml
- cloud/s3_sync.py → sync artifacts to/from AWS S3
- API layer:
- app.py / main.py → FastAPI server that loads model & preprocessing objects and serves /predict endpoints
- ping_mongo.py → health check for MongoDB
- Utilities:
- FraudDetection/utils (generic helpers, ML metrics, estimators)
- Cross‐cutting concerns:
- FraudDetection/logging/logger.py
- FraudDetection/exception

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Source
    ExternalSource["External Transaction Feed"]:::ext

    %% Fraud Detection Stack
    subgraph "Fraud Detection Stack"
        direction TB
        subgraph "Streaming Services"
            direction TB
            KafkaProducer["Kafka Producer"]:::compute
            FaustService["Faust Stream Processor"]:::compute
        end
        subgraph "API Service"
            direction TB
            FastAPI["FastAPI Inference API"]:::compute
            HealthCheck["MongoDB Health Check"]:::util
        end
    end

    %% Batch Pipelines
    subgraph "Batch Pipelines"
        direction TB
        BatchTrain["Batch Training Pipeline"]:::compute
        BatchPredict["Batch Prediction Pipeline"]:::compute
    end

    %% Data Stores & Artifacts
    KafkaCluster((Kafka Cluster)):::datastore
    MongoDB[(MongoDB)]:::datastore
    S3[(AWS S3)]:::datastore
    Schema["Data Schema (schema.yaml)"]:::datastore
    Artifacts["Model Artifacts"]:::datastore

    %% Utilities
    Logger["Logging Framework"]:::util

    %% Clients
    Client["Client (Web/Mobile)"]:::ext

    %% Data Flows
    ExternalSource -->|push raw data| KafkaProducer
    KafkaProducer -->|produce| KafkaCluster
    KafkaCluster -->|consume raw topic| FaustService
    FaustService -->|real-time scoring| MongoDB

    BatchTrain -->|train model| Artifacts
    Artifacts -->|sync artifacts| S3
    BatchPredict -->|batch score| MongoDB

    S3 -->|load model| FastAPI
    FastAPI -->|serve inference| Client
    FastAPI -->|health check| HealthCheck
    Schema -->|used by| KafkaProducer
    Schema -->|used by| FaustService
    Schema -->|used by| BatchTrain
    Schema -->|used by| BatchPredict
    Logger -->|logging| KafkaProducer
    Logger -->|logging| FaustService
    Logger -->|logging| FastAPI
    Logger -->|logging| BatchTrain
    Logger -->|logging| BatchPredict

    %% Click Events
    click KafkaProducer "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/components/kafka_producer.py"
    click FaustService "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/components/faust_app.py"
    click FaustService "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/components/kafka_consumer.py"
    click BatchTrain "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/pipeline/training_pipeline.py"
    click BatchPredict "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/pipeline/batch_prediction_pipeline.py"
    click S3 "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/cloud/s3_sync.py"
    click FastAPI "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/app.py"
    click FastAPI "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/main.py"
    click HealthCheck "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/ping_mongo.py"
    click Schema "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/data_schema/schema.yaml"
    click Artifacts "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/final_models/Model.pkl"
    click Logger "https://github.com/arpitshourya/creditcardfrauddetection/blob/main/FraudDetection/logging/logger.py"

    %% Styles
    classDef datastore fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef compute fill:#90EE90,stroke:#333,stroke-width:1px
    classDef ext fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef util fill:#F0E68C,stroke:#333,stroke-width:1px
```
