How chrisjmendoza/shaftschematic works
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: ShaftViewModel.kt ShaftViewModel · ShaftSpec.kt ShaftSpec · AppNav.kt App navigation · ShaftEditorRoute.kt Shaft editor
Components 21
Compose UI
- MainActivity
app/src/main/java/com/android/shaftschematic/MainActivity.kt - App navigation
app/src/main/java/com/android/shaftschematic/ui/nav/AppNav.kt - Document library
app/src/main/java/com/android/shaftschematic/ui/screen/StartScreen.kt - Shaft editor · Assembles editor tabs and actions.
app/src/main/java/com/android/shaftschematic/ui/screen/ShaftEditorRoute.kt - ShaftViewModel · Owns active document, edits, validation state, and undo/redo.
app/src/main/java/com/android/shaftschematic/ui/viewmodel/ShaftViewModel.kt - Interactive drawing · Renders derived state without owning business data.
app/src/main/java/com/android/shaftschematic/ui/drawing/compose/ShaftDrawing.kt - Drawing layout & renderer
app/src/main/java/com/android/shaftschematic/ui/drawing/render/ShaftRenderer.kt
Model & Geometry
- ShaftSpec · Canonical persisted dimensions are millimeters.
app/src/main/java/com/android/shaftschematic/model/ShaftSpec.kt - Shaft parts · Bodies, tapers, threads, liners, and bolt slots.
app/src/main/java/com/android/shaftschematic/model/Body.kt - Spec migrations
app/src/main/java/com/android/shaftschematic/model/ShaftSpecMigrations.kt - Resolved components · Adds non-persisted auto-bodies for preview gaps.
app/src/main/java/com/android/shaftschematic/ui/resolved/ResolvedComponent.kt - Geometry computations · Computes length, positions, label tiers, and runout bubbles.
app/src/main/java/com/android/shaftschematic/geom/OalComputations.kt
Documents & State
- Shaft document codec · Encodes and decodes .shaft envelopes.
app/src/main/java/com/android/shaftschematic/doc/ShaftDocCodec.kt - Internal storage · Library, recents, samples, SAF operations, and migration.
app/src/main/java/com/android/shaftschematic/io/InternalStorage.kt - Autosave recovery
app/src/main/java/com/android/shaftschematic/data/AutosaveManager.kt - Settings store
app/src/main/java/com/android/shaftschematic/data/SettingsStore.kt - ZIP backup & restore
app/src/main/java/com/android/shaftschematic/io/ShaftBackup.kt
Export
- PDF composers · Independently produces drawing, runout sheet, and wear form.
app/src/main/java/com/android/shaftschematic/pdf/ShaftPdfComposer.kt - PDF export route · Validates then invokes the Android SAF picker.
app/src/main/java/com/android/shaftschematic/ui/nav/PdfExportRoute.kt - PDF open intent
app/src/main/java/com/android/shaftschematic/util/PdfOpenIntent.kt
Other components
- Android runtime · Activity, intents, SAF, and app-private storage.
Connections 24
- 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