# yayoucef/trust-model architecture

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

- Interactive diagram: https://gitdiagram.com/yayoucef/trust-model
- Repository: https://github.com/yayoucef/trust-model

## Overview

The repository combines an off-chain Python anomaly-detection experiment with a JavaScript Web3 interface and a documented blockchain simulation workflow. The Python entry point generates datasets, runs three detectors, evaluates their predictions, writes split CSVs, and plots F1 scores. The README also describes peer trust updates and score retrieval through a local blockchain. Some documented blockchain capabilities, including contract deployment and on-chain trust handling, have no implementation source in the tree; those connections are shown only where the README supports them.

Main entry points: [`main.py`](https://github.com/yayoucef/trust-model/blob/main/main.py) (Experiment runner), [`web3/web3.js`](https://github.com/yayoucef/trust-model/blob/main/web3/web3.js) (Web3 facade), [`simulate.js`](https://github.com/yayoucef/trust-model/blob/main/simulate.js) (Peer simulator), [`web3/eth/index.js`](https://github.com/yayoucef/trust-model/blob/main/web3/eth/index.js) (Contract interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_offchain["Off-chain analysis"]
  node_pipeline["Experiment runner<br/>[main.py]"]
  node_generator["Synthetic data"]
  node_iforest["Isolation Forest"]
  node_lof["Local Outlier Factor<br/>[lof.py]"]
  node_autoencoder["Autoencoder<br/>[autoencoder.py]"]
  node_outputs[("Split datasets")]
end

subgraph group_evaluation["Evaluation"]
  node_metrics["Prediction metrics<br/>[metrics.py]"]
  node_plots["Result plots<br/>[plots.py]"]
end

subgraph group_blockchain["Blockchain interface"]
  node_simulator["Peer simulator<br/>[simulate.js]"]
  node_web3["Web3 facade<br/>[web3.js]"]
  node_provider["HTTP provider<br/>[httpProvider.js]"]
  node_eth["Contract interface<br/>[index.js]"]
  node_abi["Trust contract ABI<br/>[TrustABI.json]"]
end

node_researcher(("Researcher"))
node_rpc(("Local blockchain RPC"))

node_researcher -->|"runs"| node_pipeline
node_pipeline -->|"generates data"| node_generator
node_pipeline -->|"runs detector"| node_iforest
node_pipeline -->|"runs detector"| node_lof
node_pipeline -->|"runs detector"| node_autoencoder
node_pipeline -->|"evaluates predictions"| node_metrics
node_pipeline -->|"writes CSVs"| node_outputs
node_pipeline -->|"plots results"| node_plots
node_researcher -->|"runs simulation"| node_simulator
node_web3 -->|"creates provider"| node_provider
node_web3 -->|"creates interface"| node_eth
node_eth -->|"loads ABI"| node_abi
node_web3 -.->|"connects via"| node_rpc
node_simulator -.->|"uses blockchain"| node_rpc

click node_pipeline "https://github.com/yayoucef/trust-model/blob/main/main.py"
click node_generator "https://github.com/yayoucef/trust-model/blob/main/data/synthetic/synthetic_data_generator.py"
click node_iforest "https://github.com/yayoucef/trust-model/blob/main/models/isolation_forest.py"
click node_lof "https://github.com/yayoucef/trust-model/blob/main/models/lof.py"
click node_autoencoder "https://github.com/yayoucef/trust-model/blob/main/models/autoencoder.py"
click node_outputs "https://github.com/yayoucef/trust-model/tree/main/data/outputs"
click node_metrics "https://github.com/yayoucef/trust-model/blob/main/evaluation/metrics.py"
click node_plots "https://github.com/yayoucef/trust-model/blob/main/evaluation/plots.py"
click node_simulator "https://github.com/yayoucef/trust-model/blob/main/simulate.js"
click node_web3 "https://github.com/yayoucef/trust-model/blob/main/web3/web3.js"
click node_provider "https://github.com/yayoucef/trust-model/blob/main/web3/providers/httpProvider.js"
click node_eth "https://github.com/yayoucef/trust-model/blob/main/web3/eth/index.js"
click node_abi "https://github.com/yayoucef/trust-model/blob/main/web3/packages/TrustABI.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_pipeline,node_generator,node_iforest,node_lof,node_autoencoder,node_outputs toneBlue
class node_metrics,node_plots toneAmber
class node_simulator,node_web3,node_provider,node_eth,node_abi toneMint
class node_researcher,node_rpc toneIndigo
```

## Components

### Off-chain analysis

- [Experiment runner](https://github.com/yayoucef/trust-model/blob/main/main.py): `main.py`
- [Synthetic data](https://github.com/yayoucef/trust-model/blob/main/data/synthetic/synthetic_data_generator.py): `data/synthetic/synthetic_data_generator.py`
- [Isolation Forest](https://github.com/yayoucef/trust-model/blob/main/models/isolation_forest.py): `models/isolation_forest.py`
- [Local Outlier Factor](https://github.com/yayoucef/trust-model/blob/main/models/lof.py): `models/lof.py`
- [Autoencoder](https://github.com/yayoucef/trust-model/blob/main/models/autoencoder.py): `models/autoencoder.py`
- [Split datasets](https://github.com/yayoucef/trust-model/tree/main/data/outputs): `data/outputs`

### Evaluation

- [Prediction metrics](https://github.com/yayoucef/trust-model/blob/main/evaluation/metrics.py): `evaluation/metrics.py`
- [Result plots](https://github.com/yayoucef/trust-model/blob/main/evaluation/plots.py): `evaluation/plots.py`

### Blockchain interface

- [Peer simulator](https://github.com/yayoucef/trust-model/blob/main/simulate.js): `simulate.js`
- [Web3 facade](https://github.com/yayoucef/trust-model/blob/main/web3/web3.js): `web3/web3.js`
- [HTTP provider](https://github.com/yayoucef/trust-model/blob/main/web3/providers/httpProvider.js): `web3/providers/httpProvider.js`
- [Contract interface](https://github.com/yayoucef/trust-model/blob/main/web3/eth/index.js): `web3/eth/index.js`
- [Trust contract ABI](https://github.com/yayoucef/trust-model/blob/main/web3/packages/TrustABI.json): `web3/packages/TrustABI.json`

### Other components

- **Researcher**
- **Local blockchain RPC**

## Connections

- Researcher → Experiment runner: runs (evidence: `README.md`)
- Experiment runner → Synthetic data: generates data (evidence: `main.py`)
- Experiment runner → Isolation Forest: runs detector (evidence: `main.py`)
- Experiment runner → Local Outlier Factor: runs detector (evidence: `main.py`)
- Experiment runner → Autoencoder: runs detector (evidence: `main.py`)
- Experiment runner → Prediction metrics: evaluates predictions (evidence: `main.py`)
- Experiment runner → Split datasets: writes CSVs (evidence: `main.py`)
- Experiment runner → Result plots: plots results (evidence: `main.py`)
- Researcher → Peer simulator: runs simulation (evidence: `README.md`)
- Web3 facade → HTTP provider: creates provider (evidence: `web3/web3.js`)
- Web3 facade → Contract interface: creates interface (evidence: `web3/web3.js`)
- Contract interface → Trust contract ABI: loads ABI (evidence: `web3/eth/index.js`)
- Web3 facade → Local blockchain RPC: connects via
- Peer simulator → Local blockchain RPC: uses blockchain
