Files
SubMiner/docs/architecture/layering.md
T
sudacode 90fc7cf940 refactor(main): fold remaining main-deps builders into their handlers (#308)
* refactor(main): drop remaining pass-through main-deps builders

Jellyfin client-info/setup-window/remote, overlay shortcuts/visibility/
layout/window-factory, config hot-reload, and startup bootstrap factory
builders only forwarded deps. Callers now pass deps to the handlers
directly; createWatchConfigPathHandler moves into config-hot-reload-handlers.

* refactor(main): fold small-logic main-deps builders into their handlers

Tray click, mpv client factory, startup bootstrap exit callbacks, overlay
runtime options, and dictionary roots/runtime builders move their logic
into the owning handler or call site. The two duplicated dictionary-root
builders become one createBuildDictionaryRootsHandler(vendorDirName).

* refactor(main): fold cli command context builders into the factory

createCliCommandContextFactory now adapts appState and main services to
the CLI command context deps directly (socket-path change notification,
texthooker port/websocket URL, browser-open default). The pass-through
cli-command-context-main-deps and cli-command-context-deps layers are
removed; their behavioural tests now run against the factory's context.

* refactor(main): fold subtitle tokenization builder into the mpv composer

The tokenizer deps builder's logic (known-word lookup recording and the
character-dictionary gate on name matching) becomes
buildTokenizerRuntimeOptions in mpv-runtime-composer, tested through the
composer. The MeCab check and dictionary prewarm handlers move to
subtitle-tokenization-warmup.ts, and the unused BuiltMainDeps type is
removed from composer contracts.

* refactor(main): drop redundant tokenizer deps keys and cast

* refactor(main): end the main-deps builder pattern

mpv-main-event-main-deps becomes mpv-main-event-binding-deps
(createMpvMainEventBindingDeps), returning the binding deps directly
instead of a thunk; it owns the subtitle-recording state. The will-quit
cleanup adapter likewise returns its deps directly, and the pass-through
app-lifecycle activate builders are removed.

* docs: drop references to main-deps builders
2026-10-31 14:07:07 -07:00

1.7 KiB

Layering Rules

Status: active
Last verified: 2026-05-23
Owner: Kyle Yasuda
Read when: deciding whether a dependency direction is acceptable

Preferred Dependency Flow

  1. src/main.ts
  2. src/main/ composition and runtime adapters
  3. src/core/services/ focused services
  4. src/core/utils/ and other pure helpers

Renderer, launcher, plugin, and stats each keep their own local layering and should not become a grab bag for unrelated cross-runtime behavior.

Rules

  • Keep src/main.ts thin; wire, do not implement.
  • Pass deps straight to a handler factory (createXHandler({...})). Do not add deps builders (createBuild*MainDepsHandler, *-main-deps.ts) that re-wrap deps. Adaptation logic (defaults, appState getters/setters, shared state) belongs in the handler or in a named adapter that returns the deps directly.
  • Prefer injecting dependencies from src/main/ instead of reaching outward from core services.
  • Keep side effects explicit and close to composition boundaries.
  • Put reusable business logic in focused services, not in top-level lifecycle files.
  • Keep renderer concerns in src/renderer/; avoid leaking DOM behavior into main-process code.
  • Treat launcher/*.ts and the runtime bootstrap generators as source of truth for launcher behavior. scripts/build-launcher.ts creates dist/launcher; never hand-edit those artifacts.

Smells

  • main.ts grows because logic was not extracted
  • service reaches directly into unrelated runtime state
  • renderer code depends on main-process internals
  • docs-site page becomes the only place internal architecture is explained