# foundry-rs/forge-std architecture

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

- Interactive diagram: https://gitdiagram.com/foundry-rs/forge-std
- Repository: https://github.com/foundry-rs/forge-std

## Overview

Forge Standard Library is a Solidity utility library for Foundry tests and scripts. The main workflow is a test author using `Test` and its helpers to set up state, invoke assertions or inspect storage, and use Forge cheatcodes to control or observe execution. Other documented capabilities include TOML configuration, JSON/TOML utilities, chain metadata, invariant support, console output, and standard token interfaces. The README supports the documented helper behavior; source excerpts were not provided to verify internal wiring beyond that.

Main entry points: [`src/Vm.sol`](https://github.com/foundry-rs/forge-std/blob/master/src/Vm.sol) (Cheatcode Interface), [`src/Test.sol`](https://github.com/foundry-rs/forge-std/blob/master/src/Test.sol) (Test), [`src/Script.sol`](https://github.com/foundry-rs/forge-std/blob/master/src/Script.sol) (Script), [`src/StdCheats.sol`](https://github.com/foundry-rs/forge-std/blob/master/src/StdCheats.sol) (Cheat Wrappers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Test Entry Points"]
  node_test["Test<br/>[Test.sol]"]
  node_script["Script<br/>[Script.sol]"]
  node_vm["Cheatcode Interface<br/>[Vm.sol]"]
end

subgraph group_testing["Testing Helpers"]
  node_assertions["Assertions<br/>[StdAssertions.sol]"]
  node_cheats["Cheat Wrappers<br/>[StdCheats.sol]"]
  node_storage["Storage Discovery<br/>[StdStorage.sol]"]
  node_invariant["Invariant Helpers<br/>[StdInvariant.sol]"]
  node_errors["Revert Errors<br/>[StdError.sol]"]
end

subgraph group_data["Data And Config"]
  node_config["TOML Config<br/>[StdConfig.sol]"]
  node_toml["TOML Utilities<br/>[StdToml.sol]"]
  node_json["JSON Utilities<br/>[StdJson.sol]"]
  node_chains["Chain Metadata<br/>[StdChains.sol]"]
end

subgraph group_support["Runtime Support"]
  node_utils["General Utilities<br/>[StdUtils.sol]"]
  node_math["Math<br/>[StdMath.sol]"]
  node_constants["Constants<br/>[StdConstants.sol]"]
  node_console["Console Output<br/>[console.sol]"]
  node_console2["Console Output 2<br/>[console2.sol]"]
  node_safeconsole["Safe Console<br/>[safeconsole.sol]"]
  node_interfaces["Token Interfaces"]
  node_secp["Secp256k1<br/>[StdSecp256k1.sol]"]
end

node_author(("Test Author"))
node_foundry{{"Foundry Runtime"}}

node_author -->|"uses"| node_test
node_author -->|"uses"| node_script
node_test -->|"uses cheatcodes"| node_vm
node_script -->|"uses cheatcodes"| node_vm
node_vm -->|"dispatches to"| node_foundry
node_storage -->|"records storage access"| node_vm
node_cheats -->|"wraps cheatcodes"| node_vm
node_author -->|"asserts with"| node_assertions
node_author -->|"finds or writes"| node_storage
node_author -->|"sets test state"| node_cheats
node_author -->|"loads config"| node_config

click node_test "https://github.com/foundry-rs/forge-std/blob/master/src/Test.sol"
click node_script "https://github.com/foundry-rs/forge-std/blob/master/src/Script.sol"
click node_vm "https://github.com/foundry-rs/forge-std/blob/master/src/Vm.sol"
click node_assertions "https://github.com/foundry-rs/forge-std/blob/master/src/StdAssertions.sol"
click node_cheats "https://github.com/foundry-rs/forge-std/blob/master/src/StdCheats.sol"
click node_storage "https://github.com/foundry-rs/forge-std/blob/master/src/StdStorage.sol"
click node_invariant "https://github.com/foundry-rs/forge-std/blob/master/src/StdInvariant.sol"
click node_errors "https://github.com/foundry-rs/forge-std/blob/master/src/StdError.sol"
click node_config "https://github.com/foundry-rs/forge-std/blob/master/src/StdConfig.sol"
click node_toml "https://github.com/foundry-rs/forge-std/blob/master/src/StdToml.sol"
click node_json "https://github.com/foundry-rs/forge-std/blob/master/src/StdJson.sol"
click node_chains "https://github.com/foundry-rs/forge-std/blob/master/src/StdChains.sol"
click node_utils "https://github.com/foundry-rs/forge-std/blob/master/src/StdUtils.sol"
click node_math "https://github.com/foundry-rs/forge-std/blob/master/src/StdMath.sol"
click node_constants "https://github.com/foundry-rs/forge-std/blob/master/src/StdConstants.sol"
click node_console "https://github.com/foundry-rs/forge-std/blob/master/src/console.sol"
click node_console2 "https://github.com/foundry-rs/forge-std/blob/master/src/console2.sol"
click node_safeconsole "https://github.com/foundry-rs/forge-std/blob/master/src/safeconsole.sol"
click node_interfaces "https://github.com/foundry-rs/forge-std/tree/master/src/interfaces"
click node_secp "https://github.com/foundry-rs/forge-std/blob/master/src/StdSecp256k1.sol"

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_test,node_script,node_vm toneBlue
class node_assertions,node_cheats,node_storage,node_invariant,node_errors toneAmber
class node_config,node_toml,node_json,node_chains toneMint
class node_utils,node_math,node_constants,node_console,node_console2,node_safeconsole,node_interfaces,node_secp toneRose
class node_author,node_foundry toneIndigo
```

## Components

### Test Entry Points

- [Test](https://github.com/foundry-rs/forge-std/blob/master/src/Test.sol): `src/Test.sol`
- [Script](https://github.com/foundry-rs/forge-std/blob/master/src/Script.sol): `src/Script.sol`
- [Cheatcode Interface](https://github.com/foundry-rs/forge-std/blob/master/src/Vm.sol): `src/Vm.sol`

### Testing Helpers

- [Assertions](https://github.com/foundry-rs/forge-std/blob/master/src/StdAssertions.sol): `src/StdAssertions.sol`
- [Cheat Wrappers](https://github.com/foundry-rs/forge-std/blob/master/src/StdCheats.sol): `src/StdCheats.sol`
- [Storage Discovery](https://github.com/foundry-rs/forge-std/blob/master/src/StdStorage.sol): `src/StdStorage.sol`
- [Invariant Helpers](https://github.com/foundry-rs/forge-std/blob/master/src/StdInvariant.sol): `src/StdInvariant.sol`
- [Revert Errors](https://github.com/foundry-rs/forge-std/blob/master/src/StdError.sol): `src/StdError.sol`

### Data And Config

- [TOML Config](https://github.com/foundry-rs/forge-std/blob/master/src/StdConfig.sol): `src/StdConfig.sol`
- [TOML Utilities](https://github.com/foundry-rs/forge-std/blob/master/src/StdToml.sol): `src/StdToml.sol`
- [JSON Utilities](https://github.com/foundry-rs/forge-std/blob/master/src/StdJson.sol): `src/StdJson.sol`
- [Chain Metadata](https://github.com/foundry-rs/forge-std/blob/master/src/StdChains.sol): `src/StdChains.sol`

### Runtime Support

- [General Utilities](https://github.com/foundry-rs/forge-std/blob/master/src/StdUtils.sol): `src/StdUtils.sol`
- [Math](https://github.com/foundry-rs/forge-std/blob/master/src/StdMath.sol): `src/StdMath.sol`
- [Constants](https://github.com/foundry-rs/forge-std/blob/master/src/StdConstants.sol): `src/StdConstants.sol`
- [Console Output](https://github.com/foundry-rs/forge-std/blob/master/src/console.sol): `src/console.sol`
- [Console Output 2](https://github.com/foundry-rs/forge-std/blob/master/src/console2.sol): `src/console2.sol`
- [Safe Console](https://github.com/foundry-rs/forge-std/blob/master/src/safeconsole.sol): `src/safeconsole.sol`
- [Token Interfaces](https://github.com/foundry-rs/forge-std/tree/master/src/interfaces): `src/interfaces`
- [Secp256k1](https://github.com/foundry-rs/forge-std/blob/master/src/StdSecp256k1.sol): `src/StdSecp256k1.sol`

### Other components

- **Test Author**
- **Foundry Runtime**

## Connections

- Test Author → Test: uses
- Test Author → Script: uses
- Test → Cheatcode Interface: uses cheatcodes
- Script → Cheatcode Interface: uses cheatcodes
- Cheatcode Interface → Foundry Runtime: dispatches to
- Storage Discovery → Cheatcode Interface: records storage access
- Cheat Wrappers → Cheatcode Interface: wraps cheatcodes
- Test Author → Assertions: asserts with
- Test Author → Storage Discovery: finds or writes
- Test Author → Cheat Wrappers: sets test state
- Test Author → TOML Config: loads config
