# thanreiz/nextstep architecture

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

- Interactive diagram: https://gitdiagram.com/thanreiz/nextstep
- Repository: https://github.com/thanreiz/nextstep

## Overview

Lunti is an offline-first rice-farming PWA that helps a farmer decide whether to drain a paddy, records confirmed actions, and supports block-level water-delivery planning. The core workflow is: configure a parcel and crop, refresh cached weather and typhoon data, assemble local readings into a decision input, apply safe-AWD rules, show the verdict, and record farmer-confirmed draining. The graph also includes water measurement, ledger, and source-information screens. Several screen and integration links rely on README or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`src/data/repositories/decisionRepository.ts`](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/decisionRepository.ts) (Decision assembly), [`src/App.tsx`](https://github.com/thanreiz/nextstep/blob/main/src/App.tsx) (App navigation), [`src/ui/screens/DecisionScreen.tsx`](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/DecisionScreen.tsx) (Decision screen), [`src/data/db.ts`](https://github.com/thanreiz/nextstep/blob/main/src/data/db.ts) (IndexedDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Farmer experience"]
  node_app["App navigation<br/>[App.tsx]"]
  node_onboarding["Parcel setup"]
  node_decision_ui["Decision screen<br/>[DecisionScreen.tsx]"]
  node_water_ui["Water entry<br/>[WaterScreen.tsx]"]
  node_ledger_ui["Action ledger<br/>[LedgerScreen.tsx]"]
  node_blocks_ui["Block schedule<br/>[BlocksScreen.tsx]"]
  node_tube_ui["Tube guide"]
  node_sources_ui["Sources screen<br/>[SourcesScreen.tsx]"]
end

subgraph group_coordination["Decision coordination"]
  node_decision_hook["Decision hook<br/>[useDecision.ts]"]
  node_refresh_hook["Refresh hook<br/>[useRefresh.ts]"]
  node_decision_repo["Decision assembly"]
end

subgraph group_agronomy["Agronomy and planning"]
  node_engine["AWD rules<br/>[awdEngine.ts]"]
  node_crop["Crop phenology<br/>[cropCycle.ts]"]
  node_weather_rules["Rain rules<br/>[weather.ts]"]
  node_hazard_rules["Typhoon assessment<br/>[hazard.ts]"]
  node_block_plan["Block planner<br/>[blockPlan.ts]"]
  node_ledger_math["Ledger estimates<br/>[ledger.ts]"]
end

subgraph group_data["Local data and integrations"]
  node_db[("IndexedDB<br/>[db.ts]")]
  node_parcel_repo["Parcel repository"]
  node_cycle_repo["Crop-cycle repository"]
  node_water_repo["Water-reading repository"]
  node_event_repo["Drain-event repository"]
  node_hazard_repo["Hazard repository"]
  node_weather_repo["Weather repository"]
  node_seed_repo["Demo observations<br/>[seed.ts]"]
  node_noah["NOAH track client<br/>[noah.ts]"]
  node_meteo["Open-Meteo client<br/>[openMeteo.ts]"]
  node_result["Typed results<br/>[result.ts]"]
  node_flags["Refresh flags<br/>[flags.ts]"]
end

subgraph group_language["Language and guidance"]
  node_i18n["Translations<br/>[index.ts]"]
  node_ui_i18n["Language provider<br/>[i18n.tsx]"]
end

node_farmer(("Farmer"))
node_noah_service["UP NOAH service"]
node_meteo_service["Open-Meteo service"]

node_farmer -->|"uses"| node_app
node_app -->|"routes to"| node_onboarding
node_app -->|"routes to"| node_decision_ui
node_app -->|"routes to"| node_water_ui
node_app -->|"routes to"| node_ledger_ui
node_app -->|"routes to"| node_blocks_ui
node_app -->|"routes to"| node_tube_ui
node_app -->|"routes to"| node_sources_ui
node_onboarding -->|"saves parcel"| node_parcel_repo
node_onboarding -->|"saves crop cycle"| node_cycle_repo
node_onboarding -->|"saves reading"| node_water_repo
node_onboarding -->|"seeds demo"| node_seed_repo
node_decision_ui -->|"gets verdict"| node_decision_hook
node_decision_ui -->|"requests refresh"| node_refresh_hook
node_decision_ui -->|"confirms drain"| node_event_repo
node_decision_hook -->|"requests decision"| node_decision_repo
node_refresh_hook -->|"refreshes weather"| node_weather_repo
node_refresh_hook -->|"refreshes hazard"| node_hazard_repo
node_decision_repo -->|"loads parcel"| node_parcel_repo
node_decision_repo -->|"loads crop cycle"| node_cycle_repo
node_decision_repo -->|"loads reading"| node_water_repo
node_decision_repo -->|"loads cached rain"| node_weather_repo
node_decision_repo -->|"loads threat"| node_hazard_repo
node_decision_repo -->|"runs rules"| node_engine
node_decision_repo -->|"plans block"| node_block_plan
node_engine -->|"checks stage"| node_crop
node_engine -->|"checks rainfall"| node_weather_rules
node_blocks_ui -->|"requests block plan"| node_decision_repo
node_ledger_ui -.->|"reads confirmed log"| node_event_repo
node_event_repo -->|"writes events"| node_db
node_parcel_repo -->|"reads and writes"| node_db
node_cycle_repo -->|"reads and writes"| node_db
node_water_repo -->|"reads and writes"| node_db
node_hazard_repo -->|"caches threat"| node_db
node_weather_repo -->|"caches forecast"| node_db
node_seed_repo -->|"writes demo data"| node_db
node_hazard_repo -->|"refreshes track"| node_noah
node_noah -->|"fetches track"| node_noah_service
node_weather_repo -->|"fetches forecast"| node_meteo
node_meteo -->|"requests forecast"| node_meteo_service
node_hazard_repo -->|"resolves threat"| node_hazard_rules
node_weather_repo -->|"uses staleness flags"| node_flags
node_hazard_repo -->|"returns typed result"| node_result
node_decision_ui -->|"shows estimates"| node_ledger_math
node_decision_ui -->|"translates verdict"| node_ui_i18n
node_ui_i18n -->|"loads translations"| node_i18n

click node_app "https://github.com/thanreiz/nextstep/blob/main/src/App.tsx"
click node_onboarding "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/OnboardingScreen.tsx"
click node_decision_ui "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/DecisionScreen.tsx"
click node_water_ui "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/WaterScreen.tsx"
click node_ledger_ui "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/LedgerScreen.tsx"
click node_blocks_ui "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/BlocksScreen.tsx"
click node_tube_ui "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/TubeGuideScreen.tsx"
click node_sources_ui "https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/SourcesScreen.tsx"
click node_decision_hook "https://github.com/thanreiz/nextstep/blob/main/src/ui/hooks/useDecision.ts"
click node_refresh_hook "https://github.com/thanreiz/nextstep/blob/main/src/ui/hooks/useRefresh.ts"
click node_decision_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/decisionRepository.ts"
click node_engine "https://github.com/thanreiz/nextstep/blob/main/src/domain/awdEngine.ts"
click node_crop "https://github.com/thanreiz/nextstep/blob/main/src/domain/cropCycle.ts"
click node_weather_rules "https://github.com/thanreiz/nextstep/blob/main/src/domain/weather.ts"
click node_hazard_rules "https://github.com/thanreiz/nextstep/blob/main/src/domain/hazard.ts"
click node_block_plan "https://github.com/thanreiz/nextstep/blob/main/src/domain/blockPlan.ts"
click node_ledger_math "https://github.com/thanreiz/nextstep/blob/main/src/domain/ledger.ts"
click node_db "https://github.com/thanreiz/nextstep/blob/main/src/data/db.ts"
click node_parcel_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/parcelRepository.ts"
click node_cycle_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/cropCycleRepository.ts"
click node_water_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/waterReadingRepository.ts"
click node_event_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/drainEventRepository.ts"
click node_hazard_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/hazardRepository.ts"
click node_weather_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/weatherRepository.ts"
click node_seed_repo "https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/seed.ts"
click node_noah "https://github.com/thanreiz/nextstep/blob/main/src/data/noah.ts"
click node_meteo "https://github.com/thanreiz/nextstep/blob/main/src/data/openMeteo.ts"
click node_i18n "https://github.com/thanreiz/nextstep/blob/main/src/i18n/index.ts"
click node_ui_i18n "https://github.com/thanreiz/nextstep/blob/main/src/ui/i18n.tsx"
click node_result "https://github.com/thanreiz/nextstep/blob/main/src/data/result.ts"
click node_flags "https://github.com/thanreiz/nextstep/blob/main/src/data/flags.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_app,node_onboarding,node_decision_ui,node_water_ui,node_ledger_ui,node_blocks_ui,node_tube_ui,node_sources_ui toneBlue
class node_decision_hook,node_refresh_hook,node_decision_repo toneAmber
class node_engine,node_crop,node_weather_rules,node_hazard_rules,node_block_plan,node_ledger_math toneMint
class node_db,node_parcel_repo,node_cycle_repo,node_water_repo,node_event_repo,node_hazard_repo,node_weather_repo,node_seed_repo,node_noah,node_meteo,node_result,node_flags toneRose
class node_i18n,node_ui_i18n,node_farmer,node_noah_service,node_meteo_service toneIndigo
```

## Components

### Farmer experience

- [App navigation](https://github.com/thanreiz/nextstep/blob/main/src/App.tsx): `src/App.tsx`
- [Parcel setup](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/OnboardingScreen.tsx): `src/ui/screens/OnboardingScreen.tsx`
- [Decision screen](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/DecisionScreen.tsx): `src/ui/screens/DecisionScreen.tsx`
- [Water entry](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/WaterScreen.tsx): `src/ui/screens/WaterScreen.tsx`
- [Action ledger](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/LedgerScreen.tsx): `src/ui/screens/LedgerScreen.tsx`
- [Block schedule](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/BlocksScreen.tsx): `src/ui/screens/BlocksScreen.tsx`
- [Tube guide](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/TubeGuideScreen.tsx): `src/ui/screens/TubeGuideScreen.tsx`
- [Sources screen](https://github.com/thanreiz/nextstep/blob/main/src/ui/screens/SourcesScreen.tsx): `src/ui/screens/SourcesScreen.tsx`

### Decision coordination

- [Decision hook](https://github.com/thanreiz/nextstep/blob/main/src/ui/hooks/useDecision.ts): `src/ui/hooks/useDecision.ts`
- [Refresh hook](https://github.com/thanreiz/nextstep/blob/main/src/ui/hooks/useRefresh.ts): `src/ui/hooks/useRefresh.ts`
- [Decision assembly](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/decisionRepository.ts): `src/data/repositories/decisionRepository.ts`

### Agronomy and planning

- [AWD rules](https://github.com/thanreiz/nextstep/blob/main/src/domain/awdEngine.ts): `src/domain/awdEngine.ts`
- [Crop phenology](https://github.com/thanreiz/nextstep/blob/main/src/domain/cropCycle.ts): `src/domain/cropCycle.ts`
- [Rain rules](https://github.com/thanreiz/nextstep/blob/main/src/domain/weather.ts): `src/domain/weather.ts`
- [Typhoon assessment](https://github.com/thanreiz/nextstep/blob/main/src/domain/hazard.ts): `src/domain/hazard.ts`
- [Block planner](https://github.com/thanreiz/nextstep/blob/main/src/domain/blockPlan.ts): `src/domain/blockPlan.ts`
- [Ledger estimates](https://github.com/thanreiz/nextstep/blob/main/src/domain/ledger.ts): `src/domain/ledger.ts`

### Local data and integrations

- [IndexedDB](https://github.com/thanreiz/nextstep/blob/main/src/data/db.ts): `src/data/db.ts`
- [Parcel repository](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/parcelRepository.ts): `src/data/repositories/parcelRepository.ts`
- [Crop-cycle repository](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/cropCycleRepository.ts): `src/data/repositories/cropCycleRepository.ts`
- [Water-reading repository](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/waterReadingRepository.ts): `src/data/repositories/waterReadingRepository.ts`
- [Drain-event repository](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/drainEventRepository.ts): `src/data/repositories/drainEventRepository.ts`
- [Hazard repository](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/hazardRepository.ts): `src/data/repositories/hazardRepository.ts`
- [Weather repository](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/weatherRepository.ts): `src/data/repositories/weatherRepository.ts`
- [Demo observations](https://github.com/thanreiz/nextstep/blob/main/src/data/repositories/seed.ts): `src/data/repositories/seed.ts`
- [NOAH track client](https://github.com/thanreiz/nextstep/blob/main/src/data/noah.ts): `src/data/noah.ts`
- [Open-Meteo client](https://github.com/thanreiz/nextstep/blob/main/src/data/openMeteo.ts): `src/data/openMeteo.ts`
- [Typed results](https://github.com/thanreiz/nextstep/blob/main/src/data/result.ts): `src/data/result.ts`
- [Refresh flags](https://github.com/thanreiz/nextstep/blob/main/src/data/flags.ts): `src/data/flags.ts`

### Language and guidance

- [Translations](https://github.com/thanreiz/nextstep/blob/main/src/i18n/index.ts): `src/i18n/index.ts`
- [Language provider](https://github.com/thanreiz/nextstep/blob/main/src/ui/i18n.tsx): `src/ui/i18n.tsx`

### Other components

- **Farmer**
- **UP NOAH service**
- **Open-Meteo service**

## Connections

- Farmer → App navigation: uses (evidence: `README.md`)
- App navigation → Parcel setup: routes to (evidence: `src/App.tsx`)
- App navigation → Decision screen: routes to (evidence: `src/App.tsx`)
- App navigation → Water entry: routes to (evidence: `src/App.tsx`)
- App navigation → Action ledger: routes to (evidence: `src/App.tsx`)
- App navigation → Block schedule: routes to (evidence: `src/App.tsx`)
- App navigation → Tube guide: routes to (evidence: `src/App.tsx`)
- App navigation → Sources screen: routes to (evidence: `src/App.tsx`)
- Parcel setup → Parcel repository: saves parcel (evidence: `src/ui/screens/OnboardingScreen.tsx`)
- Parcel setup → Crop-cycle repository: saves crop cycle (evidence: `src/ui/screens/OnboardingScreen.tsx`)
- Parcel setup → Water-reading repository: saves reading (evidence: `src/ui/screens/OnboardingScreen.tsx`)
- Parcel setup → Demo observations: seeds demo (evidence: `src/ui/screens/OnboardingScreen.tsx`)
- Decision screen → Decision hook: gets verdict (evidence: `src/ui/screens/DecisionScreen.tsx`)
- Decision screen → Refresh hook: requests refresh (evidence: `src/ui/screens/DecisionScreen.tsx`)
- Decision screen → Drain-event repository: confirms drain (evidence: `src/ui/screens/DecisionScreen.tsx`)
- Decision hook → Decision assembly: requests decision (evidence: `src/ui/hooks/useDecision.ts`)
- Refresh hook → Weather repository: refreshes weather (evidence: `src/ui/hooks/useRefresh.ts`)
- Refresh hook → Hazard repository: refreshes hazard (evidence: `src/ui/hooks/useRefresh.ts`)
- Decision assembly → Parcel repository: loads parcel (evidence: `src/data/repositories/decisionRepository.ts`)
- Decision assembly → Crop-cycle repository: loads crop cycle (evidence: `src/data/repositories/decisionRepository.ts`)
- Decision assembly → Water-reading repository: loads reading (evidence: `src/data/repositories/decisionRepository.ts`)
- Decision assembly → Weather repository: loads cached rain (evidence: `src/data/repositories/decisionRepository.ts`)
- Decision assembly → Hazard repository: loads threat (evidence: `src/data/repositories/decisionRepository.ts`)
- Decision assembly → AWD rules: runs rules (evidence: `src/data/repositories/decisionRepository.ts`)
- Decision assembly → Block planner: plans block (evidence: `src/data/repositories/decisionRepository.ts`)
- AWD rules → Crop phenology: checks stage (evidence: `src/domain/awdEngine.ts`)
- AWD rules → Rain rules: checks rainfall (evidence: `src/domain/awdEngine.ts`)
- Block schedule → Decision assembly: requests block plan (evidence: `src/ui/screens/BlocksScreen.tsx`)
- Action ledger → Drain-event repository: reads confirmed log
- Drain-event repository → IndexedDB: writes events (evidence: `src/data/repositories/drainEventRepository.ts`)
- Parcel repository → IndexedDB: reads and writes (evidence: `src/data/repositories/parcelRepository.ts`)
- Crop-cycle repository → IndexedDB: reads and writes (evidence: `src/data/repositories/cropCycleRepository.ts`)
- Water-reading repository → IndexedDB: reads and writes (evidence: `src/data/repositories/waterReadingRepository.ts`)
- Hazard repository → IndexedDB: caches threat (evidence: `src/data/repositories/hazardRepository.ts`)
- Weather repository → IndexedDB: caches forecast (evidence: `src/data/repositories/weatherRepository.ts`)
- Demo observations → IndexedDB: writes demo data (evidence: `src/data/repositories/seed.ts`)
- Hazard repository → NOAH track client: refreshes track (evidence: `src/data/repositories/hazardRepository.ts`)
- NOAH track client → UP NOAH service: fetches track (evidence: `README.md`)
- Weather repository → Open-Meteo client: fetches forecast (evidence: `src/data/repositories/weatherRepository.ts`)
- Open-Meteo client → Open-Meteo service: requests forecast (evidence: `README.md`)
- Hazard repository → Typhoon assessment: resolves threat (evidence: `src/data/repositories/hazardRepository.ts`)
- Weather repository → Refresh flags: uses staleness flags (evidence: `src/data/repositories/weatherRepository.ts`)
- Hazard repository → Typed results: returns typed result (evidence: `src/data/repositories/hazardRepository.ts`)
- Decision screen → Ledger estimates: shows estimates (evidence: `src/ui/screens/DecisionScreen.tsx`)
- Decision screen → Language provider: translates verdict (evidence: `src/ui/screens/DecisionScreen.tsx`)
- Language provider → Translations: loads translations (evidence: `src/ui/i18n.tsx`)
