Project Structure
Every Fe project follows a standard structure with a manifest file and source directory.
Directory Layout
Section titled “Directory Layout”A minimal Fe project looks like this:
my-project/├── fe.toml└── src/ └── lib.feAs your project grows:
my-project/├── fe.toml└── src/ ├── lib.fe # Entrypoint ├── token.fe # Additional modules ├── utils.fe └── messages/ ├── mod.fe # Submodule entrypoint └── transfer.feThe fe.toml Manifest
Section titled “The fe.toml Manifest”The fe.toml file defines your ingot’s metadata and dependencies:
[ingot]name = "my_project"version = "1.0.0"
[dependencies]# Dependencies go hereThe [ingot] Section
Section titled “The [ingot] Section”Every fe.toml requires an [ingot] section with:
| Field | Required | Description |
|---|---|---|
name | Yes | The ingot name (used for imports) |
version | Yes | Semantic version string |
[ingot]name = "token_library"version = "0.1.0"The name must be a valid identifier. Use underscores instead of hyphens:
# Goodname = "my_token"
# Bad - hyphens not allowedname = "my-token"The src/ Directory
Section titled “The src/ Directory”All Fe source files live in the src/ directory. The compiler discovers files matching the pattern src/**/*.fe.
The Entrypoint: src/lib.fe
Section titled “The Entrypoint: src/lib.fe”Every ingot must have a src/lib.fe file. This is the entrypoint that defines what the ingot exports:
// Re-export items from other modulespub use token::Tokenpub use messages::Transfer
// Define items directlypub struct Config { pub max_supply: u256}Organizing with Modules
Section titled “Organizing with Modules”Split code across multiple files for better organization:
pub use token::Tokenpub use utils::calculate_fee
// src/token.fepub contract Token { // ...}
// src/utils.fepub fn calculate_fee(amount: u256) -> u256 { amount / 100}Submodules
Section titled “Submodules”Create subdirectories with mod.fe files for deeper organization:
src/├── lib.fe└── messages/ ├── mod.fe # Required for submodule ├── transfer.fe └── approval.fepub use transfer::Transferpub use approval::ApprovalCreating a New Project
Section titled “Creating a New Project”To create a new Fe project:
-
Create the project directory:
Terminal window mkdir my_projectcd my_project -
Create
fe.toml:[ingot]name = "my_project"version = "0.1.0" -
Create the source directory and entrypoint:
Terminal window mkdir srctouch src/lib.fe -
Add your code to
src/lib.fe:pub contract MyContract {// ...}
Summary
Section titled “Summary”| Component | Purpose |
|---|---|
fe.toml | Manifest with name, version, dependencies |
[ingot] | Required section with name and version |
src/ | Contains all source files |
src/lib.fe | Required entrypoint |
src/**/*.fe | Additional source files |