# sunilt808/traceacc1 architecture

> Architecture diagram of the GitHub repository sunilt808/traceacc1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sunilt808/traceacc1
- Repository: https://github.com/sunilt808/traceacc1

## Overview

#### Purpose and Entrypoints
TraceAcc Pro is a governed AML/money-muling operations platform: clients submit datasets and requests; admins route and release work; analysts detect suspicious transaction patterns; investigators turn escalations into evidence-backed cases and final reports. The backend FastAPI application starts at `backend/main.py`; the role-routed React SPA starts at `money-muling-frontend/src/main.jsx` and defines application routes in `money-muling-frontend/src/App.jsx`.

#### Frontend Workspaces
The React/Vite client presents distinct client, admin, TraceLab analyst, and InvoSpace investigator experiences. Authentication and JWT-backed session state are centralized in `money-muling-frontend/src/context/AuthContext.jsx`; API access/token injection is centralized in `money-muling-frontend/src/services/api.js`. Global analysis result state is held in `money-muling-frontend/src/context/AnalysisContext.jsx`. Key investigative views include graph visualization, pattern analysis, case work, and intelligence dossiers under `money-muling-frontend/src/components/pages/GraphViewer.jsx`, `money-muling-frontend/src/components/pages/AnalystPatternsPage.jsx`, and `money-muling-frontend/src/components/pages/InvestigatorIntelPage.jsx`.

#### API, Identity, and Workspace Boundary
FastAPI route modules expose REST operations for authentication, workflow, analysis, cases, reports, audit, datasets, notifications, and intelligence under `backend/api/routes/`. JWT authentication dependencies and current-workspace resolution form the request boundary in `backend/api/deps.py`; RBAC policy is defined in `backend/core/permissions.py`. The API is organized around domain endpoints rather than a separate BFF layer; principal integrations are browser-to-API REST calls.

#### Governed AML Lifecycle
A service request is accepted/rejected, assigned to a workspace, analyzed, escalated as alerts, converted to cases, investigated, reviewed, sealed, and released to the client. Domain persistence covers organizations/users, requests, workflow instances, assignments, alerts, cases, reports, evidence, messaging, notifications, and immutable activity/audit records. Core models reside in `backend/models/service_request.py`, `backend/models/workflow_instance.py`, and `backend/models/analysis_job.py`; lifecycle APIs are concentrated in `backend/api/routes/workflow.py`, `backend/api/routes/service_requests.py`, and `backend/api/routes/reports.py`. Audit and notification services are explicit side-effect boundaries in `backend/services/audit_service.py` and `backend/services/notification_service.py`.

#### Analysis Ingestion and Graph Pipeline
Uploaded CSV/XLSX transaction data is parsed into an in-memory directed transaction graph, then analyzed rather than persisted as normalized transaction/account tables. The input/graph boundary is `backend/utils/csv_parser.py` and `backend/utils/graph.py`. The advanced analysis endpoint in `backend/api/routes/analysis.py` invokes the scoring pipeline and stores its result in analysis-job metadata, enabling downstream reports and Intel Hub queries without re-analysis. Graph and analyst-facing retrieval operations are exposed through `backend/api/routes/graph.py`, `backend/api/routes/patterns.py`, and `backend/api/routes/intel.py`.

#### Detection and Scoring Core
The detection core combines topology, behavioral, temporal, community, and unsupervised anomaly signals. `backend/detectors/pattern_suite.py` orchestrates the standardized 15-pattern output; `backend/detectors/hybrid_engine.py` fuses detector families into account risk scores; `backend/detectors/ml_anomaly.py` provides Isolation Forest, LOF, and DBSCAN. Individual NetworkX-based graph detectors include cycle/fan/layering logic in `backend/detectors/cycle.py`, `backend/detectors/fan.py`, and `backend/detectors/layering.py`. High-risk results become alerts and feed investigation/case routes.

#### Supervised DC-LCG Model Path
The optional DC-LCG PyTorch model is trained from labeled or weakly supervised datasets, saved as versioned `.pt` artifacts, loaded through a registry, and fused as an additional hybrid-score dimension during advanced analysis. This train/serve boundary is implemented by `backend/api/routes/dclcg.py`, `backend/detectors/dclcg/train.py`, and `backend/detectors/dclcg/inference.py`; artifacts live in `backend/models_artifacts/`. It produces illicit probabilities, disguise scores, and evidence paths for analyst explanations.

#### Persistence, Deployment, and External Services
SQLAlchemy persistence is configured in `backend/db/database.py`, with schema evolution in `backend/alembic/`. PostgreSQL/Supabase is the intended production database, with SQLite fallback. The stack uses Python/FastAPI/Uvicorn, NetworkX, scikit-learn, PyTorch, React 18/Vite, Axios, and Cytoscape.js. Backend serverless deployment configuration exists at `backend/vercel.json`; frontend hosting automation targets Firebase via `.github/workflows/firebase-hosting-merge.yml`.

Main entry points: [`backend/main.py`](https://github.com/sunilt808/traceacc1/blob/t1/backend/main.py) (FastAPI application), [`backend/detectors/hybrid_engine.py`](https://github.com/sunilt808/traceacc1/blob/t1/backend/detectors/hybrid_engine.py) (Hybrid detection and scoring), [`backend/models/workflow_instance.py`](https://github.com/sunilt808/traceacc1/blob/t1/backend/models/workflow_instance.py) (Request-to-report lifecycle), [`money-muling-frontend/src/App.jsx`](https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/App.jsx) (Application routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React workspaces"]
  node_spa["Role-routed React SPA<br/>React/Vite<br/>[main.jsx]"]
  node_app_routes["Application routes<br/>React routes<br/>[App.jsx]"]
  node_auth_context["JWT session state<br/>Auth context<br/>[AuthContext.jsx]"]
  node_api_client["API client<br/>Axios service<br/>[api.js]"]
  node_investigation_views["Analyst and investigator views<br/>React pages<br/>[GraphViewer.jsx]"]
end

subgraph group_api["FastAPI boundary"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_request_boundary["Auth and workspace boundary<br/>FastAPI dependencies<br/>[deps.py]"]
  node_rbac["RBAC policy<br/>Permissions<br/>[permissions.py]"]
  node_lifecycle_api["Lifecycle APIs<br/>REST routes<br/>[workflow.py]"]
  node_analysis_api["Analysis and intelligence APIs<br/>REST routes<br/>[analysis.py]"]
end

subgraph group_analysis["Analysis pipeline"]
  node_ingestion_graph{{"CSV/XLSX transaction graph<br/>In-memory NetworkX graph<br/>[csv_parser.py]"}}
  node_detection_core["Hybrid detection and scoring<br/>Detector orchestration<br/>[hybrid_engine.py]"]
  node_ml_anomaly["Unsupervised anomaly models<br/>scikit-learn<br/>[ml_anomaly.py]"]
  node_dclcg["DC-LCG model path<br/>PyTorch train/serve<br/>[dclcg.py]"]
end

subgraph group_domain["Governed lifecycle"]
  node_lifecycle["Request-to-report lifecycle<br/>Domain workflow"]
  node_audit_notifications["Audit and notifications<br/>Side-effect services<br/>[audit_service.py]"]
end

subgraph group_data["Persistence and deployment"]
  node_database[("Operational database<br/>SQLAlchemy / PostgreSQL<br/>[database.py]")]
  node_model_artifacts["Versioned model artifacts<br/>PyTorch .pt artifacts"]
end

node_spa -->|"mounts"| node_app_routes
node_app_routes -->|"uses session"| node_auth_context
node_app_routes -->|"routes roles to"| node_investigation_views
node_auth_context -->|"supplies JWT"| node_api_client
node_investigation_views -->|"REST calls"| node_api_client
node_api_client -->|"browser REST"| node_fastapi
node_fastapi -->|"protects routes with"| node_request_boundary
node_request_boundary -->|"enforces"| node_rbac
node_fastapi -->|"serves"| node_lifecycle_api
node_fastapi -->|"serves"| node_analysis_api
node_lifecycle_api -->|"advances"| node_lifecycle
node_analysis_api -->|"parses uploads"| node_ingestion_graph
node_ingestion_graph -->|"analyzes graph"| node_detection_core
node_ml_anomaly -->|"contributes signals"| node_detection_core
node_dclcg -->|"adds score dimension"| node_detection_core
node_model_artifacts -->|"loads and saves"| node_dclcg
node_detection_core -->|"creates alerts and analysis results"| node_lifecycle
node_analysis_api -->|"stores analysis metadata"| node_lifecycle
node_lifecycle -->|"persists governed records"| node_database
node_lifecycle_api -->|"emits side effects"| node_audit_notifications
node_audit_notifications -->|"records activity"| node_database

click node_spa "https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/main.jsx"
click node_app_routes "https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/App.jsx"
click node_auth_context "https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/context/AuthContext.jsx"
click node_api_client "https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/services/api.js"
click node_investigation_views "https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/components/pages/GraphViewer.jsx"
click node_fastapi "https://github.com/sunilt808/traceacc1/blob/t1/backend/main.py"
click node_request_boundary "https://github.com/sunilt808/traceacc1/blob/t1/backend/api/deps.py"
click node_rbac "https://github.com/sunilt808/traceacc1/blob/t1/backend/core/permissions.py"
click node_lifecycle_api "https://github.com/sunilt808/traceacc1/blob/t1/backend/api/routes/workflow.py"
click node_analysis_api "https://github.com/sunilt808/traceacc1/blob/t1/backend/api/routes/analysis.py"
click node_ingestion_graph "https://github.com/sunilt808/traceacc1/blob/t1/backend/utils/csv_parser.py"
click node_detection_core "https://github.com/sunilt808/traceacc1/blob/t1/backend/detectors/hybrid_engine.py"
click node_ml_anomaly "https://github.com/sunilt808/traceacc1/blob/t1/backend/detectors/ml_anomaly.py"
click node_dclcg "https://github.com/sunilt808/traceacc1/blob/t1/backend/api/routes/dclcg.py"
click node_lifecycle "https://github.com/sunilt808/traceacc1/blob/t1/backend/models/workflow_instance.py"
click node_audit_notifications "https://github.com/sunilt808/traceacc1/blob/t1/backend/services/audit_service.py"
click node_database "https://github.com/sunilt808/traceacc1/blob/t1/backend/db/database.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa,node_app_routes,node_auth_context,node_api_client,node_investigation_views toneBlue
class node_fastapi,node_request_boundary,node_rbac,node_lifecycle_api,node_analysis_api toneAmber
class node_ingestion_graph,node_detection_core,node_ml_anomaly,node_dclcg toneMint
class node_lifecycle,node_audit_notifications toneRose
class node_database,node_model_artifacts toneIndigo
```

## Components

### React workspaces

Role-specific client, admin, analyst, and investigator experiences.

- [Role-routed React SPA](https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/main.jsx): React/Vite · `money-muling-frontend/src/main.jsx`
- [Application routes](https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/App.jsx): React routes · `money-muling-frontend/src/App.jsx`
- [JWT session state](https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/context/AuthContext.jsx): Auth context · `money-muling-frontend/src/context/AuthContext.jsx`
- [API client](https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/services/api.js): Axios service · Injects access tokens into browser REST requests. · `money-muling-frontend/src/services/api.js`
- [Analyst and investigator views](https://github.com/sunilt808/traceacc1/blob/t1/money-muling-frontend/src/components/pages/GraphViewer.jsx): React pages · Graph, pattern, case, and intelligence workspaces. · `money-muling-frontend/src/components/pages/GraphViewer.jsx`

### FastAPI boundary

REST endpoints enforce authenticated workspace access and RBAC.

- [FastAPI application](https://github.com/sunilt808/traceacc1/blob/t1/backend/main.py): FastAPI · `backend/main.py`
- [Auth and workspace boundary](https://github.com/sunilt808/traceacc1/blob/t1/backend/api/deps.py): FastAPI dependencies · Resolves JWT principal and current workspace. · `backend/api/deps.py`
- [RBAC policy](https://github.com/sunilt808/traceacc1/blob/t1/backend/core/permissions.py): Permissions · `backend/core/permissions.py`
- [Lifecycle APIs](https://github.com/sunilt808/traceacc1/blob/t1/backend/api/routes/workflow.py): REST routes · Requests, workflow, reports, cases, audit, datasets, and notifications. · `backend/api/routes/workflow.py`
- [Analysis and intelligence APIs](https://github.com/sunilt808/traceacc1/blob/t1/backend/api/routes/analysis.py): REST routes · Advanced analysis, graph, patterns, and Intel Hub retrieval. · `backend/api/routes/analysis.py`

### Analysis pipeline

Transaction graphs are scored and retained in analysis-job metadata.

- [CSV/XLSX transaction graph](https://github.com/sunilt808/traceacc1/blob/t1/backend/utils/csv_parser.py): In-memory NetworkX graph · Input data is parsed rather than normalized into transaction tables. · `backend/utils/csv_parser.py`
- [Hybrid detection and scoring](https://github.com/sunilt808/traceacc1/blob/t1/backend/detectors/hybrid_engine.py): Detector orchestration · Combines 15-pattern, topology, behavior, temporal, community, and anomaly signals. · `backend/detectors/hybrid_engine.py`
- [Unsupervised anomaly models](https://github.com/sunilt808/traceacc1/blob/t1/backend/detectors/ml_anomaly.py): scikit-learn · Isolation Forest, LOF, and DBSCAN signals. · `backend/detectors/ml_anomaly.py`
- [DC-LCG model path](https://github.com/sunilt808/traceacc1/blob/t1/backend/api/routes/dclcg.py): PyTorch train/serve · Versioned supervised model adds illicit probability, disguise score, and evidence paths. · `backend/api/routes/dclcg.py`

### Governed lifecycle

Requests progress through workflow, alerts, cases, reports, and release.

- [Request-to-report lifecycle](https://github.com/sunilt808/traceacc1/blob/t1/backend/models/workflow_instance.py): Domain workflow · Assignment, analysis, escalation, investigation, review, sealing, and client release. · `backend/models/workflow_instance.py`
- [Audit and notifications](https://github.com/sunilt808/traceacc1/blob/t1/backend/services/audit_service.py): Side-effect services · Immutable activity records and user notifications. · `backend/services/audit_service.py`

### Persistence and deployment

- [Operational database](https://github.com/sunilt808/traceacc1/blob/t1/backend/db/database.py): SQLAlchemy / PostgreSQL · PostgreSQL/Supabase production store with SQLite fallback. · `backend/db/database.py`
- **Versioned model artifacts**: PyTorch .pt artifacts

## Connections

- Role-routed React SPA → Application routes: mounts
- Application routes → JWT session state: uses session
- Application routes → Analyst and investigator views: routes roles to
- JWT session state → API client: supplies JWT
- Analyst and investigator views → API client: REST calls
- API client → FastAPI application: browser REST
- FastAPI application → Auth and workspace boundary: protects routes with
- Auth and workspace boundary → RBAC policy: enforces
- FastAPI application → Lifecycle APIs: serves
- FastAPI application → Analysis and intelligence APIs: serves
- Lifecycle APIs → Request-to-report lifecycle: advances
- Analysis and intelligence APIs → CSV/XLSX transaction graph: parses uploads
- CSV/XLSX transaction graph → Hybrid detection and scoring: analyzes graph
- Unsupervised anomaly models → Hybrid detection and scoring: contributes signals
- DC-LCG model path → Hybrid detection and scoring: adds score dimension
- Versioned model artifacts → DC-LCG model path: loads and saves
- Hybrid detection and scoring → Request-to-report lifecycle: creates alerts and analysis results
- Analysis and intelligence APIs → Request-to-report lifecycle: stores analysis metadata
- Request-to-report lifecycle → Operational database: persists governed records
- Lifecycle APIs → Audit and notifications: emits side effects
- Audit and notifications → Operational database: records activity
