Fraud Pattern Analyzer is a full-stack portfolio project that ingests anonymized transaction records, stores them in PostgreSQL, and runs partition-aware anomaly detection over configurable time windows. The UI is intentionally lightweight, while the backend focuses on batch safety, retry behavior, partition isolation, and test coverage.
- Backend: Python, FastAPI, SQLAlchemy, Pandas
- Database: PostgreSQL, with Supabase-compatible connection support
- Frontend: Astro + React, built to static assets and served by FastAPI
- Testing: PyTest
- Data model:
transactionsandfraud_alertstables with partition-aware uniqueness rules
- Batch CSV ingestion with configurable batch size and retry logic
- Partition isolation through
source_partition-scoped storage and analysis - Rolling anomaly detection for:
- transaction velocity spikes
- abnormal amount spikes using median and z-score comparisons
- Persisted alert records for downstream review and auditability
- Simple browser UI for uploading transaction files and reviewing suspicious events
Detailed design notes live in docs/architecture.md.
High-level flow:
- The frontend uploads a CSV batch to the FastAPI API.
- The ingestion layer validates required columns and normalizes records.
- Records are written to PostgreSQL in configurable chunks with retry handling.
- Pandas loads partition-scoped transaction histories and computes fraud signals per partition.
- Fraud alerts are stored in the database and returned to the UI.
Use either Supabase or the included local PostgreSQL service:
- Supabase:
- Create a project and copy its PostgreSQL connection string.
- Set
DATABASE_URLinbackend/.env.
- Local Docker PostgreSQL:
- Run
docker compose up -d - Use
postgresql+psycopg://postgres:postgres@localhost:5432/fraud_analyzer
- Run
From C:\Projects\FraudAnalyzer\backend:
Copy-Item .env.example .envUpdate DATABASE_URL if you want to point to Supabase instead of local PostgreSQL.
Backend dependencies:
pip install -r requirements.txtFrontend dependencies:
From C:\Projects\FraudAnalyzer\frontend:
npm installFrom C:\Projects\FraudAnalyzer\frontend:
npm run buildFor frontend-only development you can also run:
npm run devFrom C:\Projects\FraudAnalyzer\backend:
uvicorn app.main:app --reloadOpen http://127.0.0.1:8000.
From C:\Projects\FraudAnalyzer\backend:
pytest -qThe suite covers:
- retry behavior during batch ingestion
- missing partition edge cases
- anomaly detection behavior
- regression coverage for partition isolation
- end-to-end pipeline summaries
Use sample_data/demo_transactions.csv to test the upload flow quickly.
backend/app/API, data models, and pipeline servicesbackend/tests/PyTest coveragefrontend/src/Astro pages, React components, styles, and client utilitiesfrontend/dist/built frontend assets served by FastAPI afternpm run buildsample_data/sample transaction batchdocs/architecture and design notes