Project Layout

Forge is flexible on how you structure your project. By default, the structure is:

.
β”œβ”€β”€ foundry.toml
β”œβ”€β”€ lib
β”‚Β Β  └── forge-std
β”‚Β Β      β”œβ”€β”€ foundry.toml
β”‚Β Β      β”œβ”€β”€ LICENSE-APACHE
β”‚Β Β      β”œβ”€β”€ LICENSE-MIT
β”‚Β Β      β”œβ”€β”€ package.json
β”‚Β Β      β”œβ”€β”€ README.md
β”‚Β Β      β”œβ”€β”€ scripts
β”‚Β Β      β”œβ”€β”€ src
β”‚Β Β      └── test
β”œβ”€β”€ README.md
β”œβ”€β”€ script
β”‚Β Β  └── Counter.s.sol
β”œβ”€β”€ src
β”‚Β Β  └── Counter.sol
└── test
    └── Counter.t.sol

8 directories, 11 files
  • You can configure Foundry’s behavior using foundry.toml.
  • Remappings are specified in remappings.txt.
  • The default directory for contracts is src/.
  • The default directory for tests is test/, where any contract with a function that starts with test is considered to be a test.
  • Dependencies are stored as git submodules in lib/.

You can configure where Forge looks for both dependencies and contracts using the --lib-paths and --contracts flags respectively. Alternatively you can configure it in foundry.toml.

Combined with remappings, this gives you the flexibility needed to support the project structure of other toolchains such as Hardhat and Truffle.

For automatic Hardhat support you can also pass the --hh flag, which sets the following flags: --lib-paths node_modules --contracts contracts.