> ## Documentation Index
> Fetch the complete documentation index at: https://docs.avyratech.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Schema Overview

> Database schema organization and conventions.

# Schema Overview

Tonnex uses **Drizzle ORM** for type-safe database access. All schemas live in `packages/db/src/schema/`.

## Schema Files

| File           | Entities                                                       |
| -------------- | -------------------------------------------------------------- |
| `auth.ts`      | profiles, organizations, org\_memberships                      |
| `locations.ts` | regions, locations, godowns, warehouse\_tenancy                |
| `vehicles.ts`  | vehicles, vehicle\_leases, vehicle\_loans, vehicle\_transfers  |
| `trips.ts`     | trips, trip\_crew, sub\_contracted\_trips                      |
| `clients.ts`   | clients, client\_delivery\_points, client\_pricing             |
| `hr.ts`        | persons, person\_designations, attendance                      |
| `payroll.ts`   | pay\_structures, payroll\_entries                              |
| `invoicing.ts` | invoices, invoice\_line\_items, credit\_notes                  |
| `rbac.ts`      | permissions, roles, role\_permissions, user\_role\_assignments |
| `audit.ts`     | audit\_logs                                                    |

## Conventions

* **Table names**: `snake_case` (plural)
* **Column names**: `snake_case` in DB, `camelCase` in TypeScript
* **Every table** has `org_id` (except system tables)
* **Primary keys**: UUID with `defaultRandom()`
* **Timestamps**: `created_at` and `updated_at` with timezone

## Running Migrations

```bash theme={null}
pnpm db:generate   # Generate SQL from schema changes
pnpm db:push       # Push schema directly (development)
pnpm db:migrate    # Apply migrations (production)
pnpm db:studio     # Open Drizzle Studio
```
