๐งโ๐ง Canic ๐งโ๐ง โ Internet Computer Orchestration
Canic is a Rust toolkit for orchestrating Internet Computer (IC) canisters at scale. It packages the battle-tested patterns from large multi-canister deployments into a reusable crate: lifecycle macros, stable-memory helpers, orchestration ops, and endpoint bundles that keep your boundary layer thin while enforcing clean layering inside the canister graph.
The crate was historically known as ICU (Internet Computer Utilities). All core APIs have been renamed to Canic for the crates.io release.
Highlights
- ๐งฉ Bootstrap macros โ
canic_start!,canic_start_root!,canic_build!, andcanic_build_root!wire init/upgrade hooks, export endpoints, and validate config at compile time. - ๐ง State layers โ opinionated separation for stable memory, volatile state, ops/business logic, and public endpoints.
- ๐ Auth utilities โ composable guards (
auth_require_any!,auth_require_all!) for controllers, parents, whitelist principals, and more. - ๐๏ธ Stable memory ergonomics โ
ic_memory!,ic_memory_range!, andeager_static!manage IC stable structures safely across upgrades. - ๐ฆ WASM registry โ consistently ship/lookup child canister WASMs with hash tracking.
- โป๏ธ Lifecycle helpers โ shard policies, reserve pools, delegation sessions, and sync cascades keep fleets healthy.
- ๐งช Ready for CI โ Rust 2024 edition, MSRV 1.90, with
cargo fmt,cargo clippy -- -D warnings, andcargo testwired viamaketargets.
๐ Repository Layout
crates/canic/โ core library crate with orchestration primitives and macros.src/auth.rs&src/guard.rsโ reusable authorization helpers.src/cdk/โ IC CDK shims and patched utilities used by the macros.src/config/โ configuration loaders, validators, and schema helpers.src/env/โ IC mainnet configuration (canister IDs, SNSs etc.)src/interface/โ typed wrappers for IC management calls, ck-ledgers, and ICRC ledgers.src/macros/โ public macro entrypoints (canic_start!,canic_endpoints_*, memory helpers).src/memory/โ stable storage abstractions and registries built onic-stable-structures.src/ops/โ orchestration/business logic bridging memory and state layers.src/spec/โ representations of external IC specs (ICRC, NNS, SNS, etc.).src/state/โ volatile runtime state caches and registries.src/types/- shared domain typessrc/utils/โ time helpers, wasm utilities, etc.
crates/canisters/โ reference canisters that exercise the library end to end:root/orchestrator tying together shards, scaling, and delegation flows.shard/,shard_hub/โ shard lifecycle pair for pool management.scale/,scale_hub/โ reserve scaling agents demonstrating capacity workflows.delegation/โ delegation/session flows used in tests.blank/โ minimal canister template.
scripts/โ build, release, and environment helpers (app/,ci/,env/).
Getting Started
1. Install
Inside your workspace:
Or reference the workspace path if you pulled the repository directly.
2. Configure build.rs
Every canister crate should declare a config file (default name: canic.toml). Use one of the provided build macros:
// Root canister build.rs
// Non-root canister build.rs
The macro validates the TOML during compilation, emits the right cfg flags (e.g. canic_capability_delegation), and exposes the canonical config path via CANIC_CONFIG_PATH.
3. Bootstrap your canister
In lib.rs:
use *;
use EXAMPLE;
canic_start!; // or canic_start_root!() for the orchestrator canister
async
async
async
See crates/canisters/root and the hub/shard reference canisters under crates/canisters/* for end-to-end patterns, including WASM registries and endpoint exports.
4. Define your topology
Populate canic.toml with canister metadata, capabilities, and auth lists. The schema is documented in CONFIG.md.
Layered Architecture
Canic enforces clear separation between storage, transient state, orchestration logic, and public endpoints:
memory/โ stable data backed byic-stable-structures(e.g. shard registries, reserve pools).state/โ volatile caches and session stores that reset on upgrade.ops/โ business logic tying state + memory together (sharding policies, delegation flows, reserve management).endpoints/โ macro-generated IC entrypoints that delegate toops/and keep boundary code minimal.
Endpoints must call into ops/; they should never touch memory/ or state/ directly.
Capabilities & Endpoints
Delegation Sessions ๐
Enabled via delegation = true in canic.toml. When active, canic_endpoints_delegation!() (included automatically) exports:
canic_delegation_register(args)โ register a session for the caller wallet (update).canic_delegation_track(session_pid)โ record a requesting canister (update).canic_delegation_get(session_pid)โ fetch session metadata (query).canic_delegation_list_all()/canic_delegation_list_by_wallet(pid)โ controller-only admin views.canic_delegation_revoke(pid)โ parent-or-self revocation (update).
Sessions auto-clean during registrations; no manual cleanup endpoint is exposed.
Sharding ๐ฆ
canic::ops::shard assigns tenants to shard canisters according to a ShardPolicy (initial capacity, max shards, growth thresholds). Admin work flows through a single controller-only endpoint:
canic_sharding_admin
Command variants cover register, audit, drain, rebalance, and decommission flows. Your application is responsible for data migration around these moves.
Scaling & Reserve Pools โ๏ธ
canic_endpoints_scaling!()exposescanic_scaling_registry()for controller insight.- Root canisters manage spare capacity through
canic::ops::reserveand thecanic_reserve_*endpoints.
ICRC Support ๐
The base endpoint bundle includes:
icrc10_supported_standards()icrc21_canister_call_consent_message(request)
Register consent messages via state::icrc::Icrc21Registry for rich UX flows.
Tooling & DX
- Format:
cargo fmt --all - Lint:
make clippy - Test:
make test - Build release WASMs:
make build - Run the example suite:
make examplesorcargo build -p canic --examples
rust-toolchain.toml pins the toolchain so CI and local builds stay in sync.
Examples
Explore the runnable examples under crates/canic/examples/:
auth_rules.rsโ compose guard policies.minimal_root.rsโ bootstrap a bare-bones orchestrator.ops_create_canister.rsโ walk through the create-canister flow.shard_lifecycle.rsโ simulate register/assign/drain/rebalance operations.
Project Status & Contributing
Canic is the successor to the internal ICU toolkit. The repository is in the process of being opened for wider use; issues and PRs are currently limited to the core team. Follow AGENTS.md, VERSIONING.md, and RELEASE_GUIDE.md for workflow expectations.
License
Proprietary and confidential. See LICENSE for details.