# smit134/crypto-demo architecture

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

- Interactive diagram: https://gitdiagram.com/smit134/crypto-demo
- Repository: https://github.com/smit134/crypto-demo

## Overview

#### Purpose
VASPTrace investigates an unknown Bitcoin wallet and produces an explainable attribution graph linking likely common-control address clusters to known Virtual Asset Service Providers (VASPs). Its governing pipeline is evidence-first: collect blockchain evidence, visualize it, then optionally apply AI/ML.

#### Entry Points and Runtime
The repository is a TypeScript/Node.js project with a Next.js application build under `frontend/.next`. The primary HTTP entry points exposed by the built App Router are:
- Investigation collection: `frontend/.next/server/app/api/investigations/route.js`
- Investigation detail: `frontend/.next/server/app/api/investigations/[id]/route.js`
- Investigation graph: `frontend/.next/server/app/api/investigations/[id]/graph/route.js`
- Main UI route: `frontend/.next/server/app/page.js`

The source tree shown does not include the corresponding frontend source routes; `.next` is generated output and should not be treated as the implementation boundary.

#### Investigation API and Orchestration
The investigation API is the system boundary between clients and attribution processing. A client creates or requests an investigation, retrieves its persisted state by ID, and separately fetches graph-shaped evidence for visualization. This separates lifecycle/detail concerns from graph delivery:
- `frontend/.next/server/app/api/investigations/route.js`
- `frontend/.next/server/app/api/investigations/[id]/route.js`
- `frontend/.next/server/app/api/investigations/[id]/graph/route.js`

The API is expected to coordinate wallet input, blockchain lookup, candidate attribution, persistence, and graph assembly; exact orchestration source is not present in the supplied tree.

#### Blockchain Intelligence Boundary
Blockchain access is isolated under `src/lib/blockchain`, indicating a provider abstraction rather than direct provider calls throughout the application. This is the key external-service boundary for transaction/address history and mempool-derived evidence:
- `src/lib/blockchain/provider.ts`
- `src/lib/blockchain/mempool.ts`

This boundary should normalize upstream blockchain API responses into application evidence models, handle provider failure/rate-limit behavior, and avoid leaking vendor-specific formats into investigation or visualization layers.

#### Attribution Evidence and VASP Reference Data
Known VASP labels are maintained as local seed data and loaded through an explicit seeding process:
- `data/vasps.json`
- `src/scripts/seed-vasps.ts`

The attribution stage compares discovered wallet/cluster evidence against this labelled address corpus, then ranks candidate VASPs using multiple signals. The reference dataset is distinct from live blockchain intelligence: labelled identities are locally managed, while transactional evidence comes through the blockchain provider boundary.

#### Persistence and Investigation State
Prisma defines the durable data-model boundary:
- `prisma/schema.prisma`

Investigations need stable IDs because both detail and graph API routes are ID-addressed. Persistence should therefore retain the queried wallet, investigation status, evidence/candidate results, confidence or ranking outputs, and enough graph data to reproduce the explanation without rerunning external intelligence calls.

#### Visualization Contract
The frontend consumes graph data from the dedicated graph route and renders the investigation as connected wallet, cluster, VASP, and evidence relationships. Build artifacts show `@xyflow/react` is included, indicating a React graph/canvas runtime:
- `frontend/.next/server/app/page.js`
- `frontend/.next/dev/static/chunks/node_modules_@xyflow_react_dist_style_0w-ra00.css`

The graph API is the critical contract: backend attribution logic should emit visualization-neutral nodes, edges, labels, evidence references, and confidence metadata rather than UI-specific state.

Main entry points: [`frontend/.next/server/app/page.js`](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/page.js) (Investigation UI), [`frontend/.next/server/app/api/investigations/[id]/graph/route.js`](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/%5Bid%5D/graph/route.js) (Investigation graph API), [`src/lib/blockchain/provider.ts`](https://github.com/smit134/crypto-demo/blob/main/src/lib/blockchain/provider.ts) (Blockchain provider boundary), [`frontend/.next/server/app/api/investigations/route.js`](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/route.js) (Investigation collection API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Built application"]
  node_ui["Investigation UI<br/>Next.js page<br/>[page.js]"]
  node_create_api["Investigation collection API<br/>App Router endpoint<br/>[route.js]"]
  node_detail_api["Investigation detail API<br/>App Router endpoint<br/>[route.js]"]
  node_graph_api["Investigation graph API<br/>App Router endpoint<br/>[route.js]"]
  node_graph_canvas["Graph canvas<br/>React Flow runtime"]
end

subgraph group_investigation["Investigation pipeline"]
  node_orchestrator["Investigation orchestration<br/>application service"]
  node_evidence_models["Normalized chain evidence<br/>evidence model"]
  node_attribution["Candidate attribution<br/>ranking stage"]
  node_graph_assembly["Explanation graph assembly<br/>graph contract"]
  node_prisma_schema[("Prisma data model<br/>persistence schema<br/>[schema.prisma]")]
  node_investigation_store[("Investigation store<br/>durable state")]
end

subgraph group_intelligence["Intelligence sources"]
  node_blockchain_provider["Blockchain provider boundary<br/>provider abstraction<br/>[provider.ts]"]
  node_mempool_source["Mempool intelligence<br/>chain data adapter<br/>[mempool.ts]"]
  node_vasp_seed["VASP seed loader<br/>seed process<br/>[seed-vasps.ts]"]
  node_vasp_corpus["Labelled VASP corpus<br/>reference dataset<br/>[vasps.json]"]
end

node_ui -->|"starts investigation"| node_create_api
node_ui -->|"loads state"| node_detail_api
node_ui -->|"fetches graph"| node_graph_api
node_graph_api -->|"graph payload"| node_graph_canvas
node_create_api -->|"wallet request"| node_orchestrator
node_detail_api -->|"reads by ID"| node_investigation_store
node_graph_api -->|"reads saved graph"| node_investigation_store
node_orchestrator -->|"collects chain history"| node_blockchain_provider
node_mempool_source -->|"mempool evidence"| node_blockchain_provider
node_blockchain_provider -->|"normalizes"| node_evidence_models
node_orchestrator -->|"submits evidence"| node_attribution
node_evidence_models -->|"cluster signals"| node_attribution
node_vasp_corpus -->|"known labels"| node_attribution
node_attribution -->|"candidates and confidence"| node_graph_assembly
node_orchestrator -->|"investigation context"| node_graph_assembly
node_orchestrator -->|"persists results"| node_investigation_store
node_graph_assembly -->|"stores explanation graph"| node_investigation_store
node_prisma_schema -.->|"defines model"| node_investigation_store
node_vasp_seed -->|"loads seed labels"| node_vasp_corpus

click node_ui "https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/page.js"
click node_create_api "https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/route.js"
click node_detail_api "https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/%5Bid%5D/route.js"
click node_graph_api "https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/%5Bid%5D/graph/route.js"
click node_graph_canvas "https://github.com/smit134/crypto-demo/blob/main/frontend/.next/dev/static/chunks/node_modules_%40xyflow_react_dist_style_0w-ra00.css"
click node_prisma_schema "https://github.com/smit134/crypto-demo/blob/main/prisma/schema.prisma"
click node_blockchain_provider "https://github.com/smit134/crypto-demo/blob/main/src/lib/blockchain/provider.ts"
click node_mempool_source "https://github.com/smit134/crypto-demo/blob/main/src/lib/blockchain/mempool.ts"
click node_vasp_seed "https://github.com/smit134/crypto-demo/blob/main/src/scripts/seed-vasps.ts"
click node_vasp_corpus "https://github.com/smit134/crypto-demo/blob/main/data/vasps.json"

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_ui,node_create_api,node_detail_api,node_graph_api,node_graph_canvas toneBlue
class node_orchestrator,node_evidence_models,node_attribution,node_graph_assembly,node_prisma_schema,node_investigation_store toneAmber
class node_blockchain_provider,node_mempool_source,node_vasp_seed,node_vasp_corpus toneMint
```

## Components

### Built application

Next.js build artifacts expose the current runtime surface.

- [Investigation UI](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/page.js): Next.js page · `frontend/.next/server/app/page.js`
- [Investigation collection API](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/route.js): App Router endpoint · Creates or requests investigations. · `frontend/.next/server/app/api/investigations/route.js`
- [Investigation detail API](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/%5Bid%5D/route.js): App Router endpoint · Retrieves durable investigation state by ID. · `frontend/.next/server/app/api/investigations/[id]/route.js`
- [Investigation graph API](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/server/app/api/investigations/%5Bid%5D/graph/route.js): App Router endpoint · Delivers visualization-neutral evidence graphs by ID. · `frontend/.next/server/app/api/investigations/[id]/graph/route.js`
- [Graph canvas](https://github.com/smit134/crypto-demo/blob/main/frontend/.next/dev/static/chunks/node_modules_%40xyflow_react_dist_style_0w-ra00.css): React Flow runtime · Renders wallet, cluster, VASP, and evidence relationships. · `frontend/.next/dev/static/chunks/node_modules_@xyflow_react_dist_style_0w-ra00.css`

### Investigation pipeline

Coordinates evidence collection, attribution, persistence, and graph delivery.

- **Investigation orchestration**: application service · Coordinates lookup, attribution, durable state, and graph assembly.
- **Normalized chain evidence**: evidence model · Provider-neutral address, transaction, and mempool-derived evidence.
- **Candidate attribution**: ranking stage · Matches cluster evidence to labelled VASP addresses and confidence signals.
- **Explanation graph assembly**: graph contract · Produces nodes, edges, labels, evidence references, and confidence metadata.
- [Prisma data model](https://github.com/smit134/crypto-demo/blob/main/prisma/schema.prisma): persistence schema · Defines stable investigation and reproducible result storage. · `prisma/schema.prisma`
- **Investigation store**: durable state · Persists wallet query, status, evidence, candidates, and graph data.

### Intelligence sources

Live chain evidence and local identity labels remain separate.

- [Blockchain provider boundary](https://github.com/smit134/crypto-demo/blob/main/src/lib/blockchain/provider.ts): provider abstraction · Normalizes upstream responses and contains vendor failure behavior. · `src/lib/blockchain/provider.ts`
- [Mempool intelligence](https://github.com/smit134/crypto-demo/blob/main/src/lib/blockchain/mempool.ts): chain data adapter · `src/lib/blockchain/mempool.ts`
- [VASP seed loader](https://github.com/smit134/crypto-demo/blob/main/src/scripts/seed-vasps.ts): seed process · Loads managed VASP identity labels into reference data. · `src/scripts/seed-vasps.ts`
- [Labelled VASP corpus](https://github.com/smit134/crypto-demo/blob/main/data/vasps.json): reference dataset · Locally managed known VASP address labels. · `data/vasps.json`

## Connections

- Investigation UI → Investigation collection API: starts investigation
- Investigation UI → Investigation detail API: loads state
- Investigation UI → Investigation graph API: fetches graph
- Investigation graph API → Graph canvas: graph payload
- Investigation collection API → Investigation orchestration: wallet request
- Investigation detail API → Investigation store: reads by ID
- Investigation graph API → Investigation store: reads saved graph
- Investigation orchestration → Blockchain provider boundary: collects chain history
- Mempool intelligence → Blockchain provider boundary: mempool evidence
- Blockchain provider boundary → Normalized chain evidence: normalizes
- Investigation orchestration → Candidate attribution: submits evidence
- Normalized chain evidence → Candidate attribution: cluster signals
- Labelled VASP corpus → Candidate attribution: known labels
- Candidate attribution → Explanation graph assembly: candidates and confidence
- Investigation orchestration → Explanation graph assembly: investigation context
- Investigation orchestration → Investigation store: persists results
- Explanation graph assembly → Investigation store: stores explanation graph
- Prisma data model → Investigation store: defines model
- VASP seed loader → Labelled VASP corpus: loads seed labels
