Strategy library and Reports (teudb)
Every user keeps a library in teudb (the user database): per category (only tbs today) one level of folders, saved strategies, and a Reports section with its own folders. Code: backend/library/ (store, snapshots), API backend/app/api/library.py (/api/library, DEVELOPER rank like the TBS pages), UI frontend/src/pages/tbsLibrary.jsx (side panel, Save dialogs) and Reports.jsx (page /reports, sidebar "Reports").
Tables (migration b52d8f1a6c70 in backend/alembic_user, applied by pull.sh)
| Table | Content |
|---|---|
usr_folder | scope strategy or report, category, name, order; unique per user + scope + category + name. Deleting a folder keeps its items (they move to "no folder") |
usr_strategy | Saved strategy JSON (spec_json), engine, underlying, mode, param_hash, favorite, notes; unique per user + category + name. Replaces usr_tbs_strategy (rows copied by the migration, downgrade copies back) |
usr_report | List metadata: kind backtest or sweep, name, strategy link (+ name copy), underlying, range, summary headline, params, favorite, notes, size_bytes |
usr_report_blob | The payload, kept apart so lists never read it: json-gz snapshot (backtest) or npz price array (sweep) |
usrid is NULL only on a development machine with auth off.
Behaviour
- Strategies: the TBS side panel shows folders (expand, count), loose strategies, favorites first, search, and a three-dot menu per row (open, rename, duplicate, favorite, move, delete). The builder's Save opens a dialog (name, folder or new folder; Save replaces the same name, Save as new needs another). The old
/api/tbs/strategiesroutes still work and delegate to the library. - Backtest report: Save report on a finished run's results header copies the run (strategy, summary, daily curve, all trades) into teudb, so it outlives the run. Opening it on
/reportsuses the same Summary / Equity / Day-wise / Trades components, read only; the day filters (weekday, DTE, VIX, gap, previous-day) work from the stored trades throughGET /api/library/reports/{id}/view. - Bulk report: Save report on a finished sweep copies its compressed price array (about 3 to 12 MB). The standalone HTML is rebuilt on demand (
/reports/{id}/html) with the same live slippage / brokerage / charges recalculation, so it still opens after the sweep file is gone. - Deleting a strategy keeps the reports made from it (the name stays).
Limits
Per user: LIBRARY_MAX_REPORTS (default 200) reports and LIBRARY_MAX_REPORT_MB (default 500) MB in total; going over returns HTTP 413. The Reports page shows the usage bar.
Tests
cd backend; venv/Scripts/python -m pytest tests/test_library.py (store, ownership isolation, caps, snapshot round trip, bulk report with a 12 MB array, API).