Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

Windows Junction Manager is a portable PowerShell 7 application with two surfaces over one core:

  • an interactive terminal UI for exploration and guided operations;
  • a headless CLI for scripting and CI.

Both surfaces read the same action catalog and call the same core functions. There is no separate implementation to drift.

Layering

flowchart TD
    B["JunctionManager.bat<br/>PATH pwsh launcher"] --> E["JunctionManager.ps1<br/>root entry point"]
    E --> M["src/menu.ps1<br/>dispatcher and TUI"]
    M --> MF["src/core/manifest.ps1<br/>load order"]
    MF --> V["version.ps1"]
    MF --> P["paths.ps1"]
    MF --> J["junctions.ps1"]
    MF --> O["operations.ps1"]
    MF --> I["inventory.ps1"]
    MF --> K["catalog.ps1"]
    MF --> L["logger.ps1"]
    MF --> U["ui-helpers.ps1"]
    M --> T["Interactive TUI"]
    M --> C["Headless CLI"]
    T --> K
    C --> K
    K --> O
    K --> J
    J --> P
    O --> P
    O --> J
    I --> O
    I --> P
LayerFileResponsibility
LauncherJunctionManager.batConfirm pwsh is on PATH, then invoke the root script
Entry pointJunctionManager.ps1Resolve the repository root and hand off to src/menu.ps1
Presentationsrc/menu.ps1Parse CLI flags, render the TUI, dispatch catalog actions
Catalogsrc/core/catalog.ps1Canonical module/action definitions and search
Coresrc/core/*.ps1Paths, inspection, operations, inventory, logging, UI primitives

The launcher and entry point intentionally contain no product logic. This keeps the application runnable from any folder and testable without a terminal.

Bootstrap and load order

src/core/manifest.ps1 is the single source of module load order. The entry point and the test harness both call Get-WjmCoreModulePaths rather than hard-coding a list.

flowchart LR
    A["menu.ps1"] --> B["manifest.ps1"]
    B --> C["version.ps1"]
    C --> D["paths.ps1"]
    D --> E["junctions.ps1"]
    E --> F["operations.ps1"]
    F --> G["inventory.ps1"]
    G --> H["catalog.ps1"]
    H --> I["logger.ps1"]
    I --> J["ui-helpers.ps1"]

The order matters:

  1. version.ps1 supplies product metadata.
  2. paths.ps1 has no dependency and defines validation primitives.
  3. junctions.ps1 depends on path normalization and protection.
  4. operations.ps1 depends on inspection and validation.
  5. inventory.ps1 depends on operations.
  6. catalog.ps1 is independent of the filesystem and describes the surface.
  7. logger.ps1 and ui-helpers.ps1 are presentation and diagnostics support.

Because the modules are dot-sourced into one scope, adding a module means adding one line to the manifest and nothing else.

Request flow

Read-only scan

sequenceDiagram
    participant U as Caller
    participant M as menu.ps1
    participant J as junctions.ps1
    participant P as paths.ps1
    U->>M: --scan [root]
    M->>P: Get-WjmStandardScanRoots
    P-->>M: existing roots
    M->>J: Get-WjmJunctions roots depth
    loop each root
        J->>J: enumerate children, skip non-junction reparse points
        J->>P: Test-WjmProtectedPath
        J->>J: classify target state
    end
    J-->>M: junction records
    M-->>U: table, status toast, exit code

Discovery never recurses through a reparse point that is not a junction. This avoids traversing symlinks, mount points, or junctions into unrelated volumes.

Mutation

sequenceDiagram
    participant U as Caller
    participant M as menu.ps1
    participant O as operations.ps1
    participant P as paths.ps1
    participant W as Windows
    U->>M: --create PATH --target DIR
    M->>O: New-WjmJunction
    O->>P: Assert-WjmCreatableJunction
    alt invalid
        P-->>O: collected validation errors
        O-->>M: throw with all errors
    else valid
        O->>W: New-Item -ItemType Junction
        alt success
            W-->>O: junction created
        else native failure
            W-->>O: OS error
            O-->>M: throw with native message
        end
        O-->>M: operation result
    end
    M-->>U: result table, exit code

Validation always runs before any filesystem mutation. Native operating-system errors are wrapped with the action and paths, but the original message is preserved.

Result contracts

Core functions return small, stable objects rather than writing to the console. Presentation decides how to render them.

ProducerObjectFields
New-WjmOperationResultOperation resultAction, Success, DryRun, JunctionPath, TargetPath, PreviousTarget, Message, TimestampUtc
Get-WjmJunctionInfoJunction recordJunctionPath, Name, TargetPath, Status, Reason, TargetExists, ContainsFiles, Protected, LinkType, IsJunction, Exists
Clear-WjmStaleJunctionsCleanup resultSuccess, DryRun, Removed, Failed, TargetsRemoved, Results
Export-WjmInventoryExport resultAction, Success, DryRun, Path, Format, Count, GeneratedUtc
Import-WjmInventoryManifestSchema, GeneratedUtc, Path, Count, Junctions
Restore-WjmInventoryRestore resultSuccess, DryRun, Created, Skipped, Failed, Details
Get-WjmJunctionSummarySummaryTotal, Active, Orphaned, Empty, Other, Stale

Keeping these shapes stable is what lets the CLI, TUI, tests, and inventory schema evolve independently.

Dry-run model

Dry-run is a first-class parameter, not a presentation flag. Every mutating core function accepts -DryRun and returns the same result shape with DryRun = $true and a “Would …” message.

flowchart TD
    A[Action requested] --> B{Validate}
    B -- invalid --> X[Throw before mutation]
    B -- valid --> C{DryRun}
    C -- yes --> D[Return preview result]
    C -- no --> E[Attempt native operation]
    E --> F[Return actual result]

The TUI adds a session-level D toggle. The CLI adds --dry-run per command. Because the switch lives in the core, no surface can accidentally skip the check.

CLI exit codes

CodeMeaning
0Success
1Operation failed, inspection found a missing path, or an exception occurred
2Usage error, unknown flag, missing argument, or a refused destructive action

Destructive commands (--retarget, --remove, --clean-*, --restore) require --yes or --dry-run. The refusal happens in the dispatcher before the core is called.

Filesystem-agnostic boundary

The core does not inspect volume type, cluster size, or filesystem name before an operation. It normalizes the path, applies the protection policy, then asks Windows to perform the work.

flowchart LR
    A[Normalized path] --> B{Protected or invalid?}
    B -- yes --> X[Reject with reason]
    B -- no --> C[Attempt native operation]
    C --> D{Native success?}
    D -- yes --> E[Return result]
    D -- no --> F[Surface native error]

This is deliberate. A volume can reject a link for reasons the tool cannot predict, and a guessed filesystem gate would hide the real message. See Research: junction behavior for the platform evidence.

Architectural invariants

  1. One catalog. The TUI, CLI, documentation, and tests read the same definitions.
  2. One load order. No file repeats the module list.
  3. Validation before mutation. Every operation asserts first.
  4. Dry-run is core-level. No surface reimplements it.
  5. Protected paths are never mutated. Enforcement lives in paths.ps1 and is called by operations.
  6. Removal detaches only. The target is never followed or deleted with the link.
  7. Restore never overwrites. Existing paths and protected paths are skipped.
  8. Native behavior wins. Operations are attempted and results are reported, not pre-empted.