Overview
All PrePrompt records live in MongoDB under thepreprompts collection. The backend
never keeps a separate in-memory store—each API read/write goes through the repository
defined in src/services/database/repositories/preprompt.repository.ts, which also
initialises the indexes described below.
Document shape
key: unique identifier referenced by clients throughpreprompt_key.public_value: friendly string rendered in the UI.masked_value: injected after the system prompt; never exposed to clients.description,tags: optional metadata for catalog filtering.is_deleted: soft-delete flag used by admin workflows.
Indexes
| Name | Keys | Notes |
|---|---|---|
preprompts_key_unique | { key: 1 } | Enforces unique keys (automatic revival if a deleted key is reused). |
preprompts_is_deleted | { is_deleted: 1, key: 1 } | Speeds up admin listing & catalog queries. |
Access patterns
| Operation | Repository method | Notes |
|---|---|---|
| Create | create(data) | Inserts with timestamps, defaulting is_deleted=false. |
| Update | update(id, payload) | Automatically bumps updated_at. |
| Soft delete | softDelete(id) | Marks is_deleted=true while retaining history. |
| List (admin) | findAll(includeDeleted) | Supports auditing by toggling deleted rows. |
| List (public) | listPublicOptions() | Returns only { key, public_value, description, tags }. |