# daiwanmaru/susu-car-seeker architecture

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

- Interactive diagram: https://gitdiagram.com/daiwanmaru/susu-car-seeker
- Repository: https://github.com/daiwanmaru/susu-car-seeker

## Overview

#### Purpose and Entry Points
速速找車 is a Flutter Android/iOS parking-memory app: it records a parking session locally, helps locate the vehicle, tracks bills, and calculates time-based charges. The Flutter bootstrap is `lib/main.dart`, which composes the application shell in `lib/app/susu_app.dart`; Android and iOS host it through `android/app/src/main/kotlin/tw/susuparking/susu_parking/MainActivity.kt` and `ios/Runner/AppDelegate.swift`.

#### Application Composition and State
`lib/app/app_scope.dart` is the dependency/state boundary for app-wide services and repositories. `lib/app/app_controller.dart` coordinates startup, authentication/session restoration, and app-level state; `lib/app/app_theme.dart` provides shared presentation configuration. `lib/screens/main_shell.dart` is the authenticated navigation container, while `lib/screens/login_screen.dart` gates access through Google sign-in or debug preview mode.

#### Local-First Parking Domain
The authoritative user data remains on-device. Domain entities and pure pricing/time logic are separated in `lib/domain/models.dart` and `lib/domain/parking_calculator.dart`. Parking sessions are created/edited, restored after relaunch, and ended through UI stages including `lib/screens/home_screen.dart`, `lib/screens/edit_parking_screen.dart`, and `lib/screens/find_vehicle_screen.dart`. Derived values—elapsed duration, fee estimate, and next billing point—are recalculated from persisted facts rather than stored as authoritative aggregates.

#### Persistence, Bills, and History
SQLite access is centralized in `lib/data/app_database.dart`; `lib/data/parking_repository.dart` owns parking sessions, bills, photos, and deletion workflows. App preferences such as feature/settings state belong in `lib/data/settings_repository.dart`. The main downstream flow is: screens/controller invoke repository operations; SQLite retains parking facts and local media references; history and detail screens read those records to render active/history states. Relevant UI boundaries are `lib/screens/bill_form_screen.dart`, `lib/screens/history_screen.dart`, and `lib/screens/history_detail_screen.dart`.

#### Device Integrations
Platform-facing capabilities are isolated behind services: GPS permission/high-accuracy location in `lib/services/location_service.dart`, map handoff in `lib/services/map_service.dart`, and local photo capture/storage in `lib/services/media_service.dart`. `lib/services/notification_service.dart` schedules local reminders before the next charge point. These integrations feed local session data; parking records, images, and bills are not uploaded to the account backend.

#### Authentication and Remote Account Boundary
`lib/services/auth_service.dart` manages Google identity, offline restoration, and the development preview path. `lib/services/backend_service.dart` calls the narrowly scoped account API. The Cloudflare Worker implementation is `backend/src/index.ts`, deployed/configured through `backend/wrangler.jsonc`, with user/account state held in Cloudflare D1 according to `backend/schema.sql`. Its boundary is intentionally limited to validating Google ID tokens and maintaining user ID, account status, and last-login metadata.

#### Monetization and Platform Delivery
Ads and entitlement purchases are client-side integrations: `lib/services/purchase_service.dart` handles the non-consumable `remove_ads` purchase/restore flow, while ad configuration is supplied via Flutter build defines. Flutter packages and runtime dependencies are declared in `pubspec.yaml`; native Android/iOS packaging remains under `android/app/` and `ios/Runner/`. External production dependencies are Google OAuth, Cloudflare Workers/D1, optional AdMob banner inventory, and Play/App Store in-app purchase catalogs.

Main entry points: [`lib/screens/home_screen.dart`](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/home_screen.dart) (Parking workflow), [`lib/data/parking_repository.dart`](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/parking_repository.dart) (Parking repository), [`lib/app/app_scope.dart`](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/app_scope.dart) (App scope), [`lib/app/app_controller.dart`](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/app_controller.dart) (App controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flutter["Flutter app"]
  node_bootstrap["Flutter bootstrap<br/>entry point<br/>[main.dart]"]
  node_app["App shell<br/>composition<br/>[susu_app.dart]"]
  node_scope["App scope<br/>dependency boundary<br/>[app_scope.dart]"]
  node_controller["App controller<br/>application state"]
  node_login["Login gate<br/>screen<br/>[login_screen.dart]"]
  node_main_shell["Main navigation<br/>authenticated shell<br/>[main_shell.dart]"]
  node_parking_screens["Parking workflow<br/>screens<br/>[home_screen.dart]"]
  node_history_screens["Bills and history<br/>screens"]
end

subgraph group_local["Local-first data"]
  node_domain["Parking domain<br/>entities and pricing"]
  node_parking_repo["Parking repository<br/>local repository"]
  node_database[("SQLite database<br/>local persistence<br/>[app_database.dart]")]
  node_settings["Settings repository<br/>preferences"]
end

subgraph group_device["Device integrations"]
  node_auth["Auth service<br/>identity service<br/>[auth_service.dart]"]
  node_location["Location service<br/>GPS integration"]
  node_maps["Map service<br/>map handoff<br/>[map_service.dart]"]
  node_media["Media service<br/>photo storage<br/>[media_service.dart]"]
  node_notifications["Notification service<br/>local reminders"]
  node_purchases["Purchase service<br/>entitlements"]
end

subgraph group_account["Account backend"]
  node_backend_client["Account API client<br/>backend service"]
  node_worker{{"Cloudflare Worker<br/>account API<br/>[index.ts]"}}
  node_d1[("Cloudflare D1<br/>account database<br/>[schema.sql]")]
end

node_bootstrap -->|"starts"| node_app
node_app -->|"composes"| node_scope
node_scope -->|"provides"| node_controller
node_controller -->|"gates access"| node_login
node_login -->|"signs in"| node_auth
node_controller -->|"opens after session"| node_main_shell
node_main_shell -->|"navigates"| node_parking_screens
node_main_shell -->|"navigates"| node_history_screens
node_parking_screens -->|"creates and updates"| node_parking_repo
node_history_screens -->|"reads records"| node_parking_repo
node_parking_repo -->|"persists"| node_database
node_parking_screens -->|"calculates"| node_domain
node_parking_repo -->|"derives values"| node_domain
node_parking_screens -->|"captures location"| node_location
node_parking_screens -->|"opens navigation"| node_maps
node_parking_screens -->|"stores photos"| node_media
node_parking_repo -->|"schedules charge reminders"| node_notifications
node_scope -->|"provides"| node_settings
node_scope -->|"provides"| node_purchases
node_auth -->|"syncs account identity"| node_backend_client
node_backend_client -->|"calls"| node_worker
node_worker -->|"maintains account state"| node_d1

click node_bootstrap "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/main.dart"
click node_app "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/susu_app.dart"
click node_scope "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/app_scope.dart"
click node_controller "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/app_controller.dart"
click node_login "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/login_screen.dart"
click node_main_shell "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/main_shell.dart"
click node_parking_screens "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/home_screen.dart"
click node_history_screens "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/history_screen.dart"
click node_domain "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/domain/parking_calculator.dart"
click node_parking_repo "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/parking_repository.dart"
click node_database "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/app_database.dart"
click node_settings "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/settings_repository.dart"
click node_auth "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/auth_service.dart"
click node_location "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/location_service.dart"
click node_maps "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/map_service.dart"
click node_media "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/media_service.dart"
click node_notifications "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/notification_service.dart"
click node_purchases "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/purchase_service.dart"
click node_backend_client "https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/backend_service.dart"
click node_worker "https://github.com/daiwanmaru/susu-car-seeker/blob/main/backend/src/index.ts"
click node_d1 "https://github.com/daiwanmaru/susu-car-seeker/blob/main/backend/schema.sql"

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_bootstrap,node_app,node_scope,node_controller,node_login,node_main_shell,node_parking_screens,node_history_screens toneBlue
class node_domain,node_parking_repo,node_database,node_settings toneAmber
class node_auth,node_location,node_maps,node_media,node_notifications,node_purchases toneMint
class node_backend_client,node_worker,node_d1 toneRose
```

## Components

### Flutter app

- [Flutter bootstrap](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/main.dart): entry point · `lib/main.dart`
- [App shell](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/susu_app.dart): composition · `lib/app/susu_app.dart`
- [App scope](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/app_scope.dart): dependency boundary · Provides app-wide services and repositories. · `lib/app/app_scope.dart`
- [App controller](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/app/app_controller.dart): application state · Coordinates startup and session restoration. · `lib/app/app_controller.dart`
- [Login gate](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/login_screen.dart): screen · `lib/screens/login_screen.dart`
- [Main navigation](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/main_shell.dart): authenticated shell · `lib/screens/main_shell.dart`
- [Parking workflow](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/home_screen.dart): screens · Create, edit, and locate active parking sessions. · `lib/screens/home_screen.dart`
- [Bills and history](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/screens/history_screen.dart): screens · Renders bills, historical sessions, and details. · `lib/screens/history_screen.dart`

### Local-first data

- [Parking domain](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/domain/parking_calculator.dart): entities and pricing · Calculates duration, fees, and next billing point from facts. · `lib/domain/parking_calculator.dart`
- [Parking repository](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/parking_repository.dart): local repository · Owns sessions, bills, photos, and deletion workflows. · `lib/data/parking_repository.dart`
- [SQLite database](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/app_database.dart): local persistence · Retains parking facts and local media references. · `lib/data/app_database.dart`
- [Settings repository](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/data/settings_repository.dart): preferences · `lib/data/settings_repository.dart`

### Device integrations

- [Auth service](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/auth_service.dart): identity service · Handles Google identity, offline restoration, and debug preview. · `lib/services/auth_service.dart`
- [Location service](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/location_service.dart): GPS integration · `lib/services/location_service.dart`
- [Map service](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/map_service.dart): map handoff · `lib/services/map_service.dart`
- [Media service](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/media_service.dart): photo storage · `lib/services/media_service.dart`
- [Notification service](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/notification_service.dart): local reminders · Schedules reminders before the next charge point. · `lib/services/notification_service.dart`
- [Purchase service](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/purchase_service.dart): entitlements · Handles remove-ads purchase and restore. · `lib/services/purchase_service.dart`

### Account backend

- [Account API client](https://github.com/daiwanmaru/susu-car-seeker/blob/main/lib/services/backend_service.dart): backend service · Calls the narrow account API only. · `lib/services/backend_service.dart`
- [Cloudflare Worker](https://github.com/daiwanmaru/susu-car-seeker/blob/main/backend/src/index.ts): account API · Validates Google tokens and maintains account metadata. · `backend/src/index.ts`
- [Cloudflare D1](https://github.com/daiwanmaru/susu-car-seeker/blob/main/backend/schema.sql): account database · Stores user ID, status, and last-login metadata. · `backend/schema.sql`

## Connections

- Flutter bootstrap → App shell: starts
- App shell → App scope: composes
- App scope → App controller: provides
- App controller → Login gate: gates access
- Login gate → Auth service: signs in
- App controller → Main navigation: opens after session
- Main navigation → Parking workflow: navigates
- Main navigation → Bills and history: navigates
- Parking workflow → Parking repository: creates and updates
- Bills and history → Parking repository: reads records
- Parking repository → SQLite database: persists
- Parking workflow → Parking domain: calculates
- Parking repository → Parking domain: derives values
- Parking workflow → Location service: captures location
- Parking workflow → Map service: opens navigation
- Parking workflow → Media service: stores photos
- Parking repository → Notification service: schedules charge reminders
- App scope → Settings repository: provides
- App scope → Purchase service: provides
- Auth service → Account API client: syncs account identity
- Account API client → Cloudflare Worker: calls
- Cloudflare Worker → Cloudflare D1: maintains account state
