Skip to content

dragginzgame/mimic

Repository files navigation

MSRV CI

Mimic β€” Data Model Framework for the Internet Computer

Funny / appealing cover image for Mimic100% Certified Swamp-Free

Battle-tested, schema-first data models for Internet Computer canisters. Built for Dragginz, now open to everyone.

Make It [ Matter     ] on the Internet Computer
          Magical
          Modular
          Multiplayer
          Monetisable
          Mainstream

πŸ‘‹ Overview

Mimic is a Rust framework for building strongly-typed, queryable data models on the Internet Computer.


✨ Highlights

  • Entity macros – define entities declaratively with schema attributes.
  • Query builder – type-safe filters, sorting, offsets, limits.
  • Stable storage – powered by ic-stable-structures B-Trees with predictable costs.
  • Automatic endpoints – mimic_build generates mimic_query_load, mimic_query_save, mimic_query_delete handlers.
  • Observability endpoints – mimic_snapshot, mimic_logs, mimic_metrics, mimic_metrics_reset ship automatically.
  • Text casing toolkit – sanitizers/validators for snake/kebab/title/camel cases that work across lists, maps, sets.
  • Integration with IC canisters – ergonomic mimic_start! and mimic_build! macros.
  • Testability – fixtures, query validation, index testing utilities.

⚑ Quickstart

  1. Install Rust 1.91.1+ (workspace uses edition 2024).
  2. Add Mimic to your Cargo.toml using the latest tag:
    [dependencies]
    mimic = { git = "https://github.com/dragginzgame/mimic.git", tag = "v0.29.0" }
  3. Declare an entity with the #[entity] macro and a primary key.
  4. Query your data via db!().load::<Entity>()....

See INTEGRATION.md for pinning strategies, feature flags, and troubleshooting tips.


πŸš€ Example

Define an entity

/// Rarity
/// Affects the chance of an item dropping or an event occurring.
#[entity(
    sk(field = "id"),
    fields(
        field(ident = "id", value(item(is = "types::Ulid"))),
        field(ident = "name", value(item(is = "text::Name"))),
        field(ident = "description", value(item(is = "text::Description"))),
        field(ident = "order", value(item(is = "game::Order"))),
        field(ident = "color", value(item(is = "types::color::RgbHex"))),
    ),
)]
pub struct Rarity {}

Query entities

#[query]
pub fn rarities() -> Result<Vec<RarityView>, mimic::Error> {
    let query = mimic::db::query::load()
        .filter(|f| {
            // (level >= 2 AND level <= 4) OR (name CONTAINS "ncon")
            (f.gte("level", 2) & f.lte("level", 4)) | f.contains("name", "ncon")
        })
        .sort(|s| s.desc("level"))
        .limit(100);

    let rows = db().load::<Rarity>().debug().execute(&query)?;
    Ok(rows.views())
}

πŸ—οΈ Project Layout

  • crates/mimic β€” core framework (entities, queries, schema, stores, types).
  • crates/mimic_build β€” canister codegen (build.rs β†’ actor.rs).
  • crates/mimic_common β€” shared utilities.
  • crates/mimic_schema β€” schema definitions and types.
  • crates/mimic_declare β€” proc-macros for schema/traits.
  • crates/mimic_tests β€” integration + design tests.
  • assets/ β€” artwork and documentation assets. scripts/ β€” release/version helpers.

πŸ“Ÿ Observability & Tooling

  • mimic_snapshot() β†’ live StorageReport with data/index/state breakdowns.
  • mimic_logs() β†’ in-memory log buffer (oldest β†’ newest).
  • mimic_metrics() β†’ EventReport for counters since since_ms.
  • mimic_metrics_reset() β†’ clears metrics state.

Examples:

dfx canister call <canister> mimic_snapshot
dfx canister call <canister> mimic_logs
dfx canister call <canister> mimic_metrics
dfx canister call <canister> mimic_metrics_reset

πŸ§‘β€πŸ’» Local Development

Workspace commands (see Makefile):

make check      # type-check workspace
make clippy     # lint with warnings denied
make test       # run all unit + integration tests
make fmt        # format the workspace (or fmt-check to verify)
make build      # release build

Pre-commit hooks run cargo fmt -- --check, cargo sort --check, and cargo sort-derives --check. Run any of the make fmt*, make clippy, or make check targets once to auto-install and enable them.

Style & conventions

  • Prefer ? + typed errors (thiserror) instead of panics in library code.
  • Keep functions focused; extract helpers when logic grows.
  • Import ergonomically: group paths per crate (e.g., use crate::{db, design};).
  • Use saturating arithmetic for counters and totals.
  • Co-locate small unit tests; integration/design tests live in crates/mimic_tests.
  • No backward-compatibility promise yetβ€”document breaking changes in the changelog.

🀝 Contributing & Support

We welcome issues, discussions, and pull requests now that the repository is public. To contribute:

  1. Fork and clone the repo.
  2. Install the toolchain (rustup toolchain install 1.91.1).
  3. Run make fmt-check && make clippy && make check && make test before opening a PR.
  4. Document user-visible changes in CHANGELOG.md under the latest heading.

Need help? Start with INTEGRATION.md, VERSIONING.md, or open a GitHub issue.


πŸ“Š Current Focus

  • Expanding documentation and runnable examples.
  • Improving error modeling (MimicError + nested domain errors).
  • Deepening test coverage across entity indexes and query paths.
  • Tracking store statistics & memory usage in production deployments.
  • Reducing WASM size produced by mimic_build.

πŸ“„ License

Licensed under either of:

  • Apache License, Version 2.0 (LICENSE-APACHE)
  • MIT license (LICENSE-MIT)

at your option.

About

Mimic Dapp Framework

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •