Sample projects
Try command-line applications, reusable libraries, Rust integration, HTTP, and Low replacements. Each project includes nagi.toml and instructions.
On this page
Seven examples for libraries and foundations
| Project | What it demonstrates |
|---|---|
| Pricing CLI | Validate input and call a shared calculation interface; switch between Nagi and Rust implementations |
| JSON report | Reuse the CLI's library and aggregate valid rows while handling invalid ones |
| Read JSON with Rust | Use serde_json and convert results to a Nagi class and Result |
| Rust async operation | Await a Tokio timer from Nagi |
| Custom HTTP foundation | Pass a Nagi function to Axum/Tokio and serve HTTP without opening a database |
| Low calculation kernel | Replace a High implementation with Low while keeping the application's calls |
| Modules and aliases | Distinguish same-named classes and use one type through a module name and a from alias |
See libraries and Rust assets for the structure. Both pricing applications need shared/; obtain the whole sample directory.
Run a project
You need Rust/Cargo, Nagi, and a toolchain that can build applications on your OS. See setup and first run.
From the repository root:
nagic check --project test-nagi-code/library-examples/rust-json
nagic run --project test-nagi-code/library-examples/rust-json
Inside a project's directory, nagic check and nagic run use the same configuration. The pricing CLI waits for input; the HTTP foundation runs until Ctrl+C.
Selecting just a source file skips its neighboring nagi.toml. Use --project or a command without a source filename inside the directory to include its Rust, Low, and dependency settings.
Read complete applications
| Project | Contents |
|---|---|
| Task management | Browser UI, JSON API, and SQLite persistence |
| Result API | Invalid input, missing data, DB failures, and recovery |
| Inventory | Typed JSON input, CRUD, and aggregation |
| Rust bridge | CRC-32, serde_json, and async Rust functions |
| Fractal | Console output and distribution as an executable |
Each README explains its inputs, outputs, and limits. Passing these examples does not establish support for every Rust crate or a complete production HTTP/database foundation.
Verify the examples during development
With Python 3 and a built nagic, verify the seven projects' checks, native builds, output, and HTTP responses:
python scripts/verify_library_examples.py --compiler /path/to/nagic
The script compares both pricing implementations, checks module and type aliases, malformed JSON, and async errors, compares High/Low results, and verifies HTTP 400/404 responses, the body limit, and shutdown. It builds projects sequentially and shares the dependency cache.
On Unix it checks a clean exit after SIGINT. On Windows it terminates the process and checks that the listener closes; check console Ctrl+C manually using the HTTP sample's instructions.