# ajoel-m/mi-casa-segura architecture

> Architecture diagram of the GitHub repository ajoel-m/mi-casa-segura, 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/ajoel-m/mi-casa-segura
- Repository: https://github.com/ajoel-m/mi-casa-segura

## Overview

#### Purpose and delivery model
Mi Casa Segura is a mobile-oriented, static React SPA for self-assessing residential exposure to earthquakes and alluvions in Peru. It combines user-provided housing data with browser location and local hazard/risk rules, then presents a referential result and captures demand for professional advice. Main bootstrapping is `src/main.tsx` and `src/App.tsx`; Vite builds the deployable static bundle (`vite.config.ts`).

#### User journeys and entry surfaces
The application has landing, assessment, and results surfaces, with both page- and view-oriented implementations present:
- Lead/smoke-test entry: `src/pages/LandingPage.tsx`, `src/components/forms/SmokeTestSection.tsx`
- Guided evaluation: `src/pages/AssessmentPage.tsx`, `src/views/EvaluationFlow.tsx`
- Risk output: `src/pages/ResultsPage.tsx`, `src/views/ResultView.tsx`

The dual `pages/` and `views/` structures indicate potentially overlapping application compositions that should be reconciled before major changes.

#### Assessment state boundary
React Context holds cross-step assessment state so the questionnaire can advance without server-side sessions or route-dependent persistence. Relevant providers coexist:
- `src/context/EvaluationContext.tsx`
- `src/contexts/AssessmentContext.tsx`
- `src/types/assessment.ts`

This is the central client-side boundary between UI capture, location selection, risk computation, and results. The duplicate context directories similarly merit ownership clarification.

#### Guided data collection flow
The assessment is organized as sequential UI stages, coordinated by layout/progress components:
- `src/components/steps/LocationStep.tsx`
- `src/components/steps/HomeInfoStep.tsx`
- `src/components/steps/HazardsStep.tsx`
- `src/components/steps/AnalysisStep.tsx`
- `src/components/layout/StepIndicator.tsx`

Housing characteristics are captured through `src/components/forms/HousingForm.tsx`. A scanning stage exists in `src/components/steps/ScanStep.tsx`, but README describes vision-based structural scanning as future scope; it should not be treated as a production external-AI integration without code verification.

#### Geolocation and map interaction
Location is acquired through the browser Geolocation API and exposed to the flow through `src/hooks/useGPS.ts`. Users can inspect or adjust the point in Leaflet/OpenStreetMap map components:
- `src/components/map/LeafletMap.tsx`
- `src/components/common/HazardMap.tsx`

This boundary depends on browser permission and third-party OpenStreetMap tile availability, but the app has no required paid map API or backend geocoding service.

#### Local hazard and risk evaluation
Risk calculation is designed as local, UI-independent logic, orchestrated from a React hook:
- `src/hooks/useRiskEngine.ts`
- `src/services/riskEngine.ts`
- `src/data/hazardZones.ts`

Inputs flow from assessment context—coordinates and housing/form answers—into the risk engine. The output feeds analysis/result views and likely map visualizations. Supporting regional/mock datasets are local assets (`src/services/data/peruRegionsData.ts`, `src/services/data/mockData.ts`), meaning current results are client-computed and constrained by bundled data rather than live INAIGEM services.

#### Runtime, infrastructure, and documentation
Runtime is React 18+/TypeScript in the browser, bundled by Vite, styled with Tailwind, and uses Leaflet/React Leaflet plus Lucide icons. The intended infrastructure is serverless static hosting such as Vercel, Netlify, or GitHub Pages; no API, database, authentication provider, or server runtime is represented in the tree. Product and technical intent are documented in `docs/architecture/system-architecture.md`, `docs/product/specifications.md`, and `docs/methodology/validation-board.md`.

Main entry points: [`src/views/EvaluationFlow.tsx`](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/views/EvaluationFlow.tsx) (Guided evaluation), [`src/contexts/AssessmentContext.tsx`](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/contexts/AssessmentContext.tsx) (Assessment state), [`src/App.tsx`](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/App.tsx) (React app shell), [`src/components/steps/LocationStep.tsx`](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/steps/LocationStep.tsx) (Sequential steps)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_app["React app shell<br/>browser SPA<br/>[App.tsx]"]
  node_landing["Landing and lead entry<br/>page<br/>[LandingPage.tsx]"]
  node_smoke_test["Lead form<br/>form section"]
  node_assessment_page["Assessment page<br/>page composition<br/>[AssessmentPage.tsx]"]
  node_map["Interactive hazard map<br/>Leaflet map<br/>[LeafletMap.tsx]"]
  node_results_page["Results page<br/>page composition<br/>[ResultsPage.tsx]"]
  node_result_view["Risk result<br/>view composition<br/>[ResultView.tsx]"]
end

subgraph group_assessment["Assessment flow"]
  node_evaluation_flow["Guided evaluation<br/>view composition<br/>[EvaluationFlow.tsx]"]
  node_assessment_context["Assessment state<br/>React context"]
  node_evaluation_context["Evaluation state<br/>React context"]
  node_assessment_types["Assessment model<br/>TypeScript types<br/>[assessment.ts]"]
  node_step_flow["Sequential steps<br/>step components<br/>[LocationStep.tsx]"]
  node_housing_form["Housing form<br/>[HousingForm.tsx]"]
  node_step_indicator["Step progress<br/>layout component<br/>[StepIndicator.tsx]"]
  node_gps["Browser geolocation<br/>React hook<br/>[useGPS.ts]"]
end

subgraph group_risk["Local risk evaluation"]
  node_risk_hook["Risk engine hook<br/>React hook<br/>[useRiskEngine.ts]"]
  node_risk_engine{{"Risk calculator<br/>local service<br/>[riskEngine.ts]"}}
  node_hazard_zones[("Hazard zones<br/>bundled dataset<br/>[hazardZones.ts]")]
  node_supporting_data[("Regional and mock data<br/>bundled datasets<br/>[peruRegionsData.ts]")]
end

node_vite["Vite static bundle<br/>build and delivery<br/>[vite.config.ts]"]

node_vite -->|"bundles"| node_app
node_app -->|"renders"| node_landing
node_landing -->|"captures lead"| node_smoke_test
node_app -->|"renders"| node_assessment_page
node_assessment_page -.->|"composes"| node_evaluation_flow
node_evaluation_flow -->|"reads and updates"| node_assessment_context
node_evaluation_flow -.->|"may coordinate"| node_evaluation_context
node_assessment_context -->|"uses"| node_assessment_types
node_evaluation_flow -->|"advances through"| node_step_flow
node_evaluation_flow -->|"shows progress"| node_step_indicator
node_step_flow -->|"collects housing data"| node_housing_form
node_step_flow -->|"acquires location"| node_gps
node_gps -->|"stores coordinates"| node_assessment_context
node_step_flow -->|"inspects or adjusts point"| node_map
node_map -->|"updates location"| node_assessment_context
node_assessment_context -->|"provides inputs"| node_risk_hook
node_risk_hook -->|"orchestrates"| node_risk_engine
node_risk_engine -->|"queries"| node_hazard_zones
node_risk_engine -->|"uses"| node_supporting_data
node_risk_hook -->|"supplies result"| node_result_view
node_app -->|"renders"| node_results_page
node_results_page -.->|"composes"| node_result_view
node_result_view -.->|"visualizes risk location"| node_map

click node_vite "https://github.com/ajoel-m/mi-casa-segura/blob/main/vite.config.ts"
click node_app "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/App.tsx"
click node_landing "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/pages/LandingPage.tsx"
click node_smoke_test "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/forms/SmokeTestSection.tsx"
click node_assessment_page "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/pages/AssessmentPage.tsx"
click node_evaluation_flow "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/views/EvaluationFlow.tsx"
click node_assessment_context "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/contexts/AssessmentContext.tsx"
click node_evaluation_context "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/context/EvaluationContext.tsx"
click node_assessment_types "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/types/assessment.ts"
click node_step_flow "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/steps/LocationStep.tsx"
click node_housing_form "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/forms/HousingForm.tsx"
click node_step_indicator "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/layout/StepIndicator.tsx"
click node_gps "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/hooks/useGPS.ts"
click node_map "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/map/LeafletMap.tsx"
click node_risk_hook "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/hooks/useRiskEngine.ts"
click node_risk_engine "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/services/riskEngine.ts"
click node_hazard_zones "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/data/hazardZones.ts"
click node_supporting_data "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/services/data/peruRegionsData.ts"
click node_results_page "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/pages/ResultsPage.tsx"
click node_result_view "https://github.com/ajoel-m/mi-casa-segura/blob/main/src/views/ResultView.tsx"

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_landing,node_smoke_test,node_assessment_page,node_map,node_results_page,node_result_view toneBlue
class node_evaluation_flow,node_assessment_context,node_evaluation_context,node_assessment_types,node_step_flow,node_housing_form,node_step_indicator,node_gps toneAmber
class node_risk_hook,node_risk_engine,node_hazard_zones,node_supporting_data toneMint
class node_vite toneNeutral
```

## Components

### User interface

- [React app shell](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/App.tsx): browser SPA · `src/App.tsx`
- [Landing and lead entry](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/pages/LandingPage.tsx): page · `src/pages/LandingPage.tsx`
- [Lead form](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/forms/SmokeTestSection.tsx): form section · `src/components/forms/SmokeTestSection.tsx`
- [Assessment page](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/pages/AssessmentPage.tsx): page composition · Overlaps with the view-oriented evaluation composition. · `src/pages/AssessmentPage.tsx`
- [Interactive hazard map](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/map/LeafletMap.tsx): Leaflet map · Uses OpenStreetMap tiles. · `src/components/map/LeafletMap.tsx`
- [Results page](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/pages/ResultsPage.tsx): page composition · Overlaps with the view-oriented result composition. · `src/pages/ResultsPage.tsx`
- [Risk result](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/views/ResultView.tsx): view composition · `src/views/ResultView.tsx`

### Assessment flow

- [Guided evaluation](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/views/EvaluationFlow.tsx): view composition · Overlaps with the page-oriented assessment composition. · `src/views/EvaluationFlow.tsx`
- [Assessment state](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/contexts/AssessmentContext.tsx): React context · Cross-step client-side state boundary. · `src/contexts/AssessmentContext.tsx`
- [Evaluation state](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/context/EvaluationContext.tsx): React context · Coexisting context ownership needs clarification. · `src/context/EvaluationContext.tsx`
- [Assessment model](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/types/assessment.ts): TypeScript types · `src/types/assessment.ts`
- [Sequential steps](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/steps/LocationStep.tsx): step components · Location, home information, hazards, and analysis stages. · `src/components/steps/LocationStep.tsx`
- [Housing form](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/forms/HousingForm.tsx): form · `src/components/forms/HousingForm.tsx`
- [Step progress](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/components/layout/StepIndicator.tsx): layout component · `src/components/layout/StepIndicator.tsx`
- [Browser geolocation](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/hooks/useGPS.ts): React hook · Depends on browser location permission. · `src/hooks/useGPS.ts`

### Local risk evaluation

- [Risk engine hook](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/hooks/useRiskEngine.ts): React hook · `src/hooks/useRiskEngine.ts`
- [Risk calculator](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/services/riskEngine.ts): local service · Computes referential risk entirely in the browser. · `src/services/riskEngine.ts`
- [Hazard zones](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/data/hazardZones.ts): bundled dataset · `src/data/hazardZones.ts`
- [Regional and mock data](https://github.com/ajoel-m/mi-casa-segura/blob/main/src/services/data/peruRegionsData.ts): bundled datasets · `src/services/data/peruRegionsData.ts`

### Other components

- [Vite static bundle](https://github.com/ajoel-m/mi-casa-segura/blob/main/vite.config.ts): build and delivery · Builds the browser-deployable SPA. · `vite.config.ts`

## Connections

- Vite static bundle → React app shell: bundles
- React app shell → Landing and lead entry: renders
- Landing and lead entry → Lead form: captures lead
- React app shell → Assessment page: renders
- Assessment page → Guided evaluation: composes
- Guided evaluation → Assessment state: reads and updates
- Guided evaluation → Evaluation state: may coordinate
- Assessment state → Assessment model: uses
- Guided evaluation → Sequential steps: advances through
- Guided evaluation → Step progress: shows progress
- Sequential steps → Housing form: collects housing data
- Sequential steps → Browser geolocation: acquires location
- Browser geolocation → Assessment state: stores coordinates
- Sequential steps → Interactive hazard map: inspects or adjusts point
- Interactive hazard map → Assessment state: updates location
- Assessment state → Risk engine hook: provides inputs
- Risk engine hook → Risk calculator: orchestrates
- Risk calculator → Hazard zones: queries
- Risk calculator → Regional and mock data: uses
- Risk engine hook → Risk result: supplies result
- React app shell → Results page: renders
- Results page → Risk result: composes
- Risk result → Interactive hazard map: visualizes risk location
