# egriff38/weather-app architecture

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

- Interactive diagram: https://gitdiagram.com/egriff38/weather-app
- Repository: https://github.com/egriff38/weather-app

## Overview

##### Project Type and Purpose
- This is a full-stack, monorepo application (frontend + backend + shared client library) for displaying weather forecasts.
- Frontend: Vue 3 SPA built with Vite (`apps/weather-ui`)
- Backend: A serverless “worker” service using Hono running on Node 20 Lambda (`apps/weather-worker`)
- Shared Package: `packages/weather-client` provides type-safe API calls from the frontend to the backend.

##### File Structure
- Top-level monorepo with `pnpm` workspaces (`pnpm-workspace.yaml`)
- `apps/weather-ui`: Browser-based UI
- `src/components`: CitySearch, UnitSelector, WeatherDashboard
- `src/providers/apiClientProvider.ts`: Injects typed client
- `apps/weather-worker`: HTTP worker
- `src/router.ts` & `src/weather-router.ts`: Defines API endpoints
- `src/lib/services.ts`: Business logic calling OpenWeather
- `src/lib/cityLookup.ts`: City data lookup utility
- `packages/weather-client`: Exposes strongly typed Hono client to the UI
- Deployment scripts and environment generation (`gen-env.mjs`, AWS CLI, 1Password CLI)

##### Extract Key Architecture from the README
- UI served from S3 + CloudFront
- Worker deployed as AWS Lambda behind HTTP endpoint
- Uses external OpenWeather API (requires API key)
- CI/CD and deploy via `pnpm run deploy`

##### Main Components & Their Relationships
a. Frontend (Browser SPA)
- Hosted on AWS S3 + CloudFront
- Uses `weather-client` to call worker API
- Renders components in Vue 3 (CitySearch, Dashboard, UnitSelector)
b. Backend Worker (Hono + Node 20 Lambda)
- Exposes REST endpoints (e.g., `/weather/:city`)
- Internally calls OpenWeather API for data
- Implements routing and business logic in `apps/weather-worker/src`
c. Shared Package (`weather-client`)
- Supplies typed fetch functions
- Automatically generates types from the Hono router
d. External Service
- OpenWeather API (data provider)

##### Architectural Patterns & Design Principles
- Monorepo with isolated workspaces (pnpm)
- Separation of concerns: UI, API layer, shared client
- Type safety across boundaries: TypeScript in both frontend and backend, shared types via `weather-client`
- Serverless microservice: lightweight, event-driven backend

##### Final Checklist
✓ Component labels
✓ Notes on hosting (S3/CloudFront) and serverless runtime
✓ External dependency (OpenWeather) clearly indicated
✓ Reference to monorepo/shared package boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: Browser and CDN
    Browser["User's Browser"]:::frontend
    CloudFront["CloudFront CDN"]:::frontend
    S3["S3 Bucket\n(Static Hosting)"]:::frontend

    Browser -->|loads UI| CloudFront
    CloudFront -->|fetch static| S3
    S3 -->|serves files| Browser

    %% Frontend Application
    subgraph "Weather UI (Vue 3 SPA)" 
        direction TB
        UI_CitySearch["CitySearch.vue"]:::frontend
        UI_UnitSelector["UnitSelector.vue"]:::frontend
        UI_Dashboard["WeatherDashboard.vue"]:::frontend
        UI_apiProvider["apiClientProvider.ts"]:::frontend
        UI_main["main.ts"]:::frontend
        UI_vite["vite.config.ts"]:::frontend

        UI_CitySearch --> UI_UnitSelector
        UI_UnitSelector --> UI_Dashboard
        UI_Dashboard --> UI_apiProvider
        UI_apiProvider --> UI_main
        UI_main --> UI_vite
    end

    S3 -->|serves SPA| UI_main

    %% Shared Client Library
    Shared["weather-client\n(hono/client, TS)"]:::shared

    UI_apiProvider --> Shared

    %% API Layer
    APIGateway["API Endpoint\n(GET /weather)"]:::backend
    CloudFront -->|API call| APIGateway

    Shared -->|typed API calls| APIGateway

    %% Backend Worker
    subgraph "Weather Worker (Hono Lambda)" 
        direction TB
        Worker_handler["handler.ts"]:::backend
        Worker_router["router.ts"]:::backend
        Worker_weatherRouter["weather-router.ts"]:::backend
        Worker_services["services.ts"]:::backend
        Worker_cityLookup["cityLookup.ts"]:::backend
        Worker_index["index.ts"]:::backend
        Worker_dev["dev.ts"]:::backend

        Worker_handler --> Worker_router
        Worker_router --> Worker_weatherRouter
        Worker_weatherRouter --> Worker_services
        Worker_services --> Worker_cityLookup
        Worker_index --> Worker_dev
    end

    APIGateway -->|invokes| Worker_handler

    %% External API
    ExternalAPI["OpenWeather API"]:::external
    Worker_services -->|HTTP request| ExternalAPI
    ExternalAPI -->|data response| Worker_services

    %% Monorepo Config / Deployment
    subgraph "Monorepo Config / Deploy"
        direction TB
        Config_pnpm["pnpm-workspace.yaml"]:::config
        Config_gen["gen-env.mjs"]:::config
    end

    Config_pnpm -.-> UI_main
    Config_pnpm -.-> Worker_handler
    Config_pnpm -.-> Shared
    Config_gen -.-> Worker_handler

    %% Click Events
    click UI_CitySearch "https://github.com/egriff38/weather-app/blob/main/apps/weather-ui/src/components/CitySearch.vue"
    click UI_UnitSelector "https://github.com/egriff38/weather-app/blob/main/apps/weather-ui/src/components/UnitSelector.vue"
    click UI_Dashboard "https://github.com/egriff38/weather-app/blob/main/apps/weather-ui/src/components/WeatherDashboard.vue"
    click UI_apiProvider "https://github.com/egriff38/weather-app/blob/main/apps/weather-ui/src/providers/apiClientProvider.ts"
    click UI_main "https://github.com/egriff38/weather-app/blob/main/apps/weather-ui/src/main.ts"
    click UI_vite "https://github.com/egriff38/weather-app/blob/main/apps/weather-ui/vite.config.ts"
    click Worker_router "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/router.ts"
    click Worker_weatherRouter "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/weather-router.ts"
    click Worker_services "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/lib/services.ts"
    click Worker_cityLookup "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/lib/cityLookup.ts"
    click Worker_handler "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/handler.ts"
    click Worker_index "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/index.ts"
    click Worker_dev "https://github.com/egriff38/weather-app/blob/main/apps/weather-worker/src/dev.ts"
    click Shared "https://github.com/egriff38/weather-app/blob/main/packages/weather-client/index.ts"
    click Config_pnpm "https://github.com/egriff38/weather-app/blob/main/pnpm-workspace.yaml"
    click Config_gen "https://github.com/egriff38/weather-app/blob/main/gen-env.mjs"

    %% Styles
    classDef frontend fill:#DCEEFB,stroke:#1E40AF,stroke-width:2px
    classDef backend fill:#D1FAE5,stroke:#065F46,stroke-width:2px
    classDef external fill:#E5E7EB,stroke:#6B7280,stroke-width:2px
    classDef shared fill:#FEF9C3,stroke:#D97706,stroke-width:2px
    classDef config fill:#F3E8FF,stroke:#7C3AED,stroke-width:2px
```
