# vncsmnl/rwx architecture

> Architecture diagram of the GitHub repository vncsmnl/rwx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vncsmnl/rwx
- Repository: https://github.com/vncsmnl/rwx

## Overview

#### Purpose and Runtime

`rwx` is a Unix-only Rust terminal UI for browsing files and changing permissions, special mode bits, and ownership. It runs as a native CLI binary using Ratatui for rendering and Crossterm for terminal input/control; filesystem mutation ultimately relies on Unix permission and ownership operations.

Core manifest and binary entry point:
- `Cargo.toml`
- `src/main.rs`

#### Startup, CLI, and Terminal Lifecycle

`main` parses an optional target path and recursive flag, determines whether to begin in browser or editor mode, initializes terminal raw/alternate-screen behavior, and drives the render/event loop. It also installs panic recovery so terminal state is restored after unexpected failures.

Primary entry:
- `src/main.rs`

#### Application State and Mode Control

The application model owns navigation state, selected filesystem target, editor fields, focus/input state, pending changes, validation results, modal/status messaging, and recursive-operation selection. It controls transitions between browser mode and permission-editor mode, including returning from an editor target to directory navigation.

Central state/control boundary:
- `src/app.rs`
- `src/main.rs`

#### Filesystem Browser and Target Inspection

The browser reads directory contents, supports selection and directory traversal, and opens either selected entries or the current directory for editing. Target inspection obtains metadata needed to display file type, size, mode, current owner/group, and editable permissions. This is the boundary between the interactive state model and the local Unix filesystem.

Relevant implementation:
- `src/app.rs`

#### Permission Representation and Editing Rules

A dedicated permission domain layer converts among Unix mode bits, octal input, checkbox/grid state, and symbolic display strings. It includes regular `rwx` bits plus SetUID, SetGID, and sticky bits, allowing the UI and mutation layer to work from a consistent permission model.

Permission domain:
- `src/permissions.rs`
- `src/app.rs`

#### Ownership Validation and Change Application

Editor input validates owner and group names against local system identities before applying changes. Applying commits pending permission and ownership edits to the selected path; recursive mode walks a directory tree and applies the requested mutations to nested files and directories. Failures and completion status flow back into application state for UI feedback.

Mutation and traversal boundary:
- `src/app.rs`
- `src/permissions.rs`

#### TUI Rendering and Input Feedback

The UI module is a presentation layer over application state. It renders the file browser, permissions grid, octal and ownership inputs, previews, focus indicators, actions, and status/modal feedback. Keyboard events are interpreted by the main/application control flow, then cause state changes and redraws rather than directly embedding filesystem behavior in the renderer.

Presentation layer:
- `src/ui.rs`
- `src/main.rs`
- `src/app.rs`

#### Distribution

The project is packaged as a Cargo crate and released as native binaries/installers. Release automation is defined in:
- `.github/workflows/release.yml`
- `Cargo.toml`
- `dist-workspace.toml`

Main entry points: [`src/main.rs`](https://github.com/vncsmnl/rwx/blob/main/src/main.rs) (CLI and event loop), [`src/app.rs`](https://github.com/vncsmnl/rwx/blob/main/src/app.rs) (Ownership and change editor), [`.github/workflows/release.yml`](https://github.com/vncsmnl/rwx/blob/main/.github/workflows/release.yml) (Release automation), [`src/ui.rs`](https://github.com/vncsmnl/rwx/blob/main/src/ui.rs) (TUI presentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Terminal Runtime"]
  node_main["CLI and event loop<br/>binary entry<br/>[main.rs]"]
  node_terminal{{"Terminal control<br/>Ratatui + Crossterm"}}
  node_panic["Panic recovery<br/>terminal safeguard<br/>[main.rs]"]
  node_ui["TUI presentation<br/>renderer<br/>[ui.rs]"]
end

subgraph group_core["Application Core"]
  node_app["Application state<br/>state controller<br/>[app.rs]"]
  node_mode["Browser/editor modes<br/>mode control<br/>[app.rs]"]
  node_browser["Directory browser<br/>filesystem navigation<br/>[app.rs]"]
  node_permissions["Permission domain<br/>mode-bit model<br/>[permissions.rs]"]
  node_editor["Ownership and change editor<br/>edit workflow<br/>[app.rs]"]
end

subgraph group_unix["Unix Filesystem"]
  node_filesystem[("Local Unix filesystem<br/>system boundary")]
  node_recursive["Recursive apply<br/>tree traversal<br/>[app.rs]"]
end

subgraph group_release["Distribution"]
  node_cargo["Cargo crate<br/>manifest<br/>[Cargo.toml]"]
  node_release["Release automation<br/>native packaging<br/>[release.yml]"]
  node_dist["Distribution workspace<br/>packaging config"]
end

node_cargo -->|"builds"| node_main
node_main -->|"initializes"| node_terminal
node_main -->|"installs"| node_panic
node_terminal -->|"input events"| node_main
node_main -->|"drives"| node_app
node_app -->|"controls"| node_mode
node_mode -->|"browser mode"| node_browser
node_mode -->|"editor mode"| node_editor
node_browser -->|"lists and inspects"| node_filesystem
node_browser -->|"opens target"| node_editor
node_editor -->|"uses permission model"| node_permissions
node_permissions -->|"maps mode changes"| node_filesystem
node_editor -->|"validates identities and applies changes"| node_filesystem
node_editor -.->|"when recursive"| node_recursive
node_recursive -->|"walks and mutates"| node_filesystem
node_app -->|"provides state"| node_ui
node_ui -->|"renders to"| node_terminal
node_release -->|"packages"| node_cargo
node_release -->|"uses"| node_dist

click node_cargo "https://github.com/vncsmnl/rwx/blob/main/Cargo.toml"
click node_main "https://github.com/vncsmnl/rwx/blob/main/src/main.rs"
click node_panic "https://github.com/vncsmnl/rwx/blob/main/src/main.rs"
click node_app "https://github.com/vncsmnl/rwx/blob/main/src/app.rs"
click node_mode "https://github.com/vncsmnl/rwx/blob/main/src/app.rs"
click node_browser "https://github.com/vncsmnl/rwx/blob/main/src/app.rs"
click node_permissions "https://github.com/vncsmnl/rwx/blob/main/src/permissions.rs"
click node_editor "https://github.com/vncsmnl/rwx/blob/main/src/app.rs"
click node_ui "https://github.com/vncsmnl/rwx/blob/main/src/ui.rs"
click node_recursive "https://github.com/vncsmnl/rwx/blob/main/src/app.rs"
click node_release "https://github.com/vncsmnl/rwx/blob/main/.github/workflows/release.yml"
click node_dist "https://github.com/vncsmnl/rwx/blob/main/dist-workspace.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_terminal,node_panic,node_ui toneBlue
class node_app,node_mode,node_browser,node_permissions,node_editor toneAmber
class node_filesystem,node_recursive toneMint
class node_cargo,node_release,node_dist toneRose
```

## Components

### Terminal Runtime

- [CLI and event loop](https://github.com/vncsmnl/rwx/blob/main/src/main.rs): binary entry · Parses startup options and owns terminal lifecycle. · `src/main.rs`
- **Terminal control**: Ratatui + Crossterm · Provides rendering surface, raw mode, alternate screen, and events.
- [Panic recovery](https://github.com/vncsmnl/rwx/blob/main/src/main.rs): terminal safeguard · Restores terminal state after unexpected failure. · `src/main.rs`
- [TUI presentation](https://github.com/vncsmnl/rwx/blob/main/src/ui.rs): renderer · Renders browser, editor controls, previews, and status feedback. · `src/ui.rs`

### Application Core

- [Application state](https://github.com/vncsmnl/rwx/blob/main/src/app.rs): state controller · Owns navigation, editing, focus, pending changes, and feedback. · `src/app.rs`
- [Browser/editor modes](https://github.com/vncsmnl/rwx/blob/main/src/app.rs): mode control · Transitions between directory navigation and target editing. · `src/app.rs`
- [Directory browser](https://github.com/vncsmnl/rwx/blob/main/src/app.rs): filesystem navigation · Lists directories, tracks selection, and chooses edit targets. · `src/app.rs`
- [Permission domain](https://github.com/vncsmnl/rwx/blob/main/src/permissions.rs): mode-bit model · Converts Unix bits, octal input, grid state, and symbolic display. · `src/permissions.rs`
- [Ownership and change editor](https://github.com/vncsmnl/rwx/blob/main/src/app.rs): edit workflow · Validates identities and prepares permission or ownership changes. · `src/app.rs`

### Unix Filesystem

- **Local Unix filesystem**: system boundary · Supplies metadata and receives permission and ownership mutations.
- [Recursive apply](https://github.com/vncsmnl/rwx/blob/main/src/app.rs): tree traversal · Walks directory trees to apply requested mutations. · `src/app.rs`

### Distribution

- [Cargo crate](https://github.com/vncsmnl/rwx/blob/main/Cargo.toml): manifest · Builds the native rwx binary. · `Cargo.toml`
- [Release automation](https://github.com/vncsmnl/rwx/blob/main/.github/workflows/release.yml): native packaging · Publishes native binaries and installers. · `.github/workflows/release.yml`
- [Distribution workspace](https://github.com/vncsmnl/rwx/blob/main/dist-workspace.toml): packaging config · `dist-workspace.toml`

## Connections

- Cargo crate → CLI and event loop: builds
- CLI and event loop → Terminal control: initializes
- CLI and event loop → Panic recovery: installs
- Terminal control → CLI and event loop: input events
- CLI and event loop → Application state: drives
- Application state → Browser/editor modes: controls
- Browser/editor modes → Directory browser: browser mode
- Browser/editor modes → Ownership and change editor: editor mode
- Directory browser → Local Unix filesystem: lists and inspects
- Directory browser → Ownership and change editor: opens target
- Ownership and change editor → Permission domain: uses permission model
- Permission domain → Local Unix filesystem: maps mode changes
- Ownership and change editor → Local Unix filesystem: validates identities and applies changes
- Ownership and change editor → Recursive apply: when recursive
- Recursive apply → Local Unix filesystem: walks and mutates
- Application state → TUI presentation: provides state
- TUI presentation → Terminal control: renders to
- Release automation → Cargo crate: packages
- Release automation → Distribution workspace: uses
