# hussainbasha559/smart-contract-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/hussainbasha559/smart-contract-analysis
- Repository: https://github.com/hussainbasha559/smart-contract-analysis

## Overview

ReTrace accepts EVM runtime bytecode and returns an opcode listing, decompiler output, security findings and instruction-linked evidence, while explicitly marking incomplete analysis when tools fail or are skipped. Users can also manage accounts, files, scan history, AI explanations and usage. The graph includes the documented platform branches; several router and service implementations were not excerpted, so those connections are shown only where the index or README supports them.

Main entry points: [`frontend/src/services/api.js`](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/services/api.js) (API client), [`backend/app/main.py`](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/main.py) (Backend application), [`backend/app/services/report_service.py`](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/report_service.py) (Analysis orchestration), [`backend/app/api/routes.py`](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/api/routes.py) (Direct analysis API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_web_app["Dashboard<br/>[App.jsx]"]
  node_analyze_page["Analyze workspace<br/>[AnalyzePage.jsx]"]
  node_ui_results["Analysis panels<br/>[FindingsPanel.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_auth_ui["Sign-in and registration<br/>[AuthPage.jsx]"]
end

subgraph group_analysis["Bytecode analysis"]
  node_api_routes["Direct analysis API<br/>[routes.py]"]
  node_validation["Bytecode validation<br/>[validation.py]"]
  node_report["Analysis orchestration<br/>[report_service.py]"]
  node_disassembly["Opcode decoding"]
  node_reentrancy["Structural reentrancy check"]
  node_decompiler["Decompilation service"]
  node_mythril_service["Mythril analysis service<br/>[mythril_service.py]"]
end

subgraph group_platform["Workspace platform"]
  node_scan_routes["Background scans and history<br/>[scans.py]"]
  node_scan_runner["Scan worker<br/>[scan_runner.py]"]
  node_files_routes["File management<br/>[files.py]"]
  node_projects_routes["Projects<br/>[projects.py]"]
  node_ai_routes["AI explanations<br/>[ai.py]"]
  node_ai_service["Grounded AI service<br/>[ai_service.py]"]
  node_usage_routes["Usage analytics<br/>[usage.py]"]
end

subgraph group_identity["Identity and persistence"]
  node_auth_routes["Account and sessions<br/>[auth.py]"]
  node_database[("Application database<br/>[db.py]")]
  node_models["Platform records<br/>[models.py]"]
  node_app_entry["Backend application<br/>[main.py]"]
end

subgraph group_integrations["Analysis integrations"]
  node_heimdall["Heimdall adapter"]
  node_mythril_adapter["Mythril adapter<br/>[mythril_adapter.py]"]
  node_runtime["Tool runtime selection<br/>[runtime.py]"]
end

node_user(("User"))
node_external_tools{{"Heimdall and Mythril"}}

node_user -->|"uses"| node_web_app
node_web_app -->|"shows when signed out"| node_auth_ui
node_web_app -->|"shows workspace"| node_analyze_page
node_analyze_page -->|"requests analysis"| node_api_client
node_analyze_page -->|"renders findings"| node_ui_results
node_auth_ui -->|"registers or logs in"| node_api_client
node_api_client -->|"calls account endpoints"| node_auth_routes
node_api_client -.->|"calls analysis endpoints"| node_api_routes
node_api_client -.->|"calls scan endpoints"| node_scan_routes
node_api_client -.->|"calls file endpoints"| node_files_routes
node_api_client -.->|"calls project endpoints"| node_projects_routes
node_api_client -.->|"calls AI endpoints"| node_ai_routes
node_api_client -.->|"calls usage endpoints"| node_usage_routes
node_app_entry -->|"registers router"| node_api_routes
node_app_entry -->|"registers router"| node_auth_routes
node_app_entry -->|"registers router"| node_scan_routes
node_app_entry -->|"registers router"| node_files_routes
node_app_entry -->|"registers router"| node_projects_routes
node_app_entry -->|"registers router"| node_ai_routes
node_app_entry -->|"registers router"| node_usage_routes
node_api_routes -->|"validates input"| node_validation
node_api_routes -->|"requests analysis"| node_report
node_report -->|"decodes bytecode"| node_disassembly
node_report -->|"requests decompilation"| node_decompiler
node_report -->|"requests symbolic analysis"| node_mythril_service
node_report -->|"runs heuristic"| node_reentrancy
node_reentrancy -->|"uses instructions"| node_disassembly
node_mythril_service -->|"invokes"| node_mythril_adapter
node_decompiler -.->|"uses adapter"| node_heimdall
node_heimdall -->|"selects execution mode"| node_runtime
node_mythril_adapter -->|"selects execution mode"| node_runtime
node_heimdall -.->|"runs Heimdall"| node_external_tools
node_mythril_adapter -.->|"runs Mythril"| node_external_tools
node_scan_routes -->|"delegates scans"| node_scan_runner
node_scan_runner -.->|"runs analysis"| node_report
node_ai_routes -.->|"requests explanations"| node_ai_service
node_auth_routes -.->|"persists accounts and sessions"| node_database
node_database -->|"maps records"| node_models
node_app_entry -->|"recovers interrupted scans"| node_scan_runner

click node_web_app "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/App.jsx"
click node_analyze_page "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/pages/AnalyzePage.jsx"
click node_ui_results "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/components/FindingsPanel.jsx"
click node_api_client "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/services/api.js"
click node_auth_ui "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/pages/AuthPage.jsx"
click node_auth_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/auth.py"
click node_api_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/api/routes.py"
click node_validation "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/utils/validation.py"
click node_report "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/report_service.py"
click node_disassembly "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/bytecode_service.py"
click node_reentrancy "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/reentrancy_service.py"
click node_decompiler "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/decompiler_service.py"
click node_mythril_service "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/mythril_service.py"
click node_heimdall "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/adapters/heimdall_adapter.py"
click node_mythril_adapter "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/adapters/mythril_adapter.py"
click node_runtime "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/adapters/runtime.py"
click node_scan_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/scans.py"
click node_scan_runner "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/scan_runner.py"
click node_files_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/files.py"
click node_projects_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/projects.py"
click node_ai_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/ai.py"
click node_ai_service "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/ai_service.py"
click node_usage_routes "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/usage.py"
click node_database "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/db.py"
click node_models "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/models.py"
click node_app_entry "https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/main.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_web_app,node_analyze_page,node_ui_results,node_api_client,node_auth_ui,node_user toneBlue
class node_api_routes,node_validation,node_report,node_disassembly,node_reentrancy,node_decompiler,node_mythril_service toneAmber
class node_scan_routes,node_scan_runner,node_files_routes,node_projects_routes,node_ai_routes,node_ai_service,node_usage_routes toneMint
class node_auth_routes,node_database,node_models,node_app_entry toneRose
class node_heimdall,node_mythril_adapter,node_runtime,node_external_tools toneIndigo
```

## Components

### Web application

- [Dashboard](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Analyze workspace](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/pages/AnalyzePage.jsx): `frontend/src/pages/AnalyzePage.jsx`
- [Analysis panels](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/components/FindingsPanel.jsx): `frontend/src/components/FindingsPanel.jsx`
- [API client](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`
- [Sign-in and registration](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/frontend/src/pages/AuthPage.jsx): `frontend/src/pages/AuthPage.jsx`

### Bytecode analysis

- [Direct analysis API](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Bytecode validation](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/utils/validation.py): `backend/app/utils/validation.py`
- [Analysis orchestration](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/report_service.py): `backend/app/services/report_service.py`
- [Opcode decoding](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/bytecode_service.py): `backend/app/services/bytecode_service.py`
- [Structural reentrancy check](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/reentrancy_service.py): `backend/app/services/reentrancy_service.py`
- [Decompilation service](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/decompiler_service.py): `backend/app/services/decompiler_service.py`
- [Mythril analysis service](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/mythril_service.py): `backend/app/services/mythril_service.py`

### Workspace platform

- [Background scans and history](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/scans.py): `backend/app/routers/scans.py`
- [Scan worker](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/scan_runner.py): `backend/app/services/scan_runner.py`
- [File management](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/files.py): `backend/app/routers/files.py`
- [Projects](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/projects.py): `backend/app/routers/projects.py`
- [AI explanations](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/ai.py): `backend/app/routers/ai.py`
- [Grounded AI service](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/services/ai_service.py): `backend/app/services/ai_service.py`
- [Usage analytics](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/usage.py): `backend/app/routers/usage.py`

### Identity and persistence

- [Account and sessions](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Application database](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/db.py): `backend/app/db.py`
- [Platform records](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/models.py): `backend/app/models.py`
- [Backend application](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/main.py): `backend/app/main.py`

### Analysis integrations

- [Heimdall adapter](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/adapters/heimdall_adapter.py): `backend/app/adapters/heimdall_adapter.py`
- [Mythril adapter](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/adapters/mythril_adapter.py): `backend/app/adapters/mythril_adapter.py`
- [Tool runtime selection](https://github.com/hussainbasha559/smart-contract-analysis/blob/main/backend/app/adapters/runtime.py): `backend/app/adapters/runtime.py`

### Other components

- **User**
- **Heimdall and Mythril**

## Connections

- User → Dashboard: uses (evidence: `frontend/src/App.jsx`)
- Dashboard → Sign-in and registration: shows when signed out (evidence: `frontend/src/App.jsx`)
- Dashboard → Analyze workspace: shows workspace (evidence: `frontend/src/App.jsx`)
- Analyze workspace → API client: requests analysis (evidence: `frontend/src/pages/AnalyzePage.jsx`)
- Analyze workspace → Analysis panels: renders findings (evidence: `frontend/src/pages/AnalyzePage.jsx`)
- Sign-in and registration → API client: registers or logs in (evidence: `frontend/src/pages/AuthPage.jsx`)
- API client → Account and sessions: calls account endpoints (evidence: `frontend/src/services/api.js`)
- API client → Direct analysis API: calls analysis endpoints
- API client → Background scans and history: calls scan endpoints
- API client → File management: calls file endpoints
- API client → Projects: calls project endpoints
- API client → AI explanations: calls AI endpoints
- API client → Usage analytics: calls usage endpoints
- Backend application → Direct analysis API: registers router (evidence: `backend/app/main.py`)
- Backend application → Account and sessions: registers router (evidence: `backend/app/main.py`)
- Backend application → Background scans and history: registers router (evidence: `backend/app/main.py`)
- Backend application → File management: registers router (evidence: `backend/app/main.py`)
- Backend application → Projects: registers router (evidence: `backend/app/main.py`)
- Backend application → AI explanations: registers router (evidence: `backend/app/main.py`)
- Backend application → Usage analytics: registers router (evidence: `backend/app/main.py`)
- Direct analysis API → Bytecode validation: validates input (evidence: `backend/app/api/routes.py`)
- Direct analysis API → Analysis orchestration: requests analysis (evidence: `backend/app/api/routes.py`)
- Analysis orchestration → Opcode decoding: decodes bytecode (evidence: `backend/app/services/report_service.py`)
- Analysis orchestration → Decompilation service: requests decompilation (evidence: `backend/app/services/report_service.py`)
- Analysis orchestration → Mythril analysis service: requests symbolic analysis (evidence: `backend/app/services/report_service.py`)
- Analysis orchestration → Structural reentrancy check: runs heuristic (evidence: `backend/app/services/report_service.py`)
- Structural reentrancy check → Opcode decoding: uses instructions (evidence: `backend/app/services/reentrancy_service.py`)
- Mythril analysis service → Mythril adapter: invokes (evidence: `backend/app/services/mythril_service.py`)
- Decompilation service → Heimdall adapter: uses adapter
- Heimdall adapter → Tool runtime selection: selects execution mode (evidence: `backend/app/adapters/heimdall_adapter.py`)
- Mythril adapter → Tool runtime selection: selects execution mode (evidence: `backend/app/adapters/mythril_adapter.py`)
- Heimdall adapter → Heimdall and Mythril: runs Heimdall
- Mythril adapter → Heimdall and Mythril: runs Mythril
- Background scans and history → Scan worker: delegates scans (evidence: `backend/app/routers/scans.py`)
- Scan worker → Analysis orchestration: runs analysis
- AI explanations → Grounded AI service: requests explanations
- Account and sessions → Application database: persists accounts and sessions (evidence: `backend/app/routers/auth.py`)
- Application database → Platform records: maps records (evidence: `backend/app/db.py`)
- Backend application → Scan worker: recovers interrupted scans (evidence: `backend/app/main.py`)
