--- title: Modules & Imports description: Organizing code across files with module declarations and path-based imports. icon: FolderTree --- Mist organizes code through a file-system based module system with explicit path imports. ## Module Declarations Each `.mist` file declares itself as a module with `pub module name;` at the top. A `package.mist` file acts like `mod.rs` — it is the entry point for its directory. ```mist // src/utils/helper.mist pub module helper; pub void greet() { println!("Hello!"); } ``` ```mist // src/utils/package.mist pub module utils; // This module exports submodules and items ``` ## Imports Use the `use` keyword with a path to bring items from other modules or external crates into scope. ```mist use std::fs; use std::process; use std::path::Path; use std::collections::HashMap; // Import specific items use my_module::Helper; ``` ### Visibility Items can be re-exported with a visibility modifier on the import: ```mist pub use internal::format; ``` ## Sidefiles Any non-`.mist` file in `src/` (e.g., `.rs`, `.toml`, data files) is treated as a **sidefile** — it is copied directly into the output directory `.mist/src/` during transpilation. This allows you to keep Rust helper files or configuration alongside your Mist source. ```text src/ ├── main.mist ├── helper.rs # copied to .mist/src/helper.rs └── config/ └── data.json # copied to .mist/src/config/data.json ``` ## Project Structure A typical Mist project looks like this: ``` my-project/ ├── Cargo.toml ├── Mist.toml ├── src/ │ ├── main.mist │ ├── my_api/ │ │ ├── package.mist │ │ ├── methods.mist │ │ └── utils.mist └── .mist/ └── src/ ├── main.rs └── my_api/ ├── mod.rs ├── methods.rs └── utils.rs ``` The `.mist/src/` directory contains the transpiled Rust output.