# chrisjmendoza/shaftschematic architecture

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

- Interactive diagram: https://gitdiagram.com/chrisjmendoza/shaftschematic
- Repository: https://github.com/chrisjmendoza/shaftschematic

## Overview

#### Purpose and Runtime
ShaftSchematic is a single-activity Android app for modeling marine prop-shaft assemblies and producing dimensioned PDF drawings, runout sheets, and wear forms. It runs on Kotlin, Jetpack Compose/Material3, Coroutines, Android DataStore, Android Storage Access Framework (SAF), and app-private storage. Entry points are `app/src/main/AndroidManifest.xml` and `app/src/main/java/com/android/shaftschematic/MainActivity.kt`.

#### Navigation and Screen Composition
`MainActivity` hosts Compose navigation. Start, editor, settings, runout, wear, and PDF-preview routes are coordinated through `app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt`; editor-centric tabs and actions are assembled in `app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt`. `app/src/main/java/com/android/shaftschematic/ui/screen/StartScreen.kt` is the document-library entry flow.

#### Canonical Domain Model
`ShaftSpec` is the root aggregate and stores dimensions canonically in millimeters; UI unit conversion is intentionally an edge concern. Persisted parts include bodies, tapers, threads, liners, and bolt slots, defined under `app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt`, `app/src/main/java/com/android/shaftschematic/model/Body.kt`, and `app/src/main/java/com/android/shaftschematic/model/Taper.kt`. Version migrations protect compatibility in `app/src/main/java/com/android/shaftschematic/model/ShaftSpecMigrations.kt`.

#### Editing State and Derived Geometry
`ShaftViewModel` owns the active document, editing operations, validation-facing state, undo/redo behavior, and snapping-oriented updates: `app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt`. The resolved-component layer derives non-persisted auto-bodies to fill preview gaps at `app/src/main/java/com/android/shaftschematic/ui/resolved/ResolvedComponent.kt`. Pure geometry computes overall length, reference/set positions, label tiers, and runout-bubble placement in `app/src/main/java/com/android/shaftschematic/geom/OalComputations.kt`, `app/src/main/java/com/android/shaftschematic/geom/SetPositions.kt`, and `app/src/main/java/com/android/shaftschematic/geom/DeterministicTierAssigner.kt`.

#### Interactive Drawing Boundary
The editor renders derived model state rather than owning business data. Compose preview hosting begins at `app/src/main/java/com/android/shaftschematic/ui/drawing/compose/ShaftDrawing.kt`; layout and draw primitives are separated in `app/src/main/java/com/android/shaftschematic/ui/drawing/render/ShaftLayout.kt` and `app/src/main/java/com/android/shaftschematic/ui/drawing/render/ShaftRenderer.kt`. Screens collect ViewModel state, issue events, and use validation utilities before mutation/export.

#### Persistence, Documents, and Recovery
`.shaft` files are versioned JSON envelopes encoded/decoded by `app/src/main/java/com/android/shaftschematic/doc/ShaftDocCodec.kt` and format definitions in `app/src/main/java/com/android/shaftschematic/doc/DocumentFormat.kt`. The app-private library, recent files, sample seeding, migration, and SAF-facing file operations are centralized in `app/src/main/java/com/android/shaftschematic/io/InternalStorage.kt`. Autosave/draft recovery and persisted preferences form separate boundaries in `app/src/main/java/com/android/shaftschematic/data/AutosaveManager.kt` and `app/src/main/java/com/android/shaftschematic/data/SettingsStore.kt`; ZIP backup/restore is `app/src/main/java/com/android/shaftschematic/io/ShaftBackup.kt`.

#### Export Pipeline and External Android Services
PDF export consumes the model plus export/preferences settings, independently composing each output type: `app/src/main/java/com/android/shaftschematic/pdf/ShaftPdfComposer.kt`, `app/src/main/java/com/android/shaftschematic/pdf/RunoutPdfComposer.kt`, and `app/src/main/java/com/android/shaftschematic/pdf/WearPdfComposer.kt`. Export routing invokes Android’s SAF picker through `app/src/main/java/com/android/shaftschematic/ui/nav/PdfExportRoute.kt`; opening PDFs uses Android intents via `app/src/main/java/com/android/shaftschematic/util/PdfOpenIntent.kt`. Blocking validation gates this boundary so invalid assemblies do not produce deliverables.

Main entry points: [`app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt`](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt) (ShaftViewModel), [`app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt`](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt) (ShaftSpec), [`app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt`](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt) (App navigation), [`app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt`](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt) (Shaft editor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Compose UI"]
  node_main_activity["MainActivity<br/>Android entry<br/>[MainActivity.kt]"]
  node_app_nav["App navigation<br/>Compose navigation<br/>[AppNav.kt]"]
  node_start_screen["Document library<br/>start screen<br/>[StartScreen.kt]"]
  node_editor_route["Shaft editor<br/>editor route"]
  node_view_model["ShaftViewModel<br/>editing state<br/>[ShaftViewModel.kt]"]
  node_drawing["Interactive drawing<br/>Compose renderer<br/>[ShaftDrawing.kt]"]
  node_layout_renderer["Drawing layout &amp; renderer<br/>render primitives<br/>[ShaftRenderer.kt]"]
end

subgraph group_domain["Model &amp; Geometry"]
  node_shaft_spec["ShaftSpec<br/>root aggregate<br/>[ShaftSpec.kt]"]
  node_shaft_parts["Shaft parts<br/>persisted components<br/>[Body.kt]"]
  node_migrations["Spec migrations<br/>version migration"]
  node_resolved["Resolved components<br/>derived model"]
  node_geometry["Geometry computations<br/>pure geometry<br/>[OalComputations.kt]"]
end

subgraph group_documents["Documents &amp; State"]
  node_doc_codec["Shaft document codec<br/>versioned JSON codec<br/>[ShaftDocCodec.kt]"]
  node_storage[("Internal storage<br/>document repository<br/>[InternalStorage.kt]")]
  node_autosave["Autosave recovery<br/>draft recovery<br/>[AutosaveManager.kt]"]
  node_settings[("Settings store<br/>preferences<br/>[SettingsStore.kt]")]
  node_backup["ZIP backup &amp; restore<br/>backup service<br/>[ShaftBackup.kt]"]
end

subgraph group_output["Export"]
  node_pdf_composers["PDF composers<br/>PDF composition"]
  node_pdf_export["PDF export route<br/>export boundary<br/>[PdfExportRoute.kt]"]
  node_pdf_open["PDF open intent<br/>Android intent adapter<br/>[PdfOpenIntent.kt]"]
end

node_android{{"Android runtime<br/>platform"}}

node_android -->|"launches"| node_main_activity
node_main_activity -->|"hosts"| node_app_nav
node_app_nav -->|"routes to"| node_start_screen
node_app_nav -->|"routes to"| node_editor_route
node_editor_route -->|"collects and sends events"| node_view_model
node_start_screen -->|"opens library"| node_storage
node_view_model -->|"edits"| node_shaft_spec
node_shaft_spec -->|"contains"| node_shaft_parts
node_migrations -->|"upgrades"| node_shaft_spec
node_view_model -->|"derives preview state"| node_resolved
node_resolved -->|"uses"| node_geometry
node_drawing -->|"delegates rendering"| node_layout_renderer
node_editor_route -->|"hosts"| node_drawing
node_view_model -->|"supplies derived state"| node_drawing
node_storage -->|"reads and writes"| node_doc_codec
node_doc_codec -->|"applies compatibility"| node_migrations
node_view_model -->|"saves draft"| node_autosave
node_view_model -->|"uses preferences"| node_settings
node_backup -->|"archives library"| node_storage
node_pdf_export -->|"exports validated spec"| node_pdf_composers
node_pdf_composers -->|"composes from"| node_shaft_spec
node_pdf_composers -->|"uses export preferences"| node_settings
node_pdf_export -->|"uses SAF picker"| node_android
node_pdf_open -->|"opens via intent"| node_android

click node_main_activity "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/MainActivity.kt"
click node_app_nav "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt"
click node_start_screen "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/screen/StartScreen.kt"
click node_editor_route "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt"
click node_view_model "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt"
click node_drawing "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/drawing/compose/ShaftDrawing.kt"
click node_shaft_spec "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt"
click node_shaft_parts "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/Body.kt"
click node_migrations "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/ShaftSpecMigrations.kt"
click node_resolved "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/resolved/ResolvedComponent.kt"
click node_geometry "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/geom/OalComputations.kt"
click node_layout_renderer "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/drawing/render/ShaftRenderer.kt"
click node_doc_codec "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/doc/ShaftDocCodec.kt"
click node_storage "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/io/InternalStorage.kt"
click node_autosave "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/data/AutosaveManager.kt"
click node_settings "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/data/SettingsStore.kt"
click node_backup "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/io/ShaftBackup.kt"
click node_pdf_composers "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/pdf/ShaftPdfComposer.kt"
click node_pdf_export "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/nav/PdfExportRoute.kt"
click node_pdf_open "https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/util/PdfOpenIntent.kt"

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_activity,node_app_nav,node_start_screen,node_editor_route,node_view_model,node_drawing,node_layout_renderer toneBlue
class node_shaft_spec,node_shaft_parts,node_migrations,node_resolved,node_geometry toneAmber
class node_doc_codec,node_storage,node_autosave,node_settings,node_backup toneMint
class node_pdf_composers,node_pdf_export,node_pdf_open toneRose
class node_android toneNeutral
```

## Components

### Compose UI

- [MainActivity](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/MainActivity.kt): Android entry · `app/src/main/java/com/android/shaftschematic/MainActivity.kt`
- [App navigation](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt): Compose navigation · `app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt`
- [Document library](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/screen/StartScreen.kt): start screen · `app/src/main/java/com/android/shaftschematic/ui/screen/StartScreen.kt`
- [Shaft editor](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt): editor route · Assembles editor tabs and actions. · `app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt`
- [ShaftViewModel](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt): editing state · Owns active document, edits, validation state, and undo/redo. · `app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt`
- [Interactive drawing](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/drawing/compose/ShaftDrawing.kt): Compose renderer · Renders derived state without owning business data. · `app/src/main/java/com/android/shaftschematic/ui/drawing/compose/ShaftDrawing.kt`
- [Drawing layout & renderer](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/drawing/render/ShaftRenderer.kt): render primitives · `app/src/main/java/com/android/shaftschematic/ui/drawing/render/ShaftRenderer.kt`

### Model & Geometry

- [ShaftSpec](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt): root aggregate · Canonical persisted dimensions are millimeters. · `app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt`
- [Shaft parts](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/Body.kt): persisted components · Bodies, tapers, threads, liners, and bolt slots. · `app/src/main/java/com/android/shaftschematic/model/Body.kt`
- [Spec migrations](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/model/ShaftSpecMigrations.kt): version migration · `app/src/main/java/com/android/shaftschematic/model/ShaftSpecMigrations.kt`
- [Resolved components](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/resolved/ResolvedComponent.kt): derived model · Adds non-persisted auto-bodies for preview gaps. · `app/src/main/java/com/android/shaftschematic/ui/resolved/ResolvedComponent.kt`
- [Geometry computations](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/geom/OalComputations.kt): pure geometry · Computes length, positions, label tiers, and runout bubbles. · `app/src/main/java/com/android/shaftschematic/geom/OalComputations.kt`

### Documents & State

- [Shaft document codec](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/doc/ShaftDocCodec.kt): versioned JSON codec · Encodes and decodes .shaft envelopes. · `app/src/main/java/com/android/shaftschematic/doc/ShaftDocCodec.kt`
- [Internal storage](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/io/InternalStorage.kt): document repository · Library, recents, samples, SAF operations, and migration. · `app/src/main/java/com/android/shaftschematic/io/InternalStorage.kt`
- [Autosave recovery](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/data/AutosaveManager.kt): draft recovery · `app/src/main/java/com/android/shaftschematic/data/AutosaveManager.kt`
- [Settings store](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/data/SettingsStore.kt): preferences · `app/src/main/java/com/android/shaftschematic/data/SettingsStore.kt`
- [ZIP backup & restore](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/io/ShaftBackup.kt): backup service · `app/src/main/java/com/android/shaftschematic/io/ShaftBackup.kt`

### Export

- [PDF composers](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/pdf/ShaftPdfComposer.kt): PDF composition · Independently produces drawing, runout sheet, and wear form. · `app/src/main/java/com/android/shaftschematic/pdf/ShaftPdfComposer.kt`
- [PDF export route](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/ui/nav/PdfExportRoute.kt): export boundary · Validates then invokes the Android SAF picker. · `app/src/main/java/com/android/shaftschematic/ui/nav/PdfExportRoute.kt`
- [PDF open intent](https://github.com/chrisjmendoza/shaftschematic/blob/main/app/src/main/java/com/android/shaftschematic/util/PdfOpenIntent.kt): Android intent adapter · `app/src/main/java/com/android/shaftschematic/util/PdfOpenIntent.kt`

### Other components

- **Android runtime**: platform · Activity, intents, SAF, and app-private storage.

## Connections

- Android runtime → MainActivity: launches
- MainActivity → App navigation: hosts
- App navigation → Document library: routes to
- App navigation → Shaft editor: routes to
- Shaft editor → ShaftViewModel: collects and sends events
- Document library → Internal storage: opens library
- ShaftViewModel → ShaftSpec: edits
- ShaftSpec → Shaft parts: contains
- Spec migrations → ShaftSpec: upgrades
- ShaftViewModel → Resolved components: derives preview state
- Resolved components → Geometry computations: uses
- Interactive drawing → Drawing layout & renderer: delegates rendering
- Shaft editor → Interactive drawing: hosts
- ShaftViewModel → Interactive drawing: supplies derived state
- Internal storage → Shaft document codec: reads and writes
- Shaft document codec → Spec migrations: applies compatibility
- ShaftViewModel → Autosave recovery: saves draft
- ShaftViewModel → Settings store: uses preferences
- ZIP backup & restore → Internal storage: archives library
- PDF export route → PDF composers: exports validated spec
- PDF composers → ShaftSpec: composes from
- PDF composers → Settings store: uses export preferences
- PDF export route → Android runtime: uses SAF picker
- PDF open intent → Android runtime: opens via intent
