# Data Model: Chatbot PDF Extractor

**Date**: 2026-05-21

## Primary Database

### users

| Column | Notes |
|--------|--------|
| id | PK |
| name, email, password | Auth |
| role | ADMINISTRADOR \| OPERADOR |

### chat_messages

| Column | Notes |
|--------|--------|
| id | PK |
| session_id | e.g. `api-user-{user_id}` |
| role | user \| assistant |
| content | text |
| meta | JSON nullable |
| created_at | timestamp |

### documents

| Column | Notes |
|--------|--------|
| id | PK |
| user_id | FK users |
| filename, disk_path | storage local |
| status | processing \| completed \| failed |

### extracted_data

| Column | Notes |
|--------|--------|
| id | PK |
| document_id | FK documents |
| json_payload | JSON extracción o error |
| template_id | FK document_templates nullable |
| llm_model_used | string nullable |

### document_templates

| Column | Notes |
|--------|--------|
| id | PK |
| name | |
| target_table | tabla BD secundaria |
| identification_rules | JSON |
| json_schema | JSON esquema extracción |
| instructions | prompt LLM |

## Secondary Database (`secundaria`)

Tablas destino definidas por plantilla (ej. `plantilla_condiciones_economicas`).

| Column (typical) | Notes |
|------------------|--------|
| id | correlacionado con `reference_id` del upload |
| payload / datos_procesados | JSON — nombre vía `DB_SEC_JSON_COLUMN` |

## Session / Auth (client)

| Key | Storage |
|-----|---------|
| chatfront_access_token | sessionStorage (JWT string) |
