How ajoel-m/mi-casa-segura works
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: EvaluationFlow.tsx Guided evaluation · AssessmentContext.tsx Assessment state · App.tsx React app shell · LocationStep.tsx Sequential steps
Components 20
User interface
- React app shell
src/App.tsx - Landing and lead entry
src/pages/LandingPage.tsx - Lead form
src/components/forms/SmokeTestSection.tsx - Assessment page · Overlaps with the view-oriented evaluation composition.
src/pages/AssessmentPage.tsx - Interactive hazard map · Uses OpenStreetMap tiles.
src/components/map/LeafletMap.tsx - Results page · Overlaps with the view-oriented result composition.
src/pages/ResultsPage.tsx - Risk result
src/views/ResultView.tsx
Assessment flow
- Guided evaluation · Overlaps with the page-oriented assessment composition.
src/views/EvaluationFlow.tsx - Assessment state · Cross-step client-side state boundary.
src/contexts/AssessmentContext.tsx - Evaluation state · Coexisting context ownership needs clarification.
src/context/EvaluationContext.tsx - Assessment model
src/types/assessment.ts - Sequential steps · Location, home information, hazards, and analysis stages.
src/components/steps/LocationStep.tsx - Housing form
src/components/forms/HousingForm.tsx - Step progress
src/components/layout/StepIndicator.tsx - Browser geolocation · Depends on browser location permission.
src/hooks/useGPS.ts
Local risk evaluation
- Risk engine hook
src/hooks/useRiskEngine.ts - Risk calculator · Computes referential risk entirely in the browser.
src/services/riskEngine.ts - Hazard zones
src/data/hazardZones.ts - Regional and mock data
src/services/data/peruRegionsData.ts
Other components
- Vite static bundle · Builds the browser-deployable SPA.
vite.config.ts
Connections 23
- 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