Skip to content

refactor(app): extract crates/app UseCase layer (Phase 6 prep) #66

Open

Description

@utof

Per docs/research/architecture_audit.md §3.1 and §4.1 — the #1 top-10 action from that audit.

Problem

No application-service layer exists. Every Tauri command in crates/desktop/src/commands.rs (1158 LOC) re-orchestrates scan/search/tag workflows. Every future axum handler (Phase 6) and plugin (Phase 8) would re-duplicate the same orchestration. Estimated ~1050 LOC of scan duplication would hit at Phase 6 without the extraction.

Shape

One UseCase struct per user-visible workflow:

pub struct ScanUseCase {
    files: Arc<dyn FileRepository>,
    volumes: Arc<dyn VolumeRepository>,
    hasher: Arc<dyn Hasher>,
    events: Arc<EventBus>,
}

impl ScanUseCase {
    pub fn new(...) -> Self { ... }
    pub async fn execute(&self, cmd: ScanCommand) -> Result<ScanReport, ScanError> {
        // orchestration
    }
}
  • Concrete struct, Arc<dyn Port> fields, one async fn execute, zero generic parameters.
  • AppContainer wires use cases together; #[derive(Clone)] so axum's with_state and Tauri's .manage() accept it trivially.
  • EventBus lives in core (events are domain concepts); DbEventHandler in db; LogEventHandler in a small telemetry module.

Audit's rationale: this is the pattern real mature Rust codebases converge on (zed's Entity<Project>, rust-analyzer's Analysis, crates.io's AppState) — NOT the hex-arch textbook shape.

Blocker status

Now unblocked: the FileRepository/VolumeRepository &mut self → &self refactor landed in commit 081c694 (task #72). Use cases can now share Arc<dyn FileRepository> across handlers.

Starting set

scan, search, tag, volume, metadata. Add import later.

Rejected alternatives

  • Generic struct ScanUseCase<F: FileRepository, V: VolumeRepository> — LLMs drift on where-clauses; adding a port cascades through call sites.
  • Enum-dispatch across use cases — maintenance sink at ~15 use cases.
  • Skipping the UseCase struct for "simple" operations — consistency beats elegance when LLMs author.

Source

docs/research/architecture_audit.md §3.1, §3.2, §3.3, §4.1 (especially the ranked pattern-comparison table in §4.1).

Execution hint

Needs a proper /superpowers:brainstorming → writing-plans cycle — this is architectural, not a lint sweep. Block Phase 6 (issue #59) on this landing first.

Activity

  1. added
    type/chore
    on Apr 19, 2026
  2. utof commented on Apr 19, 2026

    @utof
    OwnerAuthor

    Correction: The body's parenthetical "Phase 6 (issue #59)" is wrong — GH issue #59 is a different FTS refactor. "Phase 6" here refers to the internal task-tracker epic (Local HTTP API: axum + keychain + OpenAPI); there is no matching GH issue yet. This issue is a blocker/prep for that epic whenever it starts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/chore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions