Documentation / Getting Started

Getting Started with moth

moth compiles and tools Moth projects. You use it from the command-line to create new projects, check them, build them and run the hot-reloading dev server.

Other tooling continues rapid development.

If you are running the compiler from the repository instead of an installed moth binary, use cargo run -- before the same commands:


    cargo run -- dev .
    cargo run -- check .
    cargo run -- build .
    

Commands

Command Use Notes

help

Prints the current command list and supported flags. Use this when the docs and local compiler may be out of sync.

--version

Prints the current compiler/tool version.

-v and -V are also accepted.

new html

Creates a complete HTML project scaffold.

Accepts an optional path and --force. If path is omitted, moth shows the current directory and asks for confirmation before scaffolding there. It then asks for a project name, a .gitignore choice and creates the default scaffold including src/@page.moth, an empty legacy lib/ placeholder, output manifests and an optional .gitignore. The lib/ folder has no special meaning in the accepted package design. Use structural +*.moth packages under the source tree for project-local packages.

check .

Runs project discovery, frontend compilation, type checking, HIR lowering and borrow validation without writing build artifacts.

Add --terse for compact one-line diagnostics.

dev .

Builds the project, starts a local dev server, watches files and reloads the browser when sources change. This is the main day-to-day command for working on HTML projects.

build .

Builds the project and writes output files.

Without --release, directory projects write to the configured dev output folder. With --release, they write to the configured release output folder.

tests

Runs the compiler integration test suite. (developer tool)

Mainly useful when working on the compiler itself. Use --terse for compact output or --backend html / --backend html_wasm to focus one backend profile.

Current flags

Flag Applies to Effect

--release

build, dev

Selects the release build profile and release output folder where supported.

--html-wasm

HTML builds Uses the experimental HTML-Wasm backend path. The JavaScript HTML backend currently targets Alpha.

--terse

check, tests

Prints compact diagnostics or test summaries for tools, logs and LLM workflows.

--force

new html only

Allows replacing existing scaffold-owned files after a confirmation warning. Never overwrites .gitignore or unrelated files.

--host, --port, --poll-interval-ms

dev only

Configures the local dev server. Defaults are `127.0.0.1`, `6342` and `300`.

Create a new HTML project

The scaffold creates a default project with config, a starter page, generated output folders, build manifests and an optional .gitignore. The HTML project builder itself has more rules than this page needs to cover. See the project structure guide for page layout, routing, assets, fragments and generated output details.

Start a new project:


    moth new html
    moth new html my-site
    moth new html ~/projects/my-site
    

If you omit the path, moth asks for confirmation in the current directory:


            No project path specified. Current directory: /your/path
            Create the new HTML project in this directory? y/N:
        

If the target directory already exists, you are given three choices:


            Target directory already exists:
            /path/to/target

            What do you want to do?
              1. Create the project inside this directory
              2. Create a new child folder for the project inside this directory
              3. Cancel

            Choose 1/2/3:
        

If the path contains directories that do not exist, moth asks before creating them:


    The project target contains directories that do not exist:
    /path/to/new/site

    Create the missing directories and scaffold the project there? y/N:
    

After the final directory is chosen, moth asks for the project name:


    Project name (press Enter to use project directory name):
    

Then it asks whether to add a .gitignore with Moth defaults:


    Add a .gitignore with Moth defaults? Y/n:
    

If .gitignore already exists, moth asks whether to append missing defaults instead of overwriting.

Generated project structure

A scaffolded project looks like this:


            project-root/
            ├── config.moth
            ├── src/
            │   └── @page.moth
            ├── lib/
            ├── dev/
            │   └── .moth_manifest
            ├── release/
            │   └── .moth_manifest
            └── .gitignore
        

Using --force

--force allows replacing scaffold-owned files when they already exist:


    moth new html my-site --force
    

It still asks for a second confirmation and never overwrites .gitignore or unrelated files.

After creation, check and run the project:


    cd my-site
    moth check .
    moth dev .
    

Run the dev server

dev handles normal day-to-day Moth project work. It builds the project, serves the generated files locally, watches for source changes and sends reload events to the browser.


    moth dev .
    

By default, open:


            http://127.0.0.1:6342/
        

Useful dev-server options:


    moth dev . --port 8080
    moth dev . --host 0.0.0.0
    moth dev . --poll-interval-ms 100
    

When a build fails, fix the reported error and save again. The dev server is designed around fast feedback rather than a manual rebuild loop.

Build a project

Use build when you want files written to disk without running the dev server.


    moth build .
    

For a release build:


    moth build . --release
    

For HTML projects, generated files are written under the configured output folder. The default scaffold currently uses dev for development output and release for release output.

Check without building

check gives the fastest correctness signal for editor loops and CI-style validation. It doesn't write output artifacts, but it runs the shared frontend diagnostics that all backends use.


    moth check .
    

Use terse mode when another tool will read the output:


    moth check . --terse
    

Terse diagnostics have a stable compact shape:


            E|type|src/@page.moth|4:12|Expected Bool, found Int|help=Use a Bool expression here.
            W|identifier_naming_convention|src/button.moth|1:1|Import alias case mismatch
        

Reading compiler errors

Moth uses the same formatted diagnostic system across the compiler front end and backend builders. That means syntax errors, type errors, config errors, file errors, borrow-checker errors, dev-server errors and backend errors use the same basic shape.

A normal diagnostic contains:

Example shape:


            Type Error (ಠ_ಠ) 🔥
            Declaration 'count' has incompatible initializer type. Expected 'Int', but found 'String'.

              --> src/@page.moth:6:17
                |
              6 | count Int = "wrong"
                |             ^^^^^^^
              Use an Int value here, or change the declaration type.
        

Read diagnostics from top to bottom:

  1. The kind tells you which part of the compiler rejected the program.
  2. The message tells you the actual rule that failed.
  3. The file/line/column points to the primary source location.
  4. The caret shows the token or expression the compiler is complaining about.
  5. The guidance lines are suggestions, not a separate error.

Error kinds

Kind Meaning Usual fix
Syntax Error The source text could not be parsed as Moth syntax. Check punctuation, block delimiters, template brackets, imports and declaration shape.
Type Error The expression type does not match the expected type. Check annotations, return types, function arguments, collection element types and contextual casts.
Language Rule Error The syntax is valid, but it violates a language rule. Check things like mutability, import visibility, unsupported feature surfaces, duplicate names or invalid top-level code.
Missing File or Directory The project references a file, directory, import path or output path that cannot be resolved. Check spelling, relative paths, `entry_root` and project config.
Malformed Config The project config exists but contains unsupported, missing or invalid settings. Check `config.moth` and backend-specific config rules.
Borrow Checker Violation The program violates Moth's access and ownership rules. Check mutable/exclusive access, later uses after possible moves and overlapping borrows.
Dev Server Issue The local server could not start, watch, build or serve the project correctly. Check port conflicts, host binding, project path, and file permissions.
Compiler Bug / HIR / LIR / WASM Generation Bug The compiler hit an internal invariant or unsupported backend path. Reduce the input if practical and report it. User code should receive structured errors instead of compiler bugs.

Warnings and future suggestions

Warnings are for code that can still compile but deserves attention. Current warnings include things like malformed CSS/HTML template content, large tracked assets, naming convention issues and import alias case mismatches.

Moth separates correctness from style pressure. The future suggest command will become the pedantic style and cleanup pass: closer to a full Clippy-style assistant for Moth code. Noisy suggestions such as unused variables, unused imports, unused declarations and more specific style improvements belong there.

The intended workflow will be:


    moth check .
    moth suggest .
    moth fmt .
    

For now, use check and the compiler's normal warnings as the practical baseline.

Planned moth extensions

moth will become the main Moth project tool, not a thin compiler launcher. Planned additions include:

The short-term rule is simple: dev for fast browser feedback, check for correctness and build when you want output files.