# shardeum/network-status architecture

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

- Interactive diagram: https://gitdiagram.com/shardeum/network-status
- Repository: https://github.com/shardeum/network-status

## Overview

Based on your file tree and README, this project is a real-time monitoring system titled “Shardeum Network Status Monitor.” It’s built using Next.js for the frontend and an Express-based Prometheus exporter for the backend, while Prometheus itself is used for scraping and storing metrics. The project monitors service availability and performance metrics, visualizing latency, uptime, and status information in real time.

##### Main Components
- Next.js Frontend: Represented by the “app” directory (with its API routes, pages, and layout) and “components” (UI elements such as Header, Footer, and monitors). This portion handles real-time visualization of metrics, latency graphs, and status indicators.
- Prometheus Exporter (Express Server): Found under the “server” directory (exporter.js and endpoints.json). Its role is to query the endpoints, implement retry logic and error handling, and expose metrics (like service_up and service_response_time) for Prometheus scraping.
- Prometheus Server: Although not part of the project code per se, the README specifies that Prometheus runs on port 9090 and scrapes metrics from the exporter.
- External Services: Represent the monitored endpoints configured via “endpoints.json” (inside the server directory) which define each service's URL, expected response format, etc.
- Docker/Deployment Components: Note Dockerfiles (Dockerfile.exporter and Dockerfile.frontend) and docker-compose.yml, indicating containerized deployment for different parts of the system.

##### Relationships and Data Flow
- The Next.js Frontend interacts with its own API routes (located in “app/api”) to fetch real-time metrics and status data, communicating possibly with custom hooks (from the “hooks” directory) that abstract away data fetching.
- The Prometheus Exporter is responsible for performing automated and concurrent checks on the configured external services, applies retry logic, and then exposes the formatted metrics.
- The Prometheus Server periodically scrapes data from the Exporter, storing time-series data that the frontend can query (directly or indirectly, as per architecture).
- External services are constantly monitored by the Exporter via HTTP requests, with retry handling and state management (as per the detailed “Monitoring Logic” in the README).

##### Essential Architectural Patterns and Design Principles
- Separation of Frontend and Backend: The architecture clearly distinguishes the user interface (Next.js) from backend service monitoring (Express exporter) and metric storage/processing (Prometheus).
- Microservice and API Patterns: The project uses API routes (in Next.js) to facilitate interaction, while the exporter runs as an independent service.
- Retry and Grace Period Mechanisms: Emphasize the retry logic implemented in the exporter (with exponential backoff) and the state management (grace period before generating alerts).
- Containerization: The multiple Dockerfiles and docker-compose configuration indicate that containerized deployment is intended – include containers for the Frontend, Exporter, and possibly a separate container for Prometheus.
- Real-time Data Flow and Polling: With realtime views refreshing every second and service checks every 60 seconds, denote different refresh intervals for user interaction and backend monitoring.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Next.js Frontend (UI & API)"
        subgraph "Pages & Layout"
            P1["app/page.tsx"]:::frontend
            P2["app/layout.tsx"]:::frontend
            P3["app/latency/page.tsx"]:::frontend
            P4["app/realtime/page.tsx"]:::frontend
        end
        subgraph "API Endpoints"
            API1["app/api/latency/route.ts"]:::frontend
            API2["app/api/metrics/route.ts"]:::frontend
            API3["app/api/status/route.ts"]:::frontend
        end
        subgraph "UI Components"
            C1["components/Header.tsx"]:::frontend
            C2["components/Footer.tsx"]:::frontend
            C3["components/LatencyMonitor.tsx"]:::frontend
            C4["components/UptimeMonitor.tsx"]:::frontend
        end
    end

    subgraph "Frontend Hooks"
        FH1["hooks/useLatencyData.ts"]:::hooks
        FH2["hooks/usePrometheusData.ts"]:::hooks
        FH3["hooks/useRealtimeStatus.ts"]:::hooks
    end

    subgraph "Express Exporter (Backend)"
        B1["server/exporter.js"]:::backend
        B2["server/endpoints.json"]:::backend
    end

    X1["Prometheus Server (Port 9090)"]:::external
    X2["Monitored External Services"]:::external

    subgraph "Deployment"
        D1["Dockerfile.frontend"]:::deployment
        D2["Dockerfile.exporter"]:::deployment
        D3["docker-compose.yml"]:::deployment
        subgraph "Startup Scripts"
            S1["scripts/start-services.js"]:::scripts
            S2["scripts/start-services.sh"]:::scripts
        end
    end

    %% Data Flow Connections
    X2 -->|"HTTP_Checks"| B1
    B1 -->|"Expose_Metrics"| X1
    X1 -->|"Query_Metrics"| API2

    %% Frontend Hooks calling API Endpoints
    FH1 -->|"fetch_latency"| API1
    FH2 -->|"fetch_metrics"| API2
    FH3 -->|"fetch_status"| API3

    %% UI Components updated via API data
    API1 -->|"Update"| C3
    API3 -->|"Update"| C4
    API1 -->|"Update"| C1
    API1 -->|"Update"| C2

    %% Deployment connections
    D3 -->|"Deploys_Frontend"| P1
    D3 -->|"Deploys_Exporter"| B1

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef hooks fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef deployment fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef scripts fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events
    click P1 "https://github.com/shardeum/network-status/blob/main/app/page.tsx"
    click P2 "https://github.com/shardeum/network-status/blob/main/app/layout.tsx"
    click P3 "https://github.com/shardeum/network-status/blob/main/app/latency/page.tsx"
    click P4 "https://github.com/shardeum/network-status/blob/main/app/realtime/page.tsx"
    click API1 "https://github.com/shardeum/network-status/blob/main/app/api/latency/route.ts"
    click API2 "https://github.com/shardeum/network-status/blob/main/app/api/metrics/route.ts"
    click API3 "https://github.com/shardeum/network-status/blob/main/app/api/status/route.ts"
    click C1 "https://github.com/shardeum/network-status/blob/main/components/Header.tsx"
    click C2 "https://github.com/shardeum/network-status/blob/main/components/Footer.tsx"
    click C3 "https://github.com/shardeum/network-status/blob/main/components/LatencyMonitor.tsx"
    click C4 "https://github.com/shardeum/network-status/blob/main/components/UptimeMonitor.tsx"
    click B1 "https://github.com/shardeum/network-status/blob/main/server/exporter.js"
    click B2 "https://github.com/shardeum/network-status/blob/main/server/endpoints.json"
    click FH1 "https://github.com/shardeum/network-status/blob/main/hooks/useLatencyData.ts"
    click FH2 "https://github.com/shardeum/network-status/blob/main/hooks/usePrometheusData.ts"
    click FH3 "https://github.com/shardeum/network-status/blob/main/hooks/useRealtimeStatus.ts"
    click D1 "https://github.com/shardeum/network-status/blob/main/Dockerfile.frontend"
    click D2 "https://github.com/shardeum/network-status/blob/main/Dockerfile.exporter"
    click D3 "https://github.com/shardeum/network-status/blob/main/docker-compose.yml"
    click S1 "https://github.com/shardeum/network-status/blob/main/scripts/start-services.js"
    click S2 "https://github.com/shardeum/network-status/blob/main/scripts/start-services.sh"
```
