remodel-core

Introduction

remodel-core is a Rust library for database modeling — build ER diagrams, convert them to relational schemas, and generate SQL DDL.

remodel-core is the engine that powers Remodel — a desktop application for visual database modeling. It is also published as an independent Rust crate so you can embed it in your own tools and pipelines.

What it does

The library works in three layers, each building on the previous one:

LayerModulePurpose
Conceptualmodels::conceptualEntity-Relationship structures (entities, attributes, relationships, specializations)
Logicalmodels::logicalRelational schema (tables, columns, constraints, foreign keys)
PhysicalsqlSQL DDL generation per dialect

The transformation from conceptual → logical is handled by transform::conceptual_to_logical, and structural correctness is checked by the validation module.

Origin

remodel-core is a Rust reimplementation of the modeling engine of brModelo by Carlos Henrique Cândido. The type names and algorithm choices follow the original Java implementation closely, so brModelo .brM3 files can be migrated to the .remodel format with the companion migration functions.

Quick example

use remodel_core::prelude::*;

// 1. Build a conceptual model
let mut m = ConceptualModel::new("blog");

let post  = m.add_entity("Post");
let user  = m.add_entity("User");

m.add_primary_attribute(post, "id",    DataType::Integer)?;
m.add_attribute(AttributeOwner::Entity(post), "title", DataType::Varchar(255))?;
m.add_primary_attribute(user, "id",    DataType::Integer)?;
m.add_attribute(AttributeOwner::Entity(user), "email", DataType::Varchar(120))?;

m.relate("wrote", post, Cardinality::ZeroToMany)
 .with(user, Cardinality::OneToMany);

// 2. Validate
let diags = validate_conceptual(&m);
assert!(diags.iter().all(|d| d.severity != Severity::Error));

// 3. Convert to logical
let logical = m.to_logical()?;

// 4. Generate SQL
let sql = logical.to_sql(SqlDialect::Postgres);
println!("{sql}");

On this page