> For the complete documentation index, see [llms.txt](https://entermirari.gitbook.io/entermirari-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://entermirari.gitbook.io/entermirari-docs/architecture/data-model.md).

# Data Model

Every user-scoped table follows the same shape:

* `id uuid primary key default gen_random_uuid()`
* `user_id uuid not null references auth.users(id) on delete cascade`
* `created_at`, `updated_at` timestamps
* Row-Level Security **enabled**
* RLS policies scoped to `auth.uid() = user_id`

## Tables

### `agent_connections`

```sql
create table public.agent_connections (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  name text not null,
  provider text not null,            -- 'hermes' | 'openrouter' | 'nous' | 'custom'
  base_url text not null,
  model text not null,
  status text not null default 'offline',
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);
```

### `conversations` & `messages`

```sql
create table public.conversations (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  agent_connection_id uuid references public.agent_connections(id) on delete set null,
  title text,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table public.messages (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  conversation_id uuid not null references public.conversations(id) on delete cascade,
  role text not null,                 -- 'system' | 'user' | 'assistant'
  content text not null,
  created_at timestamptz not null default now()
);
```

### `memory_nodes`

```sql
create table public.memory_nodes (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  label text not null,
  category text,
  strength real not null default 0.5,
  source text,
  created_at timestamptz not null default now()
);
```

### `skills`

```sql
create table public.skills (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  name text not null,
  description text,
  category text,
  status text not null default 'suggested',
  score real not null default 0,
  version integer not null default 1,
  template_prompt text,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);
```

### `mirror_reports`

```sql
create table public.mirror_reports (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  agent_connection_id uuid references public.agent_connections(id) on delete set null,
  title text,
  strengths jsonb not null default '[]',
  weaknesses jsonb not null default '[]',
  recommendations jsonb not null default '[]',
  suggested_prompt text,
  created_at timestamptz not null default now()
);
```

### `tasks`

```sql
create table public.tasks (
  id uuid primary key default gen_random_uuid(),
  user_id uuid not null,
  connection_id uuid references public.agent_connections(id) on delete set null,
  title text not null,
  description text,
  status text not null default 'pending',
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);
```

### `templates`

Templates are published bundles. The bundle payload lives in a `jsonb` column so the schema doesn't need to grow with every new skill field.

```sql
create table public.templates (
  id uuid primary key default gen_random_uuid(),
  author_id uuid not null,
  name text not null,
  description text,
  category text,
  payload jsonb not null,            -- { skills:[...], seed_memory:[...] }
  installs integer not null default 0,
  is_public boolean not null default false,
  created_at timestamptz not null default now()
);
```

## RLS pattern

Every table uses the same three policies:

```sql
alter table public.<t> enable row level security;

create policy "<t>_select_own" on public.<t>
  for select using (auth.uid() = user_id);

create policy "<t>_modify_own" on public.<t>
  for all using (auth.uid() = user_id) with check (auth.uid() = user_id);
```

For `templates`, public rows additionally allow `select` to anyone authenticated when `is_public = true`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://entermirari.gitbook.io/entermirari-docs/architecture/data-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
