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

@ -1,23 +1,15 @@
# General utilities
`@stock-bot/utils` is a private workspace package for infrastructure-neutral general
helpers. Financial/feature calculations belong to `@stock-bot/calculations`, not here.
`@stock-bot/utils` is a private workspace package for infrastructure-neutral HTTP and
user-agent helpers. Financial/feature calculations belong to
[`@stock-bot/calculations`](../calculations/README.md), not here.
## Supported capabilities
- `@stock-bot/utils/fetch`: `fetch` and the type-only `FetchOptions`.
- `@stock-bot/utils/user-agent`: `getRandomUserAgent` selects from a fixed local list.
- `@stock-bot/utils/common`: `createProxyUrl` encodes proxy credentials; `sleep`
returns a timer-backed promise.
- `@stock-bot/utils/dates`: `utcDates` supplies `isWeekday`, `nextWeekday`,
`previousWeekday`, strict `parseDate` (`YYYY-MM-DD`) and `formatDate`.
The root explicitly exports these six runtime values (`fetch`, `getRandomUserAgent`,
`createProxyUrl`, `sleep`, `utcDates`, `dateUtils`) plus the `FetchOptions` type.
Capability subpaths avoid loading unrelated helpers. There are no wildcard/deep exports.
```ts
import { utcDates } from '@stock-bot/utils/dates';
import { fetch, type FetchOptions } from '@stock-bot/utils/fetch';
import { getRandomUserAgent } from '@stock-bot/utils/user-agent';
@ -26,54 +18,16 @@ const options: FetchOptions = {
timeout: 5_000,
};
const response = await fetch('https://example.com/data', options);
const next = utcDates.nextWeekday(utcDates.parseDate('2024-03-08'));
```
Fetch keeps its existing logging, Bun proxy, timeout and original-`Response` behavior.
Non-OK statuses are returned, not thrown. Timeout cancellation and caller cancellation
are not composed: a configured timeout currently replaces the supplied signal. The
user-agent list is not fingerprinting or a guarantee of provider access.
Date arithmetic is explicitly UTC, validates inputs and does not mutate the supplied
date. Weekdays are **not** exchange sessions: holidays, exchange time zones and trading
hours are not modeled. The deprecated `dateUtils` names (`isTradingDay`,
`getNextTradingDay`, `getPreviousTradingDay`, `formatDate`, `parseDate`) remain
as aliases for migration, not as verified trading-calendar APIs. This replaces the old
environment-dependent local weekday arithmetic; use `utcDates` in new code.
`@stock-bot/invariants` is the only runtime workspace dependency. `LoggerLike`
from `@stock-bot/logger` is type-only. No databases, configuration initialization,
application service containers or mandatory native bindings may be added here.
## Calculation migration and removals
The financial modules and OHLCV helpers were **relocated/preserved**, not discarded:
- Reviewed returns/analytics/window math and OHLCV processing:
`@stock-bot/calculations` and its explicit capability subpaths.
- All 105 formerly active calculation functions with their original bodies:
`@stock-bot/calculations/legacy`, an opt-in historical API, not reviewed core.
- All seven disabled numerical/indicator prototypes:
non-executable source-verified snapshots in `libs/calculations/research/`.
See [the calculation contract](../calculations/README.md) and
[the complete cleanup audit](../../docs/cleanup-audit.md) for readiness, preserved test
scenarios and deliberate removals. The empty `analyzePortfolio` placeholder remains
removed because it calculated nothing.
Import assertions directly from `@stock-bot/invariants`; the redundant utility assertion
facade was removed, not its functionality. Import domain types from `@stock-bot/types`.
No finance compatibility re-export is added to the general utility package.
`@stock-bot/invariants` is the only runtime workspace dependency. `LoggerLike` from
`@stock-bot/logger` is type-only. Import assertions directly from `@stock-bot/invariants`
and domain types from `@stock-bot/types`.
## Verify
From the repository root:
```sh
bun run test:utils
bun run test:calculations
bun run check
```
The root gate includes general-utility and handler HTTP-consumer tests, calculation
regressions and architecture checks for the explicit APIs and dependency boundaries.