# fuellabs/sway architecture

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

- Interactive diagram: https://gitdiagram.com/fuellabs/sway
- Repository: https://github.com/fuellabs/sway

## Overview

Sway is a Rust-inspired smart-contract language and toolchain for Fuel. Its broad workflow is authoring Sway code, using Forc and language tooling, and compiling programs for the Fuel ecosystem; the repository also includes testing, documentation, debugging, migration, and publishing tools. The sampled sources show several internal relationships, especially IR utilities and test execution, but do not expose the complete compiler or CLI orchestration. Unverified workflow links are therefore dashed and uncited.

Main entry points: [`sway-ir/src/context.rs`](https://github.com/fuellabs/sway/blob/master/sway-ir/src/context.rs) (IR context), [`forc-util/src/lib.rs`](https://github.com/fuellabs/sway/blob/master/forc-util/src/lib.rs) (Forc utilities), [`forc-test/src/execute.rs`](https://github.com/fuellabs/sway/blob/master/forc-test/src/execute.rs) (Test execution), [`forc/src/cli`](https://github.com/fuellabs/sway/tree/master/forc/src/cli) (Forc CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_toolchain["Forc and packages"]
  node_forc_cli["Forc CLI"]
  node_package_manager["Package management"]
  node_shared_utilities["Forc utilities<br/>[lib.rs]"]
  node_bytecode_utils["Bytecode utilities<br/>[bytecode.rs]"]
  node_locking["Filesystem locking<br/>[fs_locking.rs]"]
  node_restricted["Restricted operations<br/>[restricted.rs]"]
  node_transaction_utils["Transaction utilities<br/>[tx_utils.rs]"]
end

subgraph group_compiler["Language compiler"]
  node_parser["Parser and AST<br/>[parser.rs]"]
  node_type_checker["Semantic and type analysis"]
  node_type_engine["Type engine<br/>[engine.rs]"]
  node_type_parameters["Type parameters<br/>[type_parameter.rs]"]
  node_type_unifier["Type unification<br/>[unifier.rs]"]
  node_source_map["Source mapping<br/>[source_engine.rs]"]
  node_diagnostics["Compiler diagnostics<br/>[handler.rs]"]
  node_assembly["Assembly generation"]
  node_source_spans["Source spans<br/>[span.rs]"]
end

subgraph group_ir["Intermediate representation"]
  node_ir_context["IR context<br/>[context.rs]"]
  node_ir_parser["IR parser<br/>[parser.rs]"]
  node_ir_types["IR types<br/>[irtype.rs]"]
  node_ir_passes["IR pass manager<br/>[pass_manager.rs]"]
  node_ir_printer["IR printer<br/>[printer.rs]"]
  node_ir_pretty["IR formatting<br/>[pretty.rs]"]
  node_storage_keys["Storage keys<br/>[storage_key.rs]"]
end

subgraph group_developer_tools["Developer tools"]
  node_lsp["Language server<br/>[server.rs]"]
  node_formatter["Code formatter"]
  node_documentation["Documentation generator"]
  node_debugger["Debugger"]
  node_migration["Code migration"]
  node_publisher["Package publisher"]
end

subgraph group_runtime["Testing and runtime"]
  node_test_runner["Test execution<br/>[execute.rs]"]
  node_test_setup["Test setup<br/>[setup.rs]"]
  node_ecal["VM syscall handling<br/>[ecal.rs]"]
end

node_author(("Sway developer"))
node_fuel_vm["Fuel VM"]

node_author -.->|"uses"| node_forc_cli
node_forc_cli -.->|"invokes"| node_package_manager
node_forc_cli -.->|"compiles with"| node_parser
node_parser -.->|"feeds analysis"| node_type_checker
node_type_engine -->|"uses"| node_type_parameters
node_type_engine -->|"uses"| node_type_unifier
node_type_checker -.->|"lowers to"| node_ir_context
node_ir_context -->|"printed by"| node_ir_printer
node_ir_types -->|"uses"| node_ir_context
node_ir_types -->|"formats with"| node_ir_pretty
node_ir_passes -->|"registers"| node_ir_printer
node_storage_keys -->|"stores in"| node_ir_context
node_storage_keys -->|"uses"| node_ir_types
node_ir_context -.->|"compiled to"| node_assembly
node_source_map -->|"tracks"| node_source_spans
node_test_runner -->|"prepares tests"| node_test_setup
node_test_runner -->|"uses"| node_ecal
node_test_runner -.->|"executes on"| node_fuel_vm
node_shared_utilities -->|"exposes"| node_bytecode_utils
node_shared_utilities -->|"exposes"| node_locking
node_shared_utilities -->|"exposes"| node_restricted
node_shared_utilities -->|"exposes"| node_transaction_utils

click node_forc_cli "https://github.com/fuellabs/sway/tree/master/forc/src/cli"
click node_package_manager "https://github.com/fuellabs/sway/tree/master/forc-pkg/src"
click node_parser "https://github.com/fuellabs/sway/blob/master/sway-parse/src/parser.rs"
click node_type_checker "https://github.com/fuellabs/sway/tree/master/sway-core/src/semantic_analysis"
click node_type_engine "https://github.com/fuellabs/sway/blob/master/sway-core/src/type_system/engine.rs"
click node_type_parameters "https://github.com/fuellabs/sway/blob/master/sway-core/src/type_system/ast_elements/type_parameter.rs"
click node_type_unifier "https://github.com/fuellabs/sway/blob/master/sway-core/src/type_system/unify/unifier.rs"
click node_source_map "https://github.com/fuellabs/sway/blob/master/sway-types/src/source_engine.rs"
click node_diagnostics "https://github.com/fuellabs/sway/blob/master/sway-error/src/handler.rs"
click node_ir_context "https://github.com/fuellabs/sway/blob/master/sway-ir/src/context.rs"
click node_ir_parser "https://github.com/fuellabs/sway/blob/master/sway-ir/src/parser.rs"
click node_ir_types "https://github.com/fuellabs/sway/blob/master/sway-ir/src/irtype.rs"
click node_ir_passes "https://github.com/fuellabs/sway/blob/master/sway-ir/src/pass_manager.rs"
click node_ir_printer "https://github.com/fuellabs/sway/blob/master/sway-ir/src/printer.rs"
click node_ir_pretty "https://github.com/fuellabs/sway/blob/master/sway-ir/src/pretty.rs"
click node_storage_keys "https://github.com/fuellabs/sway/blob/master/sway-ir/src/storage_key.rs"
click node_assembly "https://github.com/fuellabs/sway/tree/master/sway-core/src/asm_generation"
click node_lsp "https://github.com/fuellabs/sway/blob/master/sway-lsp/src/server.rs"
click node_formatter "https://github.com/fuellabs/sway/tree/master/swayfmt/src"
click node_documentation "https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-doc/src/render"
click node_debugger "https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-debug/src/server"
click node_migration "https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-migrate/src"
click node_publisher "https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-publish/src"
click node_test_runner "https://github.com/fuellabs/sway/blob/master/forc-test/src/execute.rs"
click node_test_setup "https://github.com/fuellabs/sway/blob/master/forc-test/src/setup.rs"
click node_ecal "https://github.com/fuellabs/sway/blob/master/forc-test/src/ecal.rs"
click node_shared_utilities "https://github.com/fuellabs/sway/blob/master/forc-util/src/lib.rs"
click node_bytecode_utils "https://github.com/fuellabs/sway/blob/master/forc-util/src/bytecode.rs"
click node_locking "https://github.com/fuellabs/sway/blob/master/forc-util/src/fs_locking.rs"
click node_restricted "https://github.com/fuellabs/sway/blob/master/forc-util/src/restricted.rs"
click node_transaction_utils "https://github.com/fuellabs/sway/blob/master/forc-util/src/tx_utils.rs"
click node_source_spans "https://github.com/fuellabs/sway/blob/master/sway-types/src/span.rs"

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_forc_cli,node_package_manager,node_shared_utilities,node_bytecode_utils,node_locking,node_restricted,node_transaction_utils toneBlue
class node_parser,node_type_checker,node_type_engine,node_type_parameters,node_type_unifier,node_source_map,node_diagnostics,node_assembly,node_source_spans toneAmber
class node_ir_context,node_ir_parser,node_ir_types,node_ir_passes,node_ir_printer,node_ir_pretty,node_storage_keys toneMint
class node_lsp,node_formatter,node_documentation,node_debugger,node_migration,node_publisher toneRose
class node_test_runner,node_test_setup,node_ecal,node_author,node_fuel_vm toneIndigo
```

## Components

### Forc and packages

- [Forc CLI](https://github.com/fuellabs/sway/tree/master/forc/src/cli): `forc/src/cli`
- [Package management](https://github.com/fuellabs/sway/tree/master/forc-pkg/src): `forc-pkg/src`
- [Forc utilities](https://github.com/fuellabs/sway/blob/master/forc-util/src/lib.rs): `forc-util/src/lib.rs`
- [Bytecode utilities](https://github.com/fuellabs/sway/blob/master/forc-util/src/bytecode.rs): `forc-util/src/bytecode.rs`
- [Filesystem locking](https://github.com/fuellabs/sway/blob/master/forc-util/src/fs_locking.rs): `forc-util/src/fs_locking.rs`
- [Restricted operations](https://github.com/fuellabs/sway/blob/master/forc-util/src/restricted.rs): `forc-util/src/restricted.rs`
- [Transaction utilities](https://github.com/fuellabs/sway/blob/master/forc-util/src/tx_utils.rs): `forc-util/src/tx_utils.rs`

### Language compiler

- [Parser and AST](https://github.com/fuellabs/sway/blob/master/sway-parse/src/parser.rs): `sway-parse/src/parser.rs`
- [Semantic and type analysis](https://github.com/fuellabs/sway/tree/master/sway-core/src/semantic_analysis): `sway-core/src/semantic_analysis`
- [Type engine](https://github.com/fuellabs/sway/blob/master/sway-core/src/type_system/engine.rs): `sway-core/src/type_system/engine.rs`
- [Type parameters](https://github.com/fuellabs/sway/blob/master/sway-core/src/type_system/ast_elements/type_parameter.rs): `sway-core/src/type_system/ast_elements/type_parameter.rs`
- [Type unification](https://github.com/fuellabs/sway/blob/master/sway-core/src/type_system/unify/unifier.rs): `sway-core/src/type_system/unify/unifier.rs`
- [Source mapping](https://github.com/fuellabs/sway/blob/master/sway-types/src/source_engine.rs): `sway-types/src/source_engine.rs`
- [Compiler diagnostics](https://github.com/fuellabs/sway/blob/master/sway-error/src/handler.rs): `sway-error/src/handler.rs`
- [Assembly generation](https://github.com/fuellabs/sway/tree/master/sway-core/src/asm_generation): `sway-core/src/asm_generation`
- [Source spans](https://github.com/fuellabs/sway/blob/master/sway-types/src/span.rs): `sway-types/src/span.rs`

### Intermediate representation

- [IR context](https://github.com/fuellabs/sway/blob/master/sway-ir/src/context.rs): `sway-ir/src/context.rs`
- [IR parser](https://github.com/fuellabs/sway/blob/master/sway-ir/src/parser.rs): `sway-ir/src/parser.rs`
- [IR types](https://github.com/fuellabs/sway/blob/master/sway-ir/src/irtype.rs): `sway-ir/src/irtype.rs`
- [IR pass manager](https://github.com/fuellabs/sway/blob/master/sway-ir/src/pass_manager.rs): `sway-ir/src/pass_manager.rs`
- [IR printer](https://github.com/fuellabs/sway/blob/master/sway-ir/src/printer.rs): `sway-ir/src/printer.rs`
- [IR formatting](https://github.com/fuellabs/sway/blob/master/sway-ir/src/pretty.rs): `sway-ir/src/pretty.rs`
- [Storage keys](https://github.com/fuellabs/sway/blob/master/sway-ir/src/storage_key.rs): `sway-ir/src/storage_key.rs`

### Developer tools

- [Language server](https://github.com/fuellabs/sway/blob/master/sway-lsp/src/server.rs): `sway-lsp/src/server.rs`
- [Code formatter](https://github.com/fuellabs/sway/tree/master/swayfmt/src): `swayfmt/src`
- [Documentation generator](https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-doc/src/render): `forc-plugins/forc-doc/src/render`
- [Debugger](https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-debug/src/server): `forc-plugins/forc-debug/src/server`
- [Code migration](https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-migrate/src): `forc-plugins/forc-migrate/src`
- [Package publisher](https://github.com/fuellabs/sway/tree/master/forc-plugins/forc-publish/src): `forc-plugins/forc-publish/src`

### Testing and runtime

- [Test execution](https://github.com/fuellabs/sway/blob/master/forc-test/src/execute.rs): `forc-test/src/execute.rs`
- [Test setup](https://github.com/fuellabs/sway/blob/master/forc-test/src/setup.rs): `forc-test/src/setup.rs`
- [VM syscall handling](https://github.com/fuellabs/sway/blob/master/forc-test/src/ecal.rs): `forc-test/src/ecal.rs`

### Other components

- **Sway developer**
- **Fuel VM**

## Connections

- Sway developer → Forc CLI: uses
- Forc CLI → Package management: invokes
- Forc CLI → Parser and AST: compiles with
- Parser and AST → Semantic and type analysis: feeds analysis
- Type engine → Type parameters: uses (evidence: `sway-core/src/type_system/engine.rs`)
- Type engine → Type unification: uses (evidence: `sway-core/src/type_system/engine.rs`)
- Semantic and type analysis → IR context: lowers to
- IR context → IR printer: printed by (evidence: `sway-ir/src/context.rs`)
- IR types → IR context: uses (evidence: `sway-ir/src/irtype.rs`)
- IR types → IR formatting: formats with (evidence: `sway-ir/src/irtype.rs`)
- IR pass manager → IR printer: registers (evidence: `sway-ir/src/pass_manager.rs`)
- Storage keys → IR context: stores in (evidence: `sway-ir/src/storage_key.rs`)
- Storage keys → IR types: uses (evidence: `sway-ir/src/storage_key.rs`)
- IR context → Assembly generation: compiled to
- Source mapping → Source spans: tracks (evidence: `sway-types/src/source_engine.rs`)
- Test execution → Test setup: prepares tests (evidence: `forc-test/src/lib.rs`)
- Test execution → VM syscall handling: uses (evidence: `forc-test/src/execute.rs`)
- Test execution → Fuel VM: executes on
- Forc utilities → Bytecode utilities: exposes (evidence: `forc-util/src/lib.rs`)
- Forc utilities → Filesystem locking: exposes (evidence: `forc-util/src/lib.rs`)
- Forc utilities → Restricted operations: exposes (evidence: `forc-util/src/lib.rs`)
- Forc utilities → Transaction utilities: exposes (evidence: `forc-util/src/lib.rs`)
