refactor: decompose 5 monolithic scripts into bounded-context modules#504
refactor: decompose 5 monolithic scripts into bounded-context modules#504
Conversation
Co-authored-by: pethers <[email protected]>
…les) Split the monolithic scripts/data-transformers.ts into 9 focused modules: - types.ts (90 lines) — shared interfaces - constants.ts (1126 lines) — i18n lookup tables - helpers.ts (356 lines) — utility functions - calendar.ts (149 lines) — event grid/watch points - content-generators.ts (670 lines) — article HTML generators - policy-analysis.ts (341 lines) — policy domain detection - document-analysis.ts (262 lines) — motion grouping/intel - metadata.ts (344 lines) — SEO/read-time/sources - index.ts (100 lines) — barrel re-export Original file reduced to 57-line re-export wrapper. All 1795 tests pass. Zero import changes needed in consumers. Co-authored-by: pethers <[email protected]>
…ertions Co-authored-by: pethers <[email protected]>
Co-authored-by: pethers <[email protected]>
…d-context modules article-template.ts (666 lines → 4 modules): - article-template/constants.ts (~190 lines) — i18n lookup tables - article-template/helpers.ts (~145 lines) — formatting, sanitisation, HTML sections - article-template/template.ts (~270 lines) — main generateArticleHTML - article-template/index.ts (~28 lines) — barrel re-export mcp-client.ts (810 lines → 4 modules): - mcp-client/transport.ts (~120 lines) — HTTP POST abstraction - mcp-client/document-types.ts (~65 lines) — doktyp normalisation - mcp-client/client.ts (~500 lines) — MCPClient class - mcp-client/index.ts (~105 lines) — singleton + convenience functions Note: Original barrel re-export files not yet updated for mcp-client.ts. All new module files created and ready. Co-authored-by: pethers <[email protected]>
Complete the mcp-client decomposition started in previous session: - mcp-client.ts now re-exports from mcp-client/ directory - Fixed transport.ts defensive headers access for test compatibility - All 1795 tests pass Co-authored-by: pethers <[email protected]>
…modules) Split into focused modules under generate-news-indexes/: - types.ts (~100 lines) — shared interfaces - constants.ts (~255 lines) — i18n config for 14 languages - helpers.ts (~430 lines) — article parsing, scanning, classification - template.ts (~470 lines) — HTML index page generation - index.ts (~120 lines) — barrel re-export + orchestration Original file reduced to 41-line barrel re-export. All 1795 tests pass. Co-authored-by: pethers <[email protected]>
… modules) Split into focused modules under generate-news-enhanced/: - types.ts (~40 lines) — local interfaces (TitleSet, BatchStatus, etc.) - config.ts (~222 lines) — CLI parsing, language config, shared MCP client - helpers.ts (~174 lines) — date formatting, article writing, quality validation - generators.ts (~400 lines) — week-ahead, committee, propositions, motions - index.ts (~264 lines) — orchestrator (generateNews) + barrel re-exports Original file reduced to 42-line barrel re-export. All 1795 tests pass. Co-authored-by: pethers <[email protected]>
- Add ArticleDisplayData import to template.ts - Remove generated week-ahead articles from commit Co-authored-by: pethers <[email protected]>
| import { | ||
| generateLanguageSwitcherNav, | ||
| generateAvailableLanguages, | ||
| } from './helpers.js'; |
| const f: FilterLabels = lang.filters; | ||
| const filename: string = langKey === 'en' ? 'index.html' : `index_${langKey === 'no' ? 'no' : langKey}.html`; | ||
| const mainIndex: string = langKey === 'en' ? 'index.html' : `index_${langKey === 'no' ? 'no' : langKey}.html`; | ||
| const isRTL: boolean = ['ar', 'he'].includes(langKey); |
There was a problem hiding this comment.
Pull request overview
This PR decomposes 5 monolithic TypeScript files (totaling 7,400+ lines) into 27 focused bounded-context modules averaging 200-400 lines each, following a divide-and-conquer architecture pattern with strict typing and comprehensive JSDoc.
Changes:
- Decomposed
data-transformers.ts(3453 lines → 9 modules),generate-news-indexes.ts(1311 → 5 modules),generate-news-enhanced.ts(1183 → 5 modules),mcp-client.ts(810 → 4 modules), andarticle-template.ts(666 → 4 modules) - Each original file becomes a thin barrel re-export (~35-57 lines) preserving the public API
- All 1795 tests pass, TypeScript strict mode compiles clean, zero breaking changes to consumers
Reviewed changes
Copilot reviewed 32 out of 34 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
scripts/mcp-client/transport.ts |
HTTP transport layer with fetch/Node.js HTTPS fallback |
scripts/mcp-client/document-types.ts |
Riksdag document type normalization (doktyp → English) |
scripts/mcp-client/client.ts |
Main MCPClient class with JSON-RPC 2.0 implementation |
scripts/mcp-client/index.ts |
Barrel re-export + singleton convenience functions |
scripts/generate-news-indexes/types.ts |
Type definitions for news index generation |
scripts/generate-news-indexes/constants.ts |
14-language localization configuration |
scripts/generate-news-indexes/helpers.ts |
Article parsing, classification, and scanning utilities |
scripts/generate-news-indexes/template.ts |
HTML template generation with Schema.org data |
scripts/generate-news-indexes/index.ts |
Orchestration and barrel re-export |
scripts/generate-news-enhanced/types.ts |
Local type definitions for enhanced generation |
scripts/generate-news-enhanced/config.ts |
CLI parsing, language config, shared state |
scripts/generate-news-enhanced/helpers.ts |
Article writing, quality validation, date formatting |
scripts/generate-news-enhanced/generators.ts |
Article generators for week-ahead, reports, propositions, motions |
scripts/generate-news-enhanced/index.ts |
Main orchestration and barrel re-export |
scripts/data-transformers/types.ts |
Shared data interfaces for transformation pipeline |
scripts/data-transformers/helpers.ts |
Low-level utilities (URL sanitization, date formatting, text cleaning) |
scripts/data-transformers/policy-analysis.ts |
Policy domain detection and analysis |
scripts/data-transformers/document-analysis.ts |
Document grouping and intelligence analysis |
scripts/data-transformers/calendar.ts |
Calendar event transformation and watch-point extraction |
scripts/data-transformers/index.ts |
Main barrel re-export preserving public API |
scripts/article-template/constants.ts |
Localization lookup tables for 14 languages |
scripts/article-template/helpers.ts |
Formatting, sanitization, HTML section generators |
scripts/article-template/template.ts |
Main article HTML template generator |
scripts/article-template/index.ts |
Barrel re-export |
scripts/mcp-client.ts |
Thin barrel re-export (810 → 35 lines) |
news/index_ja.html |
Japanese news index with article metadata |
Co-authored-by: pethers <[email protected]>
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
| "title": "野党の動議:再生可能エネルギー、財政、憲法改革が2月の議題を支配", | ||
| "date": "2026-02-24", | ||
| "type": "analysis", | ||
| "type": "prospective", |
There was a problem hiding this comment.
The article type has changed from "analysis" to "prospective" for this Japanese article. This is the only content change in the PR. Verify this is intentional - if the article "野党の動議:再生可能エネルギー、財政、憲法改革が2月の議題を支配" is indeed a prospective piece rather than analysis, this is correct. Otherwise, this may be an accidental change introduced during the refactoring.
Divide-and-conquer decomposition of the 5 largest scripts (totaling ~7,400 lines) into 27 focused modules with strict bounded contexts. Each original file becomes a thin barrel re-export, preserving all public API surfaces — zero consumer changes required.
Decompositions
data-transformers.ts(3453 → 9 modules): types, constants, helpers, calendar, content-generators, policy-analysis, document-analysis, metadata, indexgenerate-news-indexes.ts(1311 → 5 modules): types, constants, helpers, template, indexgenerate-news-enhanced.ts(1183 → 5 modules): types, config, helpers, generators, indexmcp-client.ts(810 → 4 modules): transport, document-types, client, indexarticle-template.ts(666 → 4 modules): constants, helpers, template, indexPattern
Each module directory follows the same structure:
types.ts— interfaces scoped to the bounded contextconstants.ts— lookup tables, i18n mapshelpers.ts— pure utility functionsindex.ts— barrel re-export defining the public APIResult
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.