# @leumas/schemas

Canonical Leumas data model — Drizzle (libSQL/SQLite) tables + drizzle-zod validators + enums. DB-agnostic definitions, no runtime connection.


The **canonical Leumas data model** — one source of truth for every product/engine/service.

- **Drizzle tables** (`src/schema/*`) for **libSQL/SQLite** (`drizzle-orm/sqlite-core`).
- **drizzle-zod validators** (`src/validators.js`) — insert/select schemas derived from the tables.
- **Enums** (`src/enums.js`) — role/status/type vocabularies shared as arrays.

**DB-agnostic definitions only — no connection.** The runtime client, migrations, seed, and the generic
repository live in [`@leumas/db`](../db). The dynamic (schema-less) CRUD connector lives in
`shared/engines/middleware`. Both point at the same libSQL file.

```js
import * as schema from '@leumas/schemas/schema';   // drizzle(client, { schema })
import { users, memberships, ROLES, insertUserSchema } from '@leumas/schemas';
```

## Tables (grouped)

- **identity** — `users`, `admins`, `temporary_users`, `leumas_ids`, `sessions`
- **rbac** — `roles`, `permissions`, `user_roles`, `role_permissions`
- **monetization** — `memberships`, `dev_api_keys`, `token_transactions`
- **gamification** — `level_badge_definitions`, `user_badge_unlocks`, `user_experience_events`
- **social** — `posts`, `post_media`, `comments`, `post_likes`, `comment_likes`, `friendships`,
  `friend_requests`, `conversations`, `conversation_members`, `messages`, `message_reads`, `notifications`

## Conventions

- Text UUID primary keys (`crypto.randomUUID()`); timestamps as epoch-ms integers.
- Mongo embedded arrays → child/join tables (`post_media`, `post_likes`, `conversation_members`, …).
- Tokens are whole integers ($1 each); `token_transactions` is an append-only ledger.
- Supersedes the legacy Mongoose `@leumas-tech/leumas-schemas` and `leumas-schema-library`.


---
Source: shared/packages/schemas/README.md
Canonical: https://docs.leumas.tech/p/packages/schemas
