Skip to content

sksizer/rust-ontogen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

433 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ontogen CI License: MIT

A build-time code generator for ontology-driven Rust applications. Define your entities with annotated structs and Ontogen generates the full stack: persistence layer, CRUD store with lifecycle hooks, API forwarding, server transports (HTTP/IPC/MCP), and client libraries.

How It Works

Ontogen runs as a library in your build.rs. It parses #[ontology(...)] annotations on your structs and generates code through a pipeline of independent generators, each producing typed intermediate representations that downstream generators can optionally consume:

parse_schema -> SchemaOutput
    |-- gen_seaorm      -> SeaOrmOutput
    |-- gen_markdown_io -> ()
    |-- gen_dtos        -> ()
    `-- gen_store       -> StoreOutput
        `-- gen_api     -> ApiOutput
            |-- gen_servers -> ServersOutput  (Rust transports: Axum / Tauri IPC / MCP)
            `-- gen_clients -> ()             (TS bindings, HTTP / IPC clients, admin registry)

Each generator is a standalone function. You can run the full pipeline or pick individual stages. Upstream outputs are optional enrichment, not hard requirements.

Quick Example

Define an entity:

#[derive(OntologyEntity)]
#[ontology(entity, table = "tasks", directory = "tasks")]
pub struct Task {
    #[ontology(id)]
    pub id: String,
    pub name: String,
    pub description: Option<String>,

    #[ontology(relation(belongs_to, target = "Agent"))]
    pub assignee_id: Option<String>,

    #[ontology(relation(many_to_many, target = "Requirement"))]
    pub fulfills: Vec<String>,
}

Wire it in build.rs:

use ontogen::*;

fn main() {
    let schema = parse_schema(&SchemaConfig {
        schema_dir: "src/schema".into(),
    }).unwrap();

    let seaorm = gen_seaorm(&schema.entities, &SeaOrmConfig {
        entity_output: "src/persistence/entities/generated".into(),
        conversion_output: "src/persistence/conversions/generated".into(),
        skip_conversions: vec![],
    }).unwrap();

    let _store = gen_store(&schema.entities, Some(&seaorm), &StoreConfig {
        output_dir: "src/store/generated".into(),
        hooks_dir: Some("src/store/hooks".into()),
    }).unwrap();

    // ... continue with gen_api, gen_servers, gen_clients as needed
}

One cargo build generates your SeaORM entities, CRUD store methods, lifecycle hook stubs, API forwarding functions, and transport handlers. Add a new entity to your schema and rebuild -- everything updates automatically.

Key Features

  • Layered pipeline with typed intermediate representations between each stage
  • Independent generators that can run alone or be chained for richer output
  • SeaORM persistence including entity models, junction tables, and model conversions
  • Store generation with CRUD methods, update structs, and relation population
  • Lifecycle hooks scaffolded once per entity, never overwritten -- you own the hook files
  • API layer that merges generated CRUD with hand-written custom endpoints
  • Server transports for Axum HTTP, Tauri IPC, and MCP (Model Context Protocol)
  • Client generation for TypeScript and admin registries
  • Markdown I/O with parser dispatch, writers, and filesystem operations

Example Project

See examples/iron-log/ for a complete working example -- a weight-lifting tracker that demonstrates the full pipeline from schema entities through to a compiled Tauri app with generated TypeScript client.

cd examples/iron-log/src-tauri
cargo build

This generates 39 files across all layers from just 4 schema entity files.

Documentation

Known Issues

  • gen_clients is a no-op. Client generation (TypeScript transport, HTTP client, admin registry) is handled inline by servers::generate_transport(). To generate clients, include GeneratorConfig::Client(...) entries in the servers::Config.generators vec and call servers::generate_transport() directly. The gen_clients public API exists for forward compatibility but is not yet wired. See src/clients/mod.rs for details.

  • strip_wikilink stubs required. Generated store code for belongs_to and many_to_many fields imports crate::persistence::fs_markdown::parser::ontology::{strip_wikilink, strip_wikilink_opt, strip_wikilinks_vec}. Projects without markdown persistence must provide stub implementations. See the iron-log example for a reference.

Project Status

Ontogen is functional and in active development. Phases 1-5 of the pipeline are complete (schema parsing through client generation). See docs/tasks.md for the current backlog.

License

This project is licensed under MIT.

About

code generators

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Generated from sksizer/rust-template