phase-7_alpha: legacy code cleanup

This commit is contained in:
Sai Kiran Vella
2026-06-05 22:27:53 -04:00
parent 5185f03c12
commit a7108b448a
13 changed files with 31 additions and 983 deletions
+4 -33
View File
@@ -4,10 +4,7 @@ Guidance for working in this repository.
## Overview
`market-screener` is a Node.js project with two modes:
1. **CLI** — screens stocks, ETFs, and bonds via `npm start`, generates HTML reports
2. **Fastify API server** — powers the SvelteKit dashboard in the `ui/` subdirectory
`market-screener` is a Node.js project consisting of a Fastify API server that powers the SvelteKit dashboard in the `ui/` subdirectory.
Every asset is scored under two lenses:
@@ -26,10 +23,6 @@ ES module project (`"type": "module"`); use `import`/`export`, not `require`.
npm install # install dependencies
npm run dev # start API server (port 3000) + SvelteKit UI (port 5173) together
npm run server # API server only (port 3000)
npm start # CLI: Yahoo news → catalyst tickers → screener-report.html
npm start -- watch # CLI: default watchlist
npm start -- AAPL MSFT VOO # CLI: specific tickers
npm run finance # CLI: portfolio advice + SimpleFIN → finance-report.html
npm test # run all unit tests (node:test, zero external deps)
npm run test:watch # watch mode — uses verbose spec reporter
npm run format # format all server/bin/tests with Prettier
@@ -45,13 +38,8 @@ npm run ui:install # install UI dependencies (ui/ sub
```
bin/
screen.ts ← CLI screener entry point
finance.ts ← CLI personal finance entry point
server.ts ← Fastify API server entry point (imports buildApp from server/app.ts)
scripts/
summary-reporter.js ← custom node:test reporter (silent on pass, summary line at end)
prompts/
catalyst-analysis.md ← daily catalyst analysis playbook (LLM prompt + workflow)
@@ -66,8 +54,8 @@ server/
analyze.controller.ts ← POST /api/analyze (LLM analysis for a ticker set)
services/ ← business logic, no HTTP or I/O concerns
ScreenerEngine.ts ← orchestrates: fetch → score × 2. Methods: screenTickers() (pure data),
screenWithProgress() (CLI with stdout). Accepts { logger } option.
ScreenerEngine.ts ← orchestrates: fetch → score × 2. Method: screenTickers() → ScreenerResult.
Accepts injected YahooFinanceClient + BenchmarkProvider + { logger } option.
DataMapper.ts ← normalises Yahoo payload → flat asset data object.
Computes: DCF intrinsic value, analyst upside, 52W movement fields,
grossMargin, marketCap. Uses trailingPE. Preserves negative FCF.
@@ -109,10 +97,6 @@ server/
EtfScorer.ts ← expense gate + registry (cost, yield, volume, fiveYearReturn)
BondScorer.ts ← credit gate + spread/duration scoring
reporters/ ← HTML rendering, no business logic
HtmlReporter.ts ← render() → HTML string (server), generate() → writes file (CLI)
FinanceReporter.ts ← render() → HTML string (server), generate() → writes file (CLI)
config/
ScoringConfig.ts ← CREDIT_RATING_SCALE + ScoringRules (single source of truth for all
gates, weights, thresholds including analyst and dcf weights)
@@ -208,7 +192,6 @@ Scorer × 2 — StockScorer / EtfScorer / BondScorer, fully stateless
ScreenerEngine — derives Signal from comparing both verdicts
├── CLI path: screenWithProgress() → HtmlReporter.generate() → screener-report.html
└── API path: screenTickers() → JSON (with serialized displayMetrics) → SvelteKit UI
```
@@ -442,17 +425,6 @@ new ScreenerEngine({ logger: noopLogger })
---
## Reporter Pattern
Both reporters have two methods:
```ts
reporter.render(...) // → HTML string (use in server route responses)
reporter.generate(...) // → writes file to disk, returns path (use in CLI)
```
---
## SimpleFIN Auth Flow
1. User gets a Setup Token from https://beta-bridge.simplefin.org
@@ -497,7 +469,7 @@ tests/
```
Pre-commit hook runs `lint-staged` (Prettier) then `npm test`. Pre-push hook runs `npm test`.
Test output: silent on pass, shows only failures + one summary line (`scripts/summary-reporter.js`).
Test output uses the built-in `spec` reporter.
**Key unit:** `ytm` in `Bond.metrics` is stored as a percentage (e.g. `6.5` = 6.5%). `BondScorer._sanitize` divides by 100 before spread calculation.
@@ -525,7 +497,6 @@ This section is the single reference for where code lives and how to add feature
| `server/clients/` | External API connectors — one class per third-party system | No business logic; only I/O and protocol handling |
| `server/models/` | Domain entity classes — hold metrics and `getDisplayMetrics()` | No I/O; pure data + formatting |
| `server/scorers/` | Stateless pure scoring functions | No I/O, no state; `score(metrics, rules, marketContext)` only |
| `server/reporters/` | HTML rendering | No business logic; `render()` → string, `generate()` → file |
| `server/config/` | Constants and scoring gates/weights | No logic; change numbers here, not in scorers |
| `server/types/` | TypeScript interfaces and types | No logic; one `*.model.ts` per domain |
| `server/utils/` | Shared pure utilities | No domain knowledge |