# decurity/semgrep-smart-contracts architecture

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

- Interactive diagram: https://gitdiagram.com/decurity/semgrep-smart-contracts
- Repository: https://github.com/decurity/semgrep-smart-contracts

## Overview

This repository is a Semgrep rule pack for smart-contract vulnerabilities and gas optimizations. The main workflow is that an engineer selects rules and supplies smart-contract source to Semgrep, which evaluates the rules and reports matches. The rules span Solidity security, performance and best practices, plus Cairo and Rust. The README documents local and registry-based use; implementation details of the external Semgrep engine are outside this repository.

Main entry points: [`solidity/security`](https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/security) (Security Rules), [`solidity/performance`](https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/performance) (Performance Rules), [`solidity/best-practice`](https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/best-practice) (Best Practices), [`cairo`](https://github.com/decurity/semgrep-smart-contracts/tree/master/cairo) (Cairo Rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_solidity["Solidity Rules"]
  node_security_rules["Security Rules"]
  node_performance_rules["Performance Rules"]
  node_best_practice_rules["Best Practices"]
end

subgraph group_other_languages["Other Languages"]
  node_cairo_rules["Cairo Rules"]
  node_rust_rules["Rust Rules"]
end

subgraph group_analysis["Scanning Workflow"]
  node_semgrep["Semgrep Engine"]
  node_findings["Rule Findings"]
end

node_engineer(("Engineer"))
node_contracts["Target Contracts"]
node_registry["Semgrep Registry"]

node_engineer -->|"runs scan"| node_semgrep
node_engineer -->|"supplies source"| node_contracts
node_semgrep -->|"scans"| node_contracts
node_security_rules -->|"configures"| node_semgrep
node_performance_rules -->|"configures"| node_semgrep
node_best_practice_rules -->|"configures"| node_semgrep
node_cairo_rules -->|"configures"| node_semgrep
node_rust_rules -->|"configures"| node_semgrep
node_semgrep -->|"reports matches"| node_findings
node_findings -->|"returns results"| node_engineer
node_registry -.->|"provides rules"| node_semgrep

click node_security_rules "https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/security"
click node_performance_rules "https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/performance"
click node_best_practice_rules "https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/best-practice"
click node_cairo_rules "https://github.com/decurity/semgrep-smart-contracts/tree/master/cairo"
click node_rust_rules "https://github.com/decurity/semgrep-smart-contracts/tree/master/rust"

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_security_rules,node_performance_rules,node_best_practice_rules toneBlue
class node_cairo_rules,node_rust_rules toneAmber
class node_semgrep,node_findings toneMint
class node_engineer,node_contracts,node_registry toneIndigo
```

## Components

### Solidity Rules

- [Security Rules](https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/security): `solidity/security`
- [Performance Rules](https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/performance): `solidity/performance`
- [Best Practices](https://github.com/decurity/semgrep-smart-contracts/tree/master/solidity/best-practice): `solidity/best-practice`

### Other Languages

- [Cairo Rules](https://github.com/decurity/semgrep-smart-contracts/tree/master/cairo): `cairo`
- [Rust Rules](https://github.com/decurity/semgrep-smart-contracts/tree/master/rust): `rust`

### Scanning Workflow

- **Semgrep Engine**
- **Rule Findings**

### Other components

- **Engineer**
- **Target Contracts**
- **Semgrep Registry**

## Connections

- Engineer → Semgrep Engine: runs scan
- Engineer → Target Contracts: supplies source
- Semgrep Engine → Target Contracts: scans
- Security Rules → Semgrep Engine: configures
- Performance Rules → Semgrep Engine: configures
- Best Practices → Semgrep Engine: configures
- Cairo Rules → Semgrep Engine: configures
- Rust Rules → Semgrep Engine: configures
- Semgrep Engine → Rule Findings: reports matches
- Rule Findings → Engineer: returns results
- Semgrep Registry → Semgrep Engine: provides rules
