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
| Layer | File | Responsibility |
|---|---|---|
| Launcher | JunctionManager.bat | Confirm pwsh is on PATH, then invoke the root script |
| Entry point | JunctionManager.ps1 | Resolve the repository root and hand off to src/menu.ps1 |
| Presentation | src/menu.ps1 | Parse CLI flags, render the TUI, dispatch catalog actions |
| Catalog | src/core/catalog.ps1 | Canonical module/action definitions and search |
| Core | src/core/*.ps1 | Paths, 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:
version.ps1supplies product metadata.paths.ps1has no dependency and defines validation primitives.junctions.ps1depends on path normalization and protection.operations.ps1depends on inspection and validation.inventory.ps1depends on operations.catalog.ps1is independent of the filesystem and describes the surface.logger.ps1andui-helpers.ps1are 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.
| Producer | Object | Fields |
|---|---|---|
New-WjmOperationResult | Operation result | Action, Success, DryRun, JunctionPath, TargetPath, PreviousTarget, Message, TimestampUtc |
Get-WjmJunctionInfo | Junction record | JunctionPath, Name, TargetPath, Status, Reason, TargetExists, ContainsFiles, Protected, LinkType, IsJunction, Exists |
Clear-WjmStaleJunctions | Cleanup result | Success, DryRun, Removed, Failed, TargetsRemoved, Results |
Export-WjmInventory | Export result | Action, Success, DryRun, Path, Format, Count, GeneratedUtc |
Import-WjmInventory | Manifest | Schema, GeneratedUtc, Path, Count, Junctions |
Restore-WjmInventory | Restore result | Success, DryRun, Created, Skipped, Failed, Details |
Get-WjmJunctionSummary | Summary | Total, 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
| Code | Meaning |
|---|---|
0 | Success |
1 | Operation failed, inspection found a missing path, or an exception occurred |
2 | Usage 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
- One catalog. The TUI, CLI, documentation, and tests read the same definitions.
- One load order. No file repeats the module list.
- Validation before mutation. Every operation asserts first.
- Dry-run is core-level. No surface reimplements it.
- Protected paths are never mutated. Enforcement lives in
paths.ps1and is called by operations. - Removal detaches only. The target is never followed or deleted with the link.
- Restore never overwrites. Existing paths and protected paths are skipped.
- Native behavior wins. Operations are attempted and results are reported, not pre-empted.
Related documentation
- Core modules — function-level reference.
- Action catalog — the module/action data model.
- Testing — suites, harness, and CI.
- Safety and protected paths — user-facing policy.