VibORM

Internals Overview

Deep dive into VibORM's internal architecture

VibORM Internals

This section documents VibORM's internal architecture for contributors and advanced users who want to understand how the ORM works under the hood.

What You'll Learn

Design Principles

1. Type-First Design

VibORM is built with TypeScript types as the source of truth. Rather than generating types from a schema file (like Prisma), types are inferred directly from the schema definition at compile time.

// Types are inferred, not generated
const user = s.model({
  id: s.string().id().ulid(),
  name: s.string(),
  email: s.string().unique(),
});

// TypeScript knows the exact shape
type UserFields = (typeof user)["~"]["fields"];
// { id: StringField<...>, name: StringField<...>, email: StringField<...> }

2. Dual Validation

Every operation is validated twice:

  1. Compile-time - TypeScript catches type errors
  2. Runtime - ArkType schemas validate actual data

3. Normalization Pipeline

User-friendly shorthand syntax is normalized to canonical forms before reaching the query engine, simplifying SQL generation.

4. Separation of Concerns

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  Schema Layer   │────▶│  Client Layer   │────▶│  Query Engine   │
│  (Definition)   │     │  (Operations)   │     │  (Execution)    │
└─────────────────┘     └─────────────────┘     └─────────────────┘
        │                       │                       │
        ▼                       ▼                       ▼
   Type System            Type Guards           SQL Generation
   ArkType Schemas        Validation            Database Adapters

Quick Architecture Overview

Key Components

ComponentLocationPurpose
Model classsrc/schema/model/model.tsSchema definition entry point
Field classessrc/schema/fields/*/field.tsField type definitions
Relation classessrc/schema/relation/relation.tsRelationship definitions
Type helperssrc/schema/model/types/TypeScript type derivation
Runtime schemassrc/schema/model/runtime/ArkType schema builders
Clientsrc/client/Operation execution
Query Enginesrc/query-engine/SQL generation

Next Steps

Start with Architecture for a comprehensive system overview, or jump directly to the component you're interested in.

On this page