# mrphansum/gauden architecture

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

- Interactive diagram: https://gitdiagram.com/mrphansum/gauden
- Repository: https://github.com/mrphansum/gauden

## Overview

#### Purpose and deployable entry points
Home Application Fix is an iOS SwiftUI catalog for selling non-consumable module/DLC content, backed by an Express/TypeScript API with MongoDB. The app executable starts at `ios/HomeApplicationFix/App/HomeApplicationFixApp.swift`; its root routing/state is in `ios/HomeApplicationFix/App/RootView.swift`. The backend process initializes from `backend/src/index.ts`, assembling Express in `backend/src/app.ts`.

#### Client composition and navigation
The SwiftUI root selects authentication and main product experiences based on app/session state. User-facing feature boundaries are authentication, module catalog/detail, and profile:
- `ios/HomeApplicationFix/Features/Auth/AuthView.swift`
- `ios/HomeApplicationFix/Features/Catalog/CatalogView.swift`
- `ios/HomeApplicationFix/Features/ModuleDetail/ModuleDetailView.swift`
- `ios/HomeApplicationFix/Features/Profile/ProfileView.swift`

Guests can see demo material; entitlement determines access to full module content.

#### iOS service and persistence boundary
Views call domain-facing services rather than directly forming HTTP requests or persisting credentials. `ios/HomeApplicationFix/Core/Networking/APIClient.swift` is the API transport boundary; auth, module, and IAP orchestration reside in:
- `ios/HomeApplicationFix/Core/Services/AuthService.swift`
- `ios/HomeApplicationFix/Core/Services/ModuleService.swift`
- `ios/HomeApplicationFix/Core/Services/IAPService.swift`

API request/response models are centralized at `ios/HomeApplicationFix/Core/Models/APIModels.swift`. Access and refresh tokens are persisted only through Keychain abstractions in `ios/HomeApplicationFix/Core/Keychain/TokenStore.swift` and `ios/HomeApplicationFix/Core/Keychain/KeychainStore.swift`.

#### Authentication lifecycle
The API supports registration/password login, Google ID-token login, access-token authentication, refresh rotation, and logout. Routes are declared in `backend/src/routes/auth.ts`; JWT creation/rotation logic is in `backend/src/services/tokenService.ts`; Google token validation is isolated in `backend/src/services/googleAuthService.ts`. Protected API endpoints cross `backend/src/middleware/auth.ts`. Mongo stores users and hashed refresh-token records via `backend/src/models/User.ts` and `backend/src/models/RefreshToken.ts`.

#### Module catalog and entitlement gate
The backend serves a dynamic module catalog, module detail, and protected/full content from `backend/src/routes/modules.ts`. Module definitions, including their App Store product association, persist through `backend/src/models/Module.ts`. The catalog is intentionally data-driven: adding modules requires database/catalog data rather than a dedicated iOS screen per product. Initial module data is provisioned through `backend/src/scripts/seed.ts`.

#### Purchase verification and source of truth
StoreKit 2 purchase/restore work is initiated on iOS through `ios/HomeApplicationFix/Core/Services/IAPService.swift`, then submitted to `POST /api/iap/verify`. Server-side verification and entitlement creation are handled by `backend/src/routes/iap.ts` and `backend/src/services/iapService.ts`. Purchase records are durable server-side state in `backend/src/models/Purchase.ts`; clients query account/purchase state via `backend/src/routes/me.ts`. The backend, not only StoreKit client state, controls full-content entitlement.

#### Runtime infrastructure and operational boundaries
The mobile client uses configurable API base URL in `ios/HomeApplicationFix/Core/Config/AppConfig.swift`, suitable for HTTPS or LAN development. Backend runtime configuration comes from `backend/src/config/env.ts`; errors cross a centralized Express boundary at `backend/src/middleware/errorHandler.ts`. Material external systems are MongoDB, Apple App Store/StoreKit non-consumable IAP verification, Google OAuth ID tokens, and iOS Keychain. Production deployment expects HTTPS/reverse proxy and real App Store verification rather than mock verification.

Main entry points: [`ios/HomeApplicationFix/Core/Services/AuthService.swift`](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Services/AuthService.swift) (Auth & module services), [`ios/HomeApplicationFix/Core/Networking/APIClient.swift`](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Networking/APIClient.swift) (API client), [`ios/HomeApplicationFix/Core/Services/IAPService.swift`](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Services/IAPService.swift) (IAP service), [`backend/src/services/tokenService.ts`](https://github.com/mrphansum/gauden/blob/main/backend/src/services/tokenService.ts) (Token & Google auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ios["iOS app"]
  node_ios_app["App entry<br/>SwiftUI app"]
  node_ios_root["Root routing &amp; session<br/>SwiftUI state<br/>[RootView.swift]"]
  node_ios_features["Auth, catalog, detail &amp; profile<br/>SwiftUI features"]
  node_ios_api_models["API models<br/>Swift models<br/>[APIModels.swift]"]
  node_ios_services["Auth &amp; module services<br/>domain services<br/>[AuthService.swift]"]
  node_ios_iap["IAP service<br/>StoreKit orchestration<br/>[IAPService.swift]"]
  node_ios_api["API client<br/>HTTP transport<br/>[APIClient.swift]"]
  node_ios_tokens["Token store<br/>Keychain abstraction<br/>[TokenStore.swift]"]
  node_ios_config["API base URL config<br/>runtime config<br/>[AppConfig.swift]"]
end

subgraph group_backend["Express API"]
  node_api_entry["Backend entry<br/>Node process<br/>[index.ts]"]
  node_express_app["Express app<br/>API assembly<br/>[app.ts]"]
  node_api_routes["Auth, modules, IAP &amp; account routes<br/>route layer"]
  node_auth_middleware["JWT auth middleware<br/>Express middleware<br/>[auth.ts]"]
  node_auth_services["Token &amp; Google auth<br/>auth services<br/>[tokenService.ts]"]
  node_iap_service["Purchase verification<br/>IAP service<br/>[iapService.ts]"]
  node_catalog_data[("Modules &amp; purchases<br/>Mongo models<br/>[Module.ts]")]
end

subgraph group_external["External systems"]
  node_mongo[("MongoDB<br/>database")]
  node_app_store{{"Apple App Store<br/>IAP verification"}}
  node_google{{"Google OAuth<br/>identity provider"}}
  node_keychain[("iOS Keychain<br/>secure storage")]
end

node_ios_app -->|"launches"| node_ios_root
node_ios_root -->|"selects experience"| node_ios_features
node_ios_features -->|"uses"| node_ios_services
node_ios_features -->|"purchases/restores"| node_ios_iap
node_ios_services -->|"maps payloads"| node_ios_api_models
node_ios_services -->|"calls"| node_ios_api
node_ios_iap -->|"submits transaction"| node_ios_api
node_ios_services -->|"reads/writes session"| node_ios_tokens
node_ios_tokens -->|"stores tokens"| node_keychain
node_ios_config -.->|"configures base URL"| node_ios_api
node_ios_iap -->|"StoreKit 2"| node_app_store
node_ios_api -->|"HTTPS API"| node_api_entry
node_api_entry -->|"starts"| node_express_app
node_express_app -->|"mounts"| node_api_routes
node_api_routes -->|"protects endpoints"| node_auth_middleware
node_api_routes -->|"login, refresh &amp; Google login"| node_auth_services
node_auth_services -->|"validates ID token"| node_google
node_api_routes -->|"verifies purchase"| node_iap_service
node_iap_service -->|"server verification"| node_app_store
node_api_routes -->|"catalog and account state"| node_catalog_data
node_auth_services -->|"users &amp; refresh tokens"| node_mongo
node_catalog_data -->|"persists"| node_mongo
node_iap_service -->|"persists purchases"| node_mongo

click node_ios_app "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/App/HomeApplicationFixApp.swift"
click node_ios_root "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/App/RootView.swift"
click node_ios_api_models "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Models/APIModels.swift"
click node_ios_services "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Services/AuthService.swift"
click node_ios_iap "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Services/IAPService.swift"
click node_ios_api "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Networking/APIClient.swift"
click node_ios_tokens "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Keychain/TokenStore.swift"
click node_ios_config "https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Config/AppConfig.swift"
click node_api_entry "https://github.com/mrphansum/gauden/blob/main/backend/src/index.ts"
click node_express_app "https://github.com/mrphansum/gauden/blob/main/backend/src/app.ts"
click node_auth_middleware "https://github.com/mrphansum/gauden/blob/main/backend/src/middleware/auth.ts"
click node_auth_services "https://github.com/mrphansum/gauden/blob/main/backend/src/services/tokenService.ts"
click node_iap_service "https://github.com/mrphansum/gauden/blob/main/backend/src/services/iapService.ts"
click node_catalog_data "https://github.com/mrphansum/gauden/blob/main/backend/src/models/Module.ts"

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_ios_app,node_ios_root,node_ios_features,node_ios_api_models,node_ios_services,node_ios_iap,node_ios_api,node_ios_tokens,node_ios_config toneBlue
class node_api_entry,node_express_app,node_api_routes,node_auth_middleware,node_auth_services,node_iap_service,node_catalog_data toneAmber
class node_mongo,node_app_store,node_google,node_keychain toneMint
```

## Components

### iOS app

- [App entry](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/App/HomeApplicationFixApp.swift): SwiftUI app · `ios/HomeApplicationFix/App/HomeApplicationFixApp.swift`
- [Root routing & session](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/App/RootView.swift): SwiftUI state · `ios/HomeApplicationFix/App/RootView.swift`
- **Auth, catalog, detail & profile**: SwiftUI features · Guests see demos; entitlement unlocks full content.
- [API models](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Models/APIModels.swift): Swift models · `ios/HomeApplicationFix/Core/Models/APIModels.swift`
- [Auth & module services](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Services/AuthService.swift): domain services · `ios/HomeApplicationFix/Core/Services/AuthService.swift`
- [IAP service](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Services/IAPService.swift): StoreKit orchestration · `ios/HomeApplicationFix/Core/Services/IAPService.swift`
- [API client](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Networking/APIClient.swift): HTTP transport · `ios/HomeApplicationFix/Core/Networking/APIClient.swift`
- [Token store](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Keychain/TokenStore.swift): Keychain abstraction · Persists access and refresh tokens only through Keychain. · `ios/HomeApplicationFix/Core/Keychain/TokenStore.swift`
- [API base URL config](https://github.com/mrphansum/gauden/blob/main/ios/HomeApplicationFix/Core/Config/AppConfig.swift): runtime config · `ios/HomeApplicationFix/Core/Config/AppConfig.swift`

### Express API

- [Backend entry](https://github.com/mrphansum/gauden/blob/main/backend/src/index.ts): Node process · `backend/src/index.ts`
- [Express app](https://github.com/mrphansum/gauden/blob/main/backend/src/app.ts): API assembly · `backend/src/app.ts`
- **Auth, modules, IAP & account routes**: route layer · Provides catalog, protected content, verification, and account state.
- [JWT auth middleware](https://github.com/mrphansum/gauden/blob/main/backend/src/middleware/auth.ts): Express middleware · `backend/src/middleware/auth.ts`
- [Token & Google auth](https://github.com/mrphansum/gauden/blob/main/backend/src/services/tokenService.ts): auth services · Creates and rotates JWTs; validates Google ID tokens. · `backend/src/services/tokenService.ts`
- [Purchase verification](https://github.com/mrphansum/gauden/blob/main/backend/src/services/iapService.ts): IAP service · Verifies transactions and creates entitlements. · `backend/src/services/iapService.ts`
- [Modules & purchases](https://github.com/mrphansum/gauden/blob/main/backend/src/models/Module.ts): Mongo models · Data-driven catalog associates modules with App Store products. · `backend/src/models/Module.ts`

### External systems

- **MongoDB**: database · Stores users, refresh tokens, modules, and purchases.
- **Apple App Store**: IAP verification
- **Google OAuth**: identity provider
- **iOS Keychain**: secure storage

## Connections

- App entry → Root routing & session: launches
- Root routing & session → Auth, catalog, detail & profile: selects experience
- Auth, catalog, detail & profile → Auth & module services: uses
- Auth, catalog, detail & profile → IAP service: purchases/restores
- Auth & module services → API models: maps payloads
- Auth & module services → API client: calls
- IAP service → API client: submits transaction
- Auth & module services → Token store: reads/writes session
- Token store → iOS Keychain: stores tokens
- API base URL config → API client: configures base URL
- IAP service → Apple App Store: StoreKit 2
- API client → Backend entry: HTTPS API
- Backend entry → Express app: starts
- Express app → Auth, modules, IAP & account routes: mounts
- Auth, modules, IAP & account routes → JWT auth middleware: protects endpoints
- Auth, modules, IAP & account routes → Token & Google auth: login, refresh & Google login
- Token & Google auth → Google OAuth: validates ID token
- Auth, modules, IAP & account routes → Purchase verification: verifies purchase
- Purchase verification → Apple App Store: server verification
- Auth, modules, IAP & account routes → Modules & purchases: catalog and account state
- Token & Google auth → MongoDB: users & refresh tokens
- Modules & purchases → MongoDB: persists
- Purchase verification → MongoDB: persists purchases
