# yumnumm/eqmonitor architecture

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

- Interactive diagram: https://gitdiagram.com/yumnumm/eqmonitor
- Repository: https://github.com/yumnumm/eqmonitor

## Overview

Below are the detailed instructions tailored to this project:

##### Relationships and Data Flow Between Components
- Also, show how the edge API interacts with databases (Cloudflare D1/Supabase) and caching (Cloudflare KV) systems.

##### Architectural Patterns and Key Technologies
- Client-side: Emphasize the use of a modern UI framework (Flutter) with reactive state management (Riverpod and Flutter Hooks). Mention that API interactions are handled through Dio and a custom eqapi_client.
- Service integration: Clearly mark where JSON serialization and data modeling occur using libraries (freezed, json_serializable) and highlight how the app integrates with maplibre_gl for mapping.
- On the service tiers: Illustrate microservice-like components (or containerized services managed by Docker Compose) and mention that multiple technologies (Node.js, Bun, Golang, C#) are used, which might interact as separate processes or services.

##### Packages/Submodules
- That these packages help encapsulate core functionalities such as parsing earthquake data or handling notification payloads.

- Clarity and not over-complicating details: separate the system into as many clear and distinct parts as possible as outlined above.
- Use annotation: provide notes or labels where necessary to describe responsibilities (for example, “Handles earthquake notifications” on the backend, or “Manages state with Riverpod” on the client).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        MobileClient["Mobile/Desktop Client (Flutter)\n(state management: Riverpod, Flutter Hooks; API Clients: Dio, eqapi_client; JSON: freezed, json_serializable; Mapping: maplibre_gl)"]:::client
    end

    %% Common Packages/Libs Layer
    subgraph "Common Packages/Libs"
        EqapiClient["eqapi_client"]:::shared
        EqapiTypes["eqapi_types"]:::shared
        EarthquakeReplay["earthquake_replay"]:::shared
        JMATable["jma_code_table_converter_internal"]:::shared
    end

    %% Edge Layer
    subgraph "Edge Layer"
        EdgeAPI["エッジサーバサイド(API)\n(Cloudflare Workers)"]:::edge
        ExecutionEnv["Execution Environment\n(Cloudflare Workers)"]:::edge
        DataPersistence["Data Persistence\n(Cloudflare D1 + Supabase)"]:::external
        Caching["Caching\n(Cloudflare KV)"]:::external
        FallbackWS["Fallback WebSocket\n(Cloudflare Durable Objects)"]:::external
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BackendServices["バックエンド\n(Oracle Cloud, Docker Compose managing 12 containers)\n(Node.js/TS, Bun/TS, Golang, C#)"]:::backend
        PostgreSQL["PostgreSQL\n(caching/working data store)"]:::external
    end

    %% Connections Between Layers
    MobileClient ---|"API Request/Response\n(earthquake data, notifications, mapping details)"| EdgeAPI
    EdgeAPI ---|"REST API calls\n(Data ingestion, real-time streams)"| BackendServices
    EdgeAPI ---|"Data Storage" | DataPersistence
    EdgeAPI ---|"Caching" | Caching
    EdgeAPI ---|"Fallback WebSocket Stream" | FallbackWS
    BackendServices ---|"Data synchronization" | PostgreSQL

    %% Connection from Client to Shared Libs (indicative use, not data flow)
    MobileClient ---|"Uses" | EqapiClient
    MobileClient ---|"Uses" | EqapiTypes
    MobileClient ---|"May utilize" | EarthquakeReplay
    MobileClient ---|"May utilize" | JMATable

    %% Class Definitions for Styling
    classDef client fill:#f39c12,stroke:#333,stroke-width:2px;
    classDef edge fill:#3498db,stroke:#333,stroke-width:2px;
    classDef backend fill:#2ecc71,stroke:#333,stroke-width:2px;
    classDef shared fill:#9b59b6,stroke:#333,stroke-width:2px;
    classDef external fill:#e74c3c,stroke:#333,stroke-width:2px;

    %% Click Events
    click MobileClient "https://github.com/yumnumm/eqmonitor/tree/develop/app/"
    click EqapiClient "https://github.com/yumnumm/eqmonitor/tree/develop/packages/eqapi_client"
    click EqapiTypes "https://github.com/yumnumm/eqmonitor/tree/develop/packages/eqapi_types"
    click EarthquakeReplay "https://github.com/yumnumm/eqmonitor/tree/develop/packages/earthquake_replay"
    click JMATable "https://github.com/yumnumm/eqmonitor/tree/develop/packages/jma_code_table_converter_internal"
    click DataPersistence "https://github.com/yumnumm/eqmonitor/tree/develop/supabase/"
```
