# danamistartrail/margo-lestari architecture

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

- Interactive diagram: https://gitdiagram.com/danamistartrail/margo-lestari
- Repository: https://github.com/danamistartrail/margo-lestari

## Overview

This backend periodically gathers BMKG and Open-Meteo weather data, evaluates rainfall risk, records a history, and broadcasts a formatted alert to a WhatsApp community or channel. The main control flow and calls are visible in `src/index.ts`; the README documents the external services and operational capabilities. The README also describes a health-check server and RainViewer radar link. Edges for these documented integrations cite the README; unsampled behavior is not inferred.

Main entry points: [`src/index.ts`](https://github.com/danamistartrail/margo-lestari/blob/main/src/index.ts) (Scheduled weather job), [`src/services/whatsapp.ts`](https://github.com/danamistartrail/margo-lestari/blob/main/src/services/whatsapp.ts) (WhatsApp client), [`src/services/openmeteo.ts`](https://github.com/danamistartrail/margo-lestari/blob/main/src/services/openmeteo.ts) (Open-Meteo adapter), [`src/config/env.ts`](https://github.com/danamistartrail/margo-lestari/blob/main/src/config/env.ts) (Environment config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Scheduling &amp; Health"]
  node_scheduler_job["Scheduled weather job<br/>[index.ts]"]
  node_health_http["Health HTTP server<br/>[index.ts]"]
  node_environment["Environment config<br/>[env.ts]"]
end

subgraph group_weather["Weather Data"]
  node_bmkg_adapter["BMKG forecast adapter<br/>[weather.ts]"]
  node_openmeteo_adapter["Open-Meteo adapter<br/>[openmeteo.ts]"]
  node_bmkg_types["BMKG data types<br/>[weather.ts]"]
  node_openmeteo_types["Open-Meteo data types<br/>[openmeteo.ts]"]
end

subgraph group_alerts["Risk &amp; Broadcast"]
  node_risk_formatter["Rainfall risk formatter<br/>[formatter.ts]"]
  node_whatsapp_client["WhatsApp client<br/>[whatsapp.ts]"]
end

subgraph group_state["Persistence &amp; Operations"]
  node_mongo_auth["MongoDB auth adapter<br/>[mongoAuth.ts]"]
  node_system_logger["System and history logs<br/>[logger.ts]"]
end

node_bmkg_api{{"BMKG API"}}
node_openmeteo_api{{"Open-Meteo API"}}
node_mongo_atlas[("MongoDB Atlas")]
node_whatsapp_network{{"WhatsApp"}}
node_community(("Village community/channel"))
node_uptimerobot(("UptimeRobot"))
node_rainviewer{{"RainViewer radar"}}

node_scheduler_job -->|"reads schedule"| node_environment
node_scheduler_job -->|"fetches forecast"| node_bmkg_adapter
node_scheduler_job -->|"fetches weather"| node_openmeteo_adapter
node_bmkg_adapter -->|"reads endpoint"| node_environment
node_openmeteo_adapter -->|"reads coordinates"| node_environment
node_bmkg_api -->|"provides forecast"| node_bmkg_adapter
node_openmeteo_api -->|"provides forecast"| node_openmeteo_adapter
node_scheduler_job -->|"formats results"| node_risk_formatter
node_risk_formatter -->|"aggregates rainfall"| node_openmeteo_adapter
node_scheduler_job -->|"records history"| node_system_logger
node_scheduler_job -->|"sends summary"| node_whatsapp_client
node_whatsapp_client -->|"reads target"| node_environment
node_whatsapp_client -->|"loads session"| node_mongo_auth
node_mongo_auth -->|"reads and writes"| node_mongo_atlas
node_whatsapp_client -->|"sends messages"| node_whatsapp_network
node_whatsapp_network -->|"delivers broadcast"| node_community
node_uptimerobot -->|"pings endpoint"| node_health_http
node_risk_formatter -->|"includes radar link"| node_rainviewer

click node_scheduler_job "https://github.com/danamistartrail/margo-lestari/blob/main/src/index.ts"
click node_health_http "https://github.com/danamistartrail/margo-lestari/blob/main/src/index.ts"
click node_environment "https://github.com/danamistartrail/margo-lestari/blob/main/src/config/env.ts"
click node_bmkg_adapter "https://github.com/danamistartrail/margo-lestari/blob/main/src/services/weather.ts"
click node_openmeteo_adapter "https://github.com/danamistartrail/margo-lestari/blob/main/src/services/openmeteo.ts"
click node_bmkg_types "https://github.com/danamistartrail/margo-lestari/blob/main/src/types/weather.ts"
click node_openmeteo_types "https://github.com/danamistartrail/margo-lestari/blob/main/src/types/openmeteo.ts"
click node_risk_formatter "https://github.com/danamistartrail/margo-lestari/blob/main/src/utils/formatter.ts"
click node_whatsapp_client "https://github.com/danamistartrail/margo-lestari/blob/main/src/services/whatsapp.ts"
click node_mongo_auth "https://github.com/danamistartrail/margo-lestari/blob/main/src/services/mongoAuth.ts"
click node_system_logger "https://github.com/danamistartrail/margo-lestari/blob/main/src/utils/logger.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_scheduler_job,node_health_http,node_environment,node_rainviewer toneBlue
class node_bmkg_adapter,node_openmeteo_adapter,node_bmkg_types,node_openmeteo_types,node_mongo_atlas toneAmber
class node_risk_formatter,node_whatsapp_client,node_bmkg_api,node_openmeteo_api toneMint
class node_mongo_auth,node_system_logger toneRose
class node_whatsapp_network,node_community,node_uptimerobot toneIndigo
```

## Components

### Scheduling & Health

- [Scheduled weather job](https://github.com/danamistartrail/margo-lestari/blob/main/src/index.ts): `src/index.ts`
- [Health HTTP server](https://github.com/danamistartrail/margo-lestari/blob/main/src/index.ts): `src/index.ts`
- [Environment config](https://github.com/danamistartrail/margo-lestari/blob/main/src/config/env.ts): `src/config/env.ts`

### Weather Data

- [BMKG forecast adapter](https://github.com/danamistartrail/margo-lestari/blob/main/src/services/weather.ts): `src/services/weather.ts`
- [Open-Meteo adapter](https://github.com/danamistartrail/margo-lestari/blob/main/src/services/openmeteo.ts): `src/services/openmeteo.ts`
- [BMKG data types](https://github.com/danamistartrail/margo-lestari/blob/main/src/types/weather.ts): `src/types/weather.ts`
- [Open-Meteo data types](https://github.com/danamistartrail/margo-lestari/blob/main/src/types/openmeteo.ts): `src/types/openmeteo.ts`

### Risk & Broadcast

- [Rainfall risk formatter](https://github.com/danamistartrail/margo-lestari/blob/main/src/utils/formatter.ts): `src/utils/formatter.ts`
- [WhatsApp client](https://github.com/danamistartrail/margo-lestari/blob/main/src/services/whatsapp.ts): `src/services/whatsapp.ts`

### Persistence & Operations

- [MongoDB auth adapter](https://github.com/danamistartrail/margo-lestari/blob/main/src/services/mongoAuth.ts): `src/services/mongoAuth.ts`
- [System and history logs](https://github.com/danamistartrail/margo-lestari/blob/main/src/utils/logger.ts): `src/utils/logger.ts`

### Other components

- **BMKG API**
- **Open-Meteo API**
- **MongoDB Atlas**
- **WhatsApp**
- **Village community/channel**
- **UptimeRobot**
- **RainViewer radar**

## Connections

- Scheduled weather job → Environment config: reads schedule (evidence: `src/index.ts`)
- Scheduled weather job → BMKG forecast adapter: fetches forecast (evidence: `src/index.ts`)
- Scheduled weather job → Open-Meteo adapter: fetches weather (evidence: `src/index.ts`)
- BMKG forecast adapter → Environment config: reads endpoint (evidence: `src/services/weather.ts`)
- Open-Meteo adapter → Environment config: reads coordinates (evidence: `src/services/openmeteo.ts`)
- BMKG API → BMKG forecast adapter: provides forecast (evidence: `README.md`)
- Open-Meteo API → Open-Meteo adapter: provides forecast (evidence: `README.md`)
- Scheduled weather job → Rainfall risk formatter: formats results (evidence: `src/index.ts`)
- Rainfall risk formatter → Open-Meteo adapter: aggregates rainfall (evidence: `src/utils/formatter.ts`)
- Scheduled weather job → System and history logs: records history (evidence: `src/index.ts`)
- Scheduled weather job → WhatsApp client: sends summary (evidence: `src/index.ts`)
- WhatsApp client → Environment config: reads target (evidence: `src/services/whatsapp.ts`)
- WhatsApp client → MongoDB auth adapter: loads session (evidence: `src/services/whatsapp.ts`)
- MongoDB auth adapter → MongoDB Atlas: reads and writes (evidence: `src/services/mongoAuth.ts`)
- WhatsApp client → WhatsApp: sends messages (evidence: `README.md`)
- WhatsApp → Village community/channel: delivers broadcast (evidence: `README.md`)
- UptimeRobot → Health HTTP server: pings endpoint (evidence: `README.md`)
- Rainfall risk formatter → RainViewer radar: includes radar link (evidence: `src/utils/formatter.ts`)
