refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack

- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched)
- Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations()
- Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation
- Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims
- Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution
- Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
This commit is contained in:
Boki 2026-11-27 00:11:50 -05:00
parent ce9e2df67c
commit 4cd6038063
432 changed files with 1247 additions and 44469 deletions

View file

@ -37,6 +37,20 @@ All 16 containers run from `/mnt/data/stockbot` (`docker compose --env-file .env
| | `loki` / `prometheus` | `3100` / `9090` | Centralized logs (`promtail`) & metrics |
| | `pgadmin` / `mongo-express` | `5050` / `8081` | Database admin UIs (LAN-only) |
### 2.1 `quant` (`125 GiB` RAM) Memory, Shared-Memory & Kernel Budget
Enforced via [docker-compose.quant.yml](../docker-compose.quant.yml) + `/etc/sysctl.d/99-stockbot.conf` (`vm.max_map_count = 1048576`):
| Component | Engine-Internal Cap | Container `mem_limit` | Required OS / Container Settings |
| --- | --- | --- | --- |
| **MongoDB `7.0.21`** (`stock`) | `--wiredTigerCacheSizeGB 16` (`8` outside bulk ETL) | `24g` | `ulimits.nofile = 1048576` |
| **QuestDB `10.2.0`** | `QDB_RAM_USAGE_LIMIT_BYTES=21474836480` (`20 GiB`), JVM `-Xms2g -Xmx4g` | `28g` | `ulimits.nofile = 1048576`, host `vm.max_map_count >= 1048576`, `bars_1m` `PARTITION BY MONTH` |
| **PostgreSQL `16.9`** (`trading_bot`) | `shared_buffers=4GB`, `effective_cache_size=16GB`, `work_mem=64MB`, `maintenance_work_mem=1GB` | `10g` | **`shm_size: 2g`** (prevents `64m` `/dev/shm` parallel hash-join/index errors) |
| **Dragonfly `v1.30.3`** | `--maxmemory=4gb --proactor_threads=4` | `5g` | Emulated cluster / hashtag locks |
| **DuckDB + Workers + `web-api`** | `SET memory_limit='6GB'; SET threads=4; SET temp_directory='/mnt/data/stockbot/tmp/duckdb'` per worker | `30g` total | Prevents DuckDB's default `80%` host-RAM (`~100 GiB`) per-worker allocation |
| **Monitoring & Admin** | Prometheus `--storage.tsdb.retention.time=15d` | `4g` total | Pinned versions across Prometheus, Loki, Grafana, Admin UIs |
| **Linux OS Page Cache** | — | **~24 GiB unallocated** | Keeps hot SN850X NVMe Parquet & QuestDB `mmap` pages resident |
---
## 3. Local Development vs `quant` Separation
@ -47,7 +61,7 @@ All 16 containers run from `/mnt/data/stockbot` (`docker compose --env-file .env
| **`qa` (`quant`)** | `docker-compose.yml` + `docker-compose.quant.yml` | `10.0.0.51:5432` (`trading_bot`) | `10.0.0.51:27017` (`stock`) | `10.0.0.51:27017` (`stock`, `MONGODB_READ_URI` for `data-pipeline`) | `10.0.0.51:6379` | `10.0.0.51:9000` |
| **Paper / Live (`9900K`)** | `docker-compose.prod.yml` (`M5`) | Isolated execution DB | None | Curated artifact pull only | Local `:6379` | Local `:9000` (90d hot window) |
> **Offline Local Snapshot:** The workstation's pre-migration Docker containers (`trading-bot-*`) are intentionally stopped with their local Docker volumes preserved untouched as a cold local fallback.
> **Side-by-Side Local Execution:** On the `91 GiB` workstation, `docker-compose.dev.yml` (`stock-bot-dev-*` on `5433`/`27018`/`6380`/`9100`) and `docker-compose.yml` (`trading-bot-*` local QA stack on `5432`/`27017`/`6379`/`9000`) use non-overlapping ports, networks, and volume namespaces so both stacks run simultaneously without conflict (`./scripts/docker.sh start --dev && ./scripts/docker.sh start --qa`).
---