A modern end-to-end AML fraud detection project that converts natural language questions into SQL, executes them against PostgreSQL, and provides a React-based user interface for query history, bookmarks, and analytics.
This repository contains a fraud detection pipeline built with:
- FastAPI backend for NLP-to-SQL processing and fraud analytics
- React + Vite frontend for user queries, results display, and history management
- PostgreSQL-compatible SQL generation and execution
- Synthetic AML/fraud dataset generation for testing and demonstrations
The solution supports:
- natural language query input
- AI-assisted SQL generation fallback using a local LLaMA model via Ollama
- query history, bookmarking, and rerun support
- SAR generation and fraud pattern detection
- Natural language to SQL conversion for AML and fraud queries
- FastAPI REST API with
/query,/history,/bookmarks, and bookmark endpoints - React UI for query input, results, history, and analytics
- Local model integration via Ollama for advanced query understanding
- Synthetic dataset generation scripts in
backend/data_generation - Documentation and UI screenshot in
docs
backend/- main API and processing logicbackend/api/- FastAPI routesbackend/core/- classifier, fraud rules, prompt building, pipeline and model callerbackend/services/- history, query, SAR servicesbackend/database/- SQL schema, seed data, database helpersbackend/data_generation/- synthetic AML data generation scripts
frontend/- React + Vite appdocs/- project documentation and UI screenshotgenerated_data/- generated CSV datasets
- Python 3.11+ (recommended)
- FastAPI
- PostgreSQL / Psycopg2
- SQLAlchemy
- React 19 + Vite
- Material UI
- Ollama + LLaMA 3.1 8B for local model inference
- Groq API (remote model inference) as an alternative hosted LLM option
From the project root:
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txtcd frontend
npm install
cd ..The repository includes PostgreSQL schema and seed scripts in backend/database/.
Run the SQL scripts in a PostgreSQL database before starting the backend.
Recommended steps (example):
- Create a PostgreSQL database and user (example):
# create DB and user (run as postgres user)
psql -c "CREATE USER fraud_user WITH PASSWORD 'secure_password';"
psql -c "CREATE DATABASE fraud_db OWNER fraud_user;"- Configure environment variables for DB connection. Create a
.envfile at the project root with:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=fraud_db
DB_USER=fraud_user
DB_PASSWORD=secure_passwordThe backend reads these variables via backend/database/db_config.py.
- Apply schema and seed data (two options):
- Using psql to run SQL files:
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -f backend/database/schema.sql
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -f backend/database/seed_data.sql- Or use the provided Python loader which imports CSV files from
generated_data/:
# activate Python venv first
venv\\Scripts\\activate
python backend/database/load_data.py- Verify the database:
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -c "SELECT count(*) FROM transactions;"Notes:
- Ensure
generated_data/contains the CSV files required bybackend/database/load_data.py. - If you change table or column names, update
backend/database/load_data.pyaccordingly.
The backend supports two options for LLM-based fallbacks:
- Local (recommended for offline use): Ollama with LLaMA 3.1 8B
ollama pull llama3.1:8b
ollama serve- Remote (hosted): Groq API for managed model inference. To use Groq, set the
GROQ_API_KEYenvironment variable and updatebackend/core/llm_caller.pyto call the Groq endpoint instead of Ollama.
Example environment variable:
set GROQ_API_KEY=your_groq_api_key_hereKeep the Ollama server running when using the local option. If using Groq, ensure your API key is valid and network access is available.
From the project root:
uvicorn backend.app:app --reloadThe API will be available at http://127.0.0.1:8000.
From the frontend folder:
npm run devOpen the browser at the address shown by Vite, usually http://localhost:5173.
POST /query- execute a natural language AML queryGET /history- retrieve query historyGET /bookmarks- retrieve bookmarked queriesPOST /bookmark/{history_id}- bookmark a queryDELETE /bookmark/{history_id}- remove a bookmarkPOST /history/{history_id}/rerun- rerun a saved query using stored SQL
docs/data_model.md— data model and schema documentationdocs/images/ui-dashboard.png— application screenshot
- The UI image is located at
docs/images/ui-dashboard.pngand is referenced in this README. - If you need to regenerate data, use the scripts in
backend/data_generation/. - For local ML query fallback, ensure Ollama is running and the LLaMA model is loaded, or configure Groq API by setting
GROQ_API_KEYfor remote inference.
For questions or enhancements, review the code in backend/core/ and frontend/src/ and open issues or discussions as needed.
