# yonazakkart/agroalerta-sv architecture

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

- Interactive diagram: https://gitdiagram.com/yonazakkart/agroalerta-sv
- Repository: https://github.com/yonazakkart/agroalerta-sv

## Overview

AgroAlerta Morazán is an agricultural risk-prevention web platform for Morazán. An authenticated farmer registers a planting; the backend stores it and emits an event, while climate and CENTA-based crop viability inform yield, cost, risk, and recommendation reports that can be persisted and reviewed in history. The README documents the broader capabilities; source-index references and excerpts support the backend call edges shown. Frontend page-to-service wiring and some event-driven links are not excerpted, so those links are marked unverified rather than asserted as direct calls.

Main entry points: [`backend/src/index.ts`](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/index.ts) (API server), [`backend/src/estimacion/reporte.service.ts`](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/reporte.service.ts) (Report service), [`backend/src/siembra/siembra.routes.ts`](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.routes.ts) (Planting routes), [`backend/src/auth/auth.middleware.ts`](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/auth/auth.middleware.ts) (Auth middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Farmer interface"]
  node_web_routes["Web routes<br/>[app.routes.ts]"]
  node_farmer_pages["Farm workflows"]
  node_web_api["API clients"]
end

subgraph group_api["API and identity"]
  node_api_entry["API server<br/>[index.ts]"]
  node_identity["Identity routes"]
  node_auth_guard["Auth middleware<br/>[auth.middleware.ts]"]
end

subgraph group_agri["Crop and viability"]
  node_viability_routes["Viability routes"]
  node_viability_service["CENTA viability<br/>[service.ts]"]
  node_district_routes["District catalog"]
  node_planting_routes["Planting routes<br/>[siembra.routes.ts]"]
  node_planting_validation["Planting validation"]
  node_planting_service["Planting service<br/>[siembra.service.ts]"]
end

subgraph group_climate["Climate service"]
  node_climate_routes["Climate routes<br/>[clima.routes.ts]"]
  node_climate_orchestrator["Climate orchestration<br/>[orquestador.ts]"]
  node_open_meteo["Open-Meteo client"]
  node_climate_store["Climate condition store<br/>[condicion.repo.ts]"]
end

subgraph group_estimation["Estimation and events"]
  node_event_bus["Domain event bus<br/>[bus.ts]"]
  node_estimate_routes["Estimate history routes"]
  node_report_service["Report service<br/>[reporte.service.ts]"]
  node_projection["Yield projection<br/>[proyeccion.ts]"]
  node_recommendation["Risk recommendations<br/>[recomendacion.ts]"]
end

node_farmer(("Farmer"))
node_postgres[("Neon Postgres")]
node_meteo_service["Open-Meteo"]

node_farmer -->|"uses"| node_web_routes
node_web_routes -->|"loads pages"| node_farmer_pages
node_farmer_pages -.->|"requests data"| node_web_api
node_web_api -.->|"calls API"| node_api_entry
node_api_entry -->|"mounts routes"| node_identity
node_api_entry -->|"mounts routes"| node_viability_routes
node_api_entry -->|"mounts routes"| node_district_routes
node_api_entry -->|"mounts routes"| node_climate_routes
node_api_entry -->|"mounts routes"| node_planting_routes
node_api_entry -->|"mounts routes"| node_estimate_routes
node_viability_routes -->|"guards requests"| node_auth_guard
node_viability_routes -->|"calls"| node_viability_service
node_viability_service -->|"reads"| node_postgres
node_district_routes -->|"reads"| node_postgres
node_planting_routes -->|"guards requests"| node_auth_guard
node_planting_routes -->|"validates with"| node_planting_validation
node_planting_routes -->|"calls"| node_planting_service
node_planting_service -->|"reads and writes"| node_postgres
node_planting_service -->|"emits planting event"| node_event_bus
node_climate_routes -->|"guards requests"| node_auth_guard
node_climate_routes -->|"requests update"| node_climate_orchestrator
node_climate_orchestrator -->|"fetches weather"| node_open_meteo
node_open_meteo -.->|"requests forecasts"| node_meteo_service
node_climate_orchestrator -->|"stores conditions"| node_climate_store
node_climate_store -.->|"reads and writes"| node_postgres
node_estimate_routes -->|"guards requests"| node_auth_guard
node_estimate_routes -->|"lists reports"| node_report_service
node_report_service -->|"uses projection"| node_projection
node_report_service -->|"uses recommendations"| node_recommendation
node_report_service -->|"reads and persists reports"| node_postgres
node_event_bus -.->|"triggers recalculation"| node_report_service

click node_web_routes "https://github.com/yonazakkart/agroalerta-sv/blob/main/frontend/src/app/app.routes.ts"
click node_farmer_pages "https://github.com/yonazakkart/agroalerta-sv/tree/main/frontend/src/app/pages"
click node_web_api "https://github.com/yonazakkart/agroalerta-sv/tree/main/frontend/src/app/core"
click node_api_entry "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/index.ts"
click node_identity "https://github.com/yonazakkart/agroalerta-sv/tree/main/backend/src/auth"
click node_auth_guard "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/auth/auth.middleware.ts"
click node_viability_routes "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/viabilidad/viabilidad.routes.ts"
click node_viability_service "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/viabilidad/service.ts"
click node_district_routes "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/viabilidad/distritos.routes.ts"
click node_planting_routes "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.routes.ts"
click node_planting_validation "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.validacion.ts"
click node_planting_service "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.service.ts"
click node_climate_routes "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/clima.routes.ts"
click node_climate_orchestrator "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/orquestador.ts"
click node_open_meteo "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/open-meteo.client.ts"
click node_climate_store "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/condicion.repo.ts"
click node_event_bus "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/events/bus.ts"
click node_estimate_routes "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/estimaciones.routes.ts"
click node_report_service "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/reporte.service.ts"
click node_projection "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/proyeccion.ts"
click node_recommendation "https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/recomendacion.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_web_routes,node_farmer_pages,node_web_api toneBlue
class node_api_entry,node_identity,node_auth_guard,node_postgres toneAmber
class node_viability_routes,node_viability_service,node_district_routes,node_planting_routes,node_planting_validation,node_planting_service toneMint
class node_climate_routes,node_climate_orchestrator,node_open_meteo,node_climate_store toneRose
class node_event_bus,node_estimate_routes,node_report_service,node_projection,node_recommendation,node_farmer,node_meteo_service toneIndigo
```

## Components

### Farmer interface

- [Web routes](https://github.com/yonazakkart/agroalerta-sv/blob/main/frontend/src/app/app.routes.ts): `frontend/src/app/app.routes.ts`
- [Farm workflows](https://github.com/yonazakkart/agroalerta-sv/tree/main/frontend/src/app/pages): `frontend/src/app/pages`
- [API clients](https://github.com/yonazakkart/agroalerta-sv/tree/main/frontend/src/app/core): `frontend/src/app/core`

### API and identity

- [API server](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/index.ts): `backend/src/index.ts`
- [Identity routes](https://github.com/yonazakkart/agroalerta-sv/tree/main/backend/src/auth): `backend/src/auth`
- [Auth middleware](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/auth/auth.middleware.ts): `backend/src/auth/auth.middleware.ts`

### Crop and viability

- [Viability routes](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/viabilidad/viabilidad.routes.ts): `backend/src/viabilidad/viabilidad.routes.ts`
- [CENTA viability](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/viabilidad/service.ts): `backend/src/viabilidad/service.ts`
- [District catalog](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/viabilidad/distritos.routes.ts): `backend/src/viabilidad/distritos.routes.ts`
- [Planting routes](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.routes.ts): `backend/src/siembra/siembra.routes.ts`
- [Planting validation](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.validacion.ts): `backend/src/siembra/siembra.validacion.ts`
- [Planting service](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/siembra/siembra.service.ts): `backend/src/siembra/siembra.service.ts`

### Climate service

- [Climate routes](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/clima.routes.ts): `backend/src/clima/clima.routes.ts`
- [Climate orchestration](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/orquestador.ts): `backend/src/clima/orquestador.ts`
- [Open-Meteo client](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/open-meteo.client.ts): `backend/src/clima/open-meteo.client.ts`
- [Climate condition store](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/clima/condicion.repo.ts): `backend/src/clima/condicion.repo.ts`

### Estimation and events

- [Domain event bus](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/events/bus.ts): `backend/src/events/bus.ts`
- [Estimate history routes](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/estimaciones.routes.ts): `backend/src/estimacion/estimaciones.routes.ts`
- [Report service](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/reporte.service.ts): `backend/src/estimacion/reporte.service.ts`
- [Yield projection](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/proyeccion.ts): `backend/src/estimacion/proyeccion.ts`
- [Risk recommendations](https://github.com/yonazakkart/agroalerta-sv/blob/main/backend/src/estimacion/recomendacion.ts): `backend/src/estimacion/recomendacion.ts`

### Other components

- **Farmer**
- **Neon Postgres**
- **Open-Meteo**

## Connections

- Farmer → Web routes: uses
- Web routes → Farm workflows: loads pages (evidence: `frontend/src/app/app.routes.ts`)
- Farm workflows → API clients: requests data
- API clients → API server: calls API
- API server → Identity routes: mounts routes (evidence: `backend/src/index.ts`)
- API server → Viability routes: mounts routes (evidence: `backend/src/index.ts`)
- API server → District catalog: mounts routes (evidence: `backend/src/index.ts`)
- API server → Climate routes: mounts routes (evidence: `backend/src/index.ts`)
- API server → Planting routes: mounts routes (evidence: `backend/src/index.ts`)
- API server → Estimate history routes: mounts routes (evidence: `backend/src/index.ts`)
- Viability routes → Auth middleware: guards requests (evidence: `backend/src/viabilidad/viabilidad.routes.ts`)
- Viability routes → CENTA viability: calls (evidence: `backend/src/viabilidad/viabilidad.routes.ts`)
- CENTA viability → Neon Postgres: reads (evidence: `backend/src/viabilidad/service.ts`)
- District catalog → Neon Postgres: reads (evidence: `backend/src/viabilidad/distritos.routes.ts`)
- Planting routes → Auth middleware: guards requests (evidence: `backend/src/siembra/siembra.routes.ts`)
- Planting routes → Planting validation: validates with (evidence: `backend/src/siembra/siembra.routes.ts`)
- Planting routes → Planting service: calls (evidence: `backend/src/siembra/siembra.routes.ts`)
- Planting service → Neon Postgres: reads and writes (evidence: `backend/src/siembra/siembra.service.ts`)
- Planting service → Domain event bus: emits planting event (evidence: `backend/src/siembra/siembra.service.ts`)
- Climate routes → Auth middleware: guards requests (evidence: `backend/src/clima/clima.routes.ts`)
- Climate routes → Climate orchestration: requests update (evidence: `backend/src/clima/clima.routes.ts`)
- Climate orchestration → Open-Meteo client: fetches weather (evidence: `backend/src/clima/orquestador.ts`)
- Open-Meteo client → Open-Meteo: requests forecasts
- Climate orchestration → Climate condition store: stores conditions (evidence: `backend/src/clima/orquestador.ts`)
- Climate condition store → Neon Postgres: reads and writes
- Estimate history routes → Auth middleware: guards requests (evidence: `backend/src/estimacion/estimaciones.routes.ts`)
- Estimate history routes → Report service: lists reports (evidence: `backend/src/estimacion/estimaciones.routes.ts`)
- Report service → Yield projection: uses projection (evidence: `backend/src/estimacion/reporte.service.ts`)
- Report service → Risk recommendations: uses recommendations (evidence: `backend/src/estimacion/reporte.service.ts`)
- Report service → Neon Postgres: reads and persists reports (evidence: `backend/src/estimacion/reporte.service.ts`)
- Domain event bus → Report service: triggers recalculation
