AGENTS.md
src/lib/db/AGENTS.mdAGENTS.md
Quality
72/100
Scores the file, not the repository.Length
594 words
6 headings · 0 code blocksRepository
38k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# src/lib/db/ — SQLite Persistence Layer23**Purpose**: Domain-driven SQLite persistence. Each module owns a specific table set. Schema migrations are versioned and idempotent. No raw SQL in routes — all ops go through `src/lib/db/` modules.45Live count: `ls src/lib/db/*.ts | wc -l` (currently 95). Migrations: `ls src/lib/db/migrations/*.sql | wc -l` (currently 110).67---89## Core Infrastructure1011- **`core.ts`** — `getDbInstance()` returns singleton `better-sqlite3` with WAL journaling. Exports `rowToCamel()` (snake_case → camelCase), `encryptConnectionFields()` for provider credentials at rest. `SCHEMA_SQL` defines **17 base tables** (verify: `grep -c "CREATE TABLE" src/lib/db/core.ts` minus 1 for `_omniroute_migrations`).12- **`migrationRunner.ts`** — Applies versioned SQL files from `db/migrations/` inside transactions. Tracks applied migrations in `_omniroute_migrations`. Each migration is idempotent.13- **`db/migrations/`** — 110 SQL files (`001_initial_schema.sql` → `110_*.sql`). Each runs in a transaction, never fails partially.14- **`localDb.ts`** — Re-export layer only. Never add logic here.1516## Key Domain Modules1718| Module | Tables / Scope | Responsibility |19| ---------------------- | ------------------------- | --------------------------------------------------- |20| `providers.ts` | `provider_connections` | OAuth/API key provider registration and credentials |21| `models.ts` | `models` | Model definitions, capabilities, pricing |22| `combos.ts` | `combos`, `combo_targets` | Combo routing configs, target ordering |23| `apiKeys.ts` | `api_keys` | API key lifecycle, scopes, quota tracking |24| `settings.ts` | `settings` | KV store for system configuration |25| `secrets.ts` | `secrets` | Encrypted secret storage (API keys at rest) |26| `quotaSnapshots.ts` | `quota_snapshots` | Historical quota usage for analytics |27| `quotaPools.ts` | `quota_pools` | Quota-Share pool management |28| `creditBalance.ts` | `credit_balance` | Per-provider credit tracking |29| `compression.ts` | compression settings | Prompt compression pipeline config |30| `compressionCombos.ts` | `compression_combos` | Per-combo compression pipeline assignments |31| `evals.ts` | eval tables | Eval framework persistence |32| `webhooks.ts` | `webhooks` | Event-driven webhook subscriptions and logs |33| `reasoningCache.ts` | reasoning cache | Hybrid in-memory + SQLite reasoning replay |34| `skills.ts` | `skills` | Skill registration and metadata |35| `plugins.ts` | `plugins` | Plugin marketplace state |36| `gamification.ts` | gamification tables | Levels, badges, leaderboard |37| `notion.ts` | notion tables | Notion integration state |38| `obsidian.ts` | obsidian tables | Obsidian vault integration state |39| `files.ts` | file storage | Uploaded file management |40| `batches.ts` | batch processing | Batch job tracking |41| `featureFlags.ts` | feature flags | Runtime feature flag overrides |42| `backup.ts` | backup ops | Serialize/deserialize entire DB state |43| `cleanup.ts` | cleanup ops | Stale data purging |44| `healthCheck.ts` | health ops | DB health monitoring |45| `databaseSettings.ts` | database settings | DB-level configuration |4647Full list: `ls src/lib/db/*.ts | wc -l` (95 files). Drift detection: `npm run check:docs-counts`.4849## Encryption & Security5051- **Sensitive fields** (API keys, OAuth tokens, connection strings) encrypted at rest using AES-256-GCM52- **`encryptConnectionFields()`** in `core.ts` — automatic encryption when storing provider credentials53- **`secrets.ts`** — dedicated encrypted store for long-term secret handling54- **Never log** SQLite encryption keys or raw secrets; always use redacted values in logs5556## Adding a New Domain Module57581. Create `src/lib/db/[module].ts` with CRUD functions592. Export from `src/lib/localDb.ts` (add re-export)603. If new tables: create migration in `db/migrations/NNN_[description].sql`614. Migration runs automatically at startup via `migrationRunner.ts`625. Add unit tests in `tests/unit/db/`6364## Anti-Patterns6566- Raw SQL in routes — always use domain module functions67- Direct `prepare()` statements outside `db/` — breaks modularity68- Adding logic to `localDb.ts` — re-export layer only69- Barrel-importing from `localDb.ts` — import specific modules instead70- Skipping migrations for schema changes — all changes go through `db/migrations/`71
Also in diegosouzapw/OmniRoute
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| diegosouzapw/OmniRoute.github/copilot-instructions.md · 38k | Copilot instructions | teststyletesting-strategygit+1 | 46/100 | 3 days ago | |
| diegosouzapw/OmniRouteAGENTS.md · 38k | AGENTS.md | buildtestlint-formatstyle+12 | 84/100 | 3 days ago | |
| diegosouzapw/OmniRouteCLAUDE.md · 38k | CLAUDE.md | setupbuildtestlint-format+9 | 84/100 | yesterday | |
| diegosouzapw/OmniRouteGEMINI.md · 38k | GEMINI.md | testlint-formatarchsecurity+2 | 87/100 | 3 days ago | |
| diegosouzapw/OmniRouteopen-sse/services/AGENTS.md · 38k | AGENTS.md | styleperformancedeployment | 52/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago |
