Project Structure
After zyvor init and zyvor dev, your project looks like this:
my-api/
├── Cargo.toml
├── src/
│ └── main.rs
└── .zyvor/
├── schema.zyvor ← you edit this
├── .env ← DATABASE_URL (gitignored)
├── config.toml ← structured config
├── .gitignore ← ignores .env
├── generated/ ← CLI writes this, you never edit it
│ ├── mod.rs
│ ├── user/
│ │ ├── mod.rs
│ │ └── types.rs
│ ├── post/
│ │ ├── mod.rs
│ │ └── types.rs
│ └── ...
└── migrations/
├── 0001_initial.sql
├── 0002_schema_update.sql
└── snapshot.json
What each piece is for
| Path | Owner | Commit to git? |
|---|---|---|
schema.zyvor | you | ✅ yes — it’s your source of truth |
.env | you | ❌ no — credentials |
config.toml | you | ⚠️ only if it has no secrets |
generated/ | CLI | ✅ recommended (see below) |
migrations/*.sql | CLI | ✅ yes — this is your schema history |
migrations/snapshot.json | CLI | ✅ yes — needed for diffing |
Why one folder per model
Zyvor doesn’t emit a single giant entities.rs. Each model gets a folder:
| File | Contains |
|---|---|
user/mod.rs | User entity, UserModel, typed fields, relations |
user/types.rs | UserCreate, UserUpdate, and their trait impls |
generated/mod.rs | re-exports everything flat |
Two benefits: a 30-model schema stays navigable, and you can open one file to see exactly what Zyvor generated for one table.
Because generated/mod.rs re-exports, you import flat anyway:
#![allow(unused)]
fn main() {
#[path = "../.zyvor/generated/mod.rs"]
mod generated;
use generated::{User, UserCreate, UserModel, Post, PostModel};
}
Commit generated code or not?
Recommendation: commit it.
- Reviewers can see what your schema change actually produced.
- CI builds without running the CLI first.
- Anyone cloning gets a compiling project immediately.
The tradeoff is diff noise on schema changes. If you’d rather not, add
.zyvor/generated/ to .gitignore and run zyvor generate in CI before building —
but then snapshot.json and migrations/ must still be committed.
Never edit generated/
The next zyvor dev save overwrites it. If you need extra behaviour, write it
in your own module:
#![allow(unused)]
fn main() {
// src/models.rs — your code, safe from regeneration
use crate::generated::UserModel;
impl UserModel {
pub fn display_name(&self) -> String {
format!("{} ({})", self.name, self.email)
}
}
}
Rust lets you add inherent impls to a type from another module in the same crate. That’s your extension point.