# Schema Overview

The Prax schema is a declarative language for defining your data models, relationships, and database configuration in a single, type-safe file.

## What is a Schema?

A Prax schema is a text file (located at `prax/schema.prax`) that serves as the single source of truth for your database structure. It defines:

- Datasources - Database connection configuration
- Generators - Code generation settings and plugins
- Models - Database tables and their columns
- Enums - Type-safe enumerated values
- Relations - Connections between models
- Views - Read-only aggregated data

Prax uses your schema to generate type-safe Rust code, create database migrations, and validate your queries at compile time.

## Minimal Schema

Here's the simplest possible schema to get started:

## Complete Example

A production-ready schema demonstrating all major features:

## Schema Components

Click on any component to learn more:

### Datasources & Generators

Configure database connections, code generation output, and plugins.

### Models

Define database tables, primary keys, indexes, and constraints.

### Fields & Types

Scalar types, type modifiers, default values, and database-specific types.

### Relations

One-to-one, one-to-many, many-to-many relationships and referential actions.

### Attributes

Field and model attributes for validation, mapping, defaults, and more.

### Enums

Type-safe enumerated values with database-level enforcement.

### Views

Read-only database views with custom SQL for aggregations and joins.

## Project Structure

Prax uses a dedicated `prax/` directory for the schema and migrations:

## Schema Workflow

The typical workflow when working with Prax schemas:

1

#### Define Schema

Write your models, enums, and relations in `prax/schema.prax`

2

#### Generate Client

Run `prax generate` to create type-safe Rust code

3

#### Create Migration

Run `prax migrate dev` to generate SQL migration files

4

#### Deploy

Run `prax migrate deploy` to apply migrations to production

## Next Steps

Ready to dive deeper? Start with Models to learn how to define your database tables, then explore Fields & Types for the full type system.

Learn about Models → Quick Start Guide