# ADR 0008: Editor Module Boundaries and lib/bin Split

## Status

Accepted

## Context

The in-process editor grew to ~15k LOC in a flat `src/` root with manual plugin tuples in `main.rs`. Stubs, domain logic, and UI cross-cuts lived side by side, making navigation, review, and repeat render-target bugs harder to prevent (see Outstanding Issues Audit Phase A).

## Decision

1. **lib + bin split:** `crates/editor` exposes `editor` as a library (`src/lib.rs`) with a thin binary (`src/bin/main.rs`) that calls `configure_editor_app` and `register_game_editor_plugins`.

2. **Domain modules** under `src/` with flat re-exports at the crate root for stable `crate::scene_io` paths:
   - `scene/` — I/O, schema plugin, viewport render-target setup
   - `viewport/` — camera, selection, gizmos, render views, panel settings
   - `play/` — PIE session, editor mode state, net editor profiles
   - `assets/` — catalog, asset DB, prefab overrides
   - `project/` — workspace, project I/O, settings UI
   - `ext/` — extensibility, BRP, command queue, game panel adapters, hot reload
   - `history/` — undo commands + plugin (commands in submodule)
   - `ui/` — egui shell (asset browser split into submodules)

3. **`EditorPluginGroup`** in `lib.rs` is the single ordered plugin registration surface. Order is documented in `docs/editor/architecture.md`.

4. **Shared `scene` crate** owns schema stamp/migrate/validate; editor save/load and `xtask validate-levels` both use it.

5. **Dependency rules:**
   - `sim`, `protocol`, `settings`, `shared`, `scene` must not depend on `editor` or `bevy_egui`.
   - `editor` may depend on `game`; `game` must not depend on `editor`.
   - Game-specific editor panels register via `game::editor_ext::editor_panel_setups()`; editor wraps them as `EditorPlugin` (ADR 0007).

6. **Stub policy:** unwired modules live in domain folders (`net_editor`, `prefab_overrides` v2 fields), not at an ambiguous crate root.

## Consequences

- Third-party and game panels can embed or extend the editor library without forking the binary.
- Domain moves are incremental; flat re-exports avoid wide import churn.
- New workspace crates require an ADR update when they cross the dependency rules above.
- `cargo test -p editor` becomes viable as logic tests are added to the library.
