SPB Git

Repository Public MIT

overview.md 5.1 KB

# Architecture overview

ORIX Calc is a thin SwiftUI app on top of local Swift packages. Calculation logic never imports SwiftUI; every engine is tested from the command line without launching the app.

flowchart TD
    subgraph App["App target (ORIXCalc)"]
        Shell["Adaptive shell · history · settings · intents · Math Camera"]
    end
    subgraph Features["Feature packages (SwiftUI)"]
        FCalc["ORIXFeatureCalculator<br/>Standard · Scientific"]
        FFin["ORIXFeatureFinancial"]
        FGraph["ORIXFeatureGraph"]
        FMath["ORIXFeatureMath"]
        FStat["ORIXFeatureStatistics"]
        FConv["ORIXFeatureConvert"]
        FWork["ORIXFeatureWorkspace"]
    end
    UI["ORIXUI<br/>design system · AppModel · SwiftData store"]
    subgraph Engines["Engine packages (no UI)"]
        Expr["ORIXExpression<br/>values · parser · evaluator · formatter · RPN"]
        Fin["ORIXFinancial"]
        Graph["ORIXGraph"]
        Sym["ORIXSymbolic"]
        Stat["ORIXStatistics"]
        Units["ORIXUnits"]
        Work["ORIXWorkspace"]
        Cam["ORIXMathCamera"]
    end
    Num["ORIXNumerics<br/>Explanation · VerificationReport · root finding · quadrature"]

    Shell --> Features
    Features --> UI
    FCalc --> Expr
    FFin --> Fin
    FGraph --> Graph
    FMath --> Sym
    FStat --> Stat
    FConv --> Units
    FWork --> Work
    Shell --> Cam
    UI --> Expr
    UI --> Work
    Graph --> Expr
    Sym --> Expr
    Work --> Expr
    Cam --> Expr
    Expr --> Num
    Fin --> Num
    Stat --> Num
    Graph --> Num
    Sym --> Num

# Module boundaries

Package Responsibility Depends on
ORIXNumerics Shared result vocabulary (Explanation, VerificationReport) and scalar numerical methods (Brent, adaptive Gauss–Kronrod, tanh-sinh, Ridders) Foundation
ORIXExpression Typed values, exact arithmetic, parser, evaluator, compiled real functions, number formatting, expression printing (text / LaTeX), RPN machine ORIXNumerics, BigInt, Swift Numerics, Accelerate
ORIXFinancial TVM, cash flows, loans, bonds, investments, options, sensitivity ORIXNumerics
ORIXStatistics Special functions, descriptive statistics, distributions, inference, regression, simulation ORIXNumerics
ORIXUnits Unit catalogue, exact conversion, rate conventions, currency model Foundation
ORIXSymbolic Simplification, polynomials, calculus, solving, limits, series, optimisation, ODEs ORIXExpression, ORIXNumerics
ORIXGraph Sampling with discontinuity detection, analysis, implicit curves, 3D meshes ORIXExpression, ORIXNumerics
ORIXWorkspace Document model, dependency graph, incremental recalculation, exports, .orixcalc format ORIXExpression, ORIXNumerics
ORIXMathCamera Vision text recognition and normalisation into parseable input ORIXExpression, Vision
ORIXUI Design tokens and components; AppModel (shared session); SwiftData store ORIXExpression, ORIXWorkspace, ORIXNumerics
ORIXFeature* One SwiftUI package per environment ORIXUI + its engine

Rules that keep this honest:

  • Engines return values with an Explanation and a VerificationReport. The UI never invents either.
  • Feature packages do not depend on each other. Cross-environment actions go through AppModel mailboxes (pendingGraphExpression, pendingConvertValue, pendingWorkspaceLine, pendingCalculatorText) or through an environment seam (graphPreview, used by Workspace to embed a real plot).
  • One session: AppModel owns one CalculatorEngine (variables, user functions, ans), one history and one store.

# Local persistence

flowchart LR
    AppModel -->|"SwiftData (ORIXSchemaV1)"| Store[("ORIXCalc.store<br/>Application Support")]
    Store --- H["HistoryRecord"]
    Store --- V["NamedValueRecord (canonical text)"]
    Store --- F["FunctionRecord (ASCII body)"]
    Store --- W["WorkspaceRecord (.orixcalc payload, SHA-256 checked)"]
    Store --- M["SavedModelRecord (JSON payload per screen / model)"]
    Settings["AppSettings"] -->|JSON| Defaults[("UserDefaults")]
    AppModel -->|"exportBackup()"| Backup["Backup JSON → Files"]
  • Values are persisted as canonical text (NumberFormat.canonical: exact fractions, 17-digit doubles) and re-parsed on load, so no precision is lost and no binary format has to be migrated.
  • The schema is versioned (ORIXSchemaV1 + ORIXMigrationPlan). If the store cannot be opened, its files are renamed …damaged-<timestamp> (never deleted), a fresh store is created, and the user is told.
  • Workspaces carry a checksum; a damaged payload is detected and its readable content recovered.

# Concurrency

Swift 6 language mode with complete strict concurrency in every package. Engines are value types and Sendable. Heavy work (committed evaluations, live previews, binomial trees, sweeps, sampling) runs off the main actor in detached tasks with latest-wins or cancellation; the main actor only applies results.

Files main
Menu

Theme