# stevenb32/weatherapp architecture

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

- Interactive diagram: https://gitdiagram.com/stevenb32/weatherapp
- Repository: https://github.com/stevenb32/weatherapp

## Overview

#### Purpose and Runtime Topology
WeatherApp is a two-process full-stack weather application: an ASP.NET Core Minimal API aggregates WeatherAPI forecasts, while a React/Vite UI provides the initial client shell. The API owns WeatherAPI credentials and provider interaction; the UI issues same-origin relative API requests through Vite’s development proxy.
- API host/composition: `src/WeatherApp.Api/Program.cs`
- React bootstrap and root: `src/WeatherApp.Ui/src/main.tsx`, `src/WeatherApp.Ui/src/App.tsx`
- Local proxy boundary: `src/WeatherApp.Ui/vite.config.ts`

#### API Composition and Public Surface
`Program.cs` configures dependency injection, typed options, HTTP client behavior, caching, rate limiting, health checks, and endpoint mapping. The public API surface is deliberately separated from the external provider schema.
- Application composition: `src/WeatherApp.Api/Program.cs`
- Weather route handler(s): `src/WeatherApp.Api/Weather/WeatherEndpoints.cs`
- Stable response contract and unit selection: `src/WeatherApp.Api/Weather/WeatherResponse.cs`, `src/WeatherApp.Api/Weather/WeatherUnitSystem.cs`

Primary request flow is `GET /api/weather?location=...&units=...`: validate/query inputs, apply weather-specific rate limiting, consult in-memory cached response, fetch provider data if needed, map it to the public contract, then return it. `GET /health` is intentionally outside this weather rate-limit boundary.

#### Provider Integration Boundary
A typed HTTP client encapsulates calls to WeatherAPI. Provider transport models, error models, exceptions, and configuration remain internal to this boundary, preventing WeatherAPI schema leakage into API consumers.
- Client and outbound request handling: `src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs`
- Provider DTOs/errors: `src/WeatherApp.Api/WeatherApi/WeatherApiForecastResponse.cs`, `src/WeatherApp.Api/WeatherApi/WeatherApiErrorResponse.cs`
- Provider configuration and domain failure: `src/WeatherApp.Api/WeatherApi/WeatherApiOptions.cs`, `src/WeatherApp.Api/WeatherApi/WeatherApiException.cs`

WeatherAPI is the only external runtime service. Its API key is supplied outside source control, while base URL, timeout, and cache duration are configuration-driven.

#### Forecast Transformation Stage
The mapper converts WeatherAPI’s forecast payload into the API-owned response: current conditions, the next 24 future hourly periods, and a three-day daily forecast. Unit choice is applied at this contract-creation stage, rather than requiring UI consumers to understand provider fields.
- Transformation layer: `src/WeatherApp.Api/WeatherApi/WeatherApiForecastMapper.cs`
- Provider source schema: `src/WeatherApp.Api/WeatherApi/WeatherApiForecastResponse.cs`
- Output schema: `src/WeatherApp.Api/Weather/WeatherResponse.cs`

#### Resilience and Traffic Controls
The backend applies several boundaries around provider access: startup validation for provider options, request timeout via the typed client, in-memory response caching, fixed-window weather rate limiting, and translation of invalid-location/provider/timeout failures into API responses.
- Rate-limit options: `src/WeatherApp.Api/RateLimiting/WeatherRateLimitOptions.cs`
- Provider timeout/cache settings: `src/WeatherApp.Api/WeatherApi/WeatherApiOptions.cs`
- Registration and policy application: `src/WeatherApp.Api/Program.cs`

#### Frontend Client Boundary
The frontend is an early MVP shell, not yet a complete search/presentation workflow. Its service module is the intended boundary between React components and the backend, using shared TypeScript weather types and relative `/api` requests.
- UI root: `src/WeatherApp.Ui/src/App.tsx`
- API client service: `src/WeatherApp.Ui/src/services/weatherApi.ts`
- Client-side contract types: `src/WeatherApp.Ui/src/types/weather.ts`

#### Verification Architecture
Backend integration tests host the API and use WireMock.Net to substitute WeatherAPI, validating endpoint behavior without provider calls. Focused tests also cover outbound-client and mapping behavior. Frontend component/service tests run under Vitest/jsdom.
- API test host and endpoint tests: `tests/WeatherApp.Api.Tests/WeatherAppFactory.cs`, `tests/WeatherApp.Api.Tests/WeatherEndpointTests.cs`
- Provider simulation/mapping tests: `tests/WeatherApp.Api.Tests/WeatherApiClientTests.cs`, `tests/WeatherApp.Api.Tests/WeatherApiForecastMapperTests.cs`

Main entry points: [`src/WeatherApp.Api/Weather/WeatherEndpoints.cs`](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Weather/WeatherEndpoints.cs) (GET /api/weather), [`src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs`](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs) (WeatherAPI client), [`src/WeatherApp.Api/Program.cs`](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs) (API composition), [`src/WeatherApp.Ui/src/services/weatherApi.ts`](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/services/weatherApi.ts) (Weather API service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["React UI"]
  node_ui_bootstrap["React bootstrap<br/>Vite entry<br/>[main.tsx]"]
  node_ui_root["UI root shell<br/>React component<br/>[App.tsx]"]
  node_ui_service["Weather API service<br/>TypeScript client<br/>[weatherApi.ts]"]
  node_ui_types["Client weather types<br/>TypeScript contract<br/>[weather.ts]"]
  node_vite_proxy{{"Vite dev proxy<br/>proxy boundary<br/>[vite.config.ts]"}}
end

subgraph group_api["ASP.NET Core API"]
  node_api_host["API composition<br/>Minimal API host<br/>[Program.cs]"]
  node_weather_endpoint["GET /api/weather<br/>route handler"]
  node_weather_contract["Weather response contract<br/>public DTO<br/>[WeatherResponse.cs]"]
  node_rate_limit{{"Weather rate limit<br/>fixed-window policy"}}
  node_response_cache[("In-memory cache<br/>response cache<br/>[Program.cs]")]
  node_health_endpoint["GET /health<br/>health endpoint<br/>[Program.cs]"]
end

subgraph group_provider["WeatherAPI boundary"]
  node_provider_client["WeatherAPI client<br/>typed HTTP client"]
  node_provider_models["Provider DTOs and errors<br/>internal schema"]
  node_forecast_mapper["Forecast mapper<br/>transformation"]
  node_provider_options["Provider options<br/>typed configuration"]
end

subgraph group_verification["Verification"]
  node_api_test_host["API integration host<br/>test factory"]
  node_endpoint_tests["Endpoint tests<br/>integration tests"]
  node_provider_tests["Client and mapper tests<br/>focused tests"]
end

node_weatherapi{{"WeatherAPI<br/>external service"}}

node_ui_bootstrap -->|"mounts"| node_ui_root
node_ui_root -->|"uses"| node_ui_service
node_ui_service -->|"uses"| node_ui_types
node_ui_service -->|"/api request"| node_vite_proxy
node_vite_proxy -->|"forwards in development"| node_weather_endpoint
node_api_host -->|"maps"| node_weather_endpoint
node_api_host -->|"maps"| node_health_endpoint
node_api_host -->|"configures"| node_rate_limit
node_weather_endpoint -->|"applies"| node_rate_limit
node_weather_endpoint -->|"checks"| node_response_cache
node_weather_endpoint -->|"fetches on cache miss"| node_provider_client
node_provider_client -->|"uses"| node_provider_options
node_provider_client -->|"HTTPS forecast request"| node_weatherapi
node_weatherapi -->|"forecast payload"| node_provider_models
node_provider_client -->|"deserializes"| node_provider_models
node_provider_models -->|"source payload"| node_forecast_mapper
node_forecast_mapper -->|"maps to"| node_weather_contract
node_weather_endpoint -->|"returns"| node_weather_contract
node_api_test_host -.->|"hosts"| node_api_host
node_endpoint_tests -.->|"exercises"| node_api_test_host
node_provider_tests -.->|"verifies"| node_provider_client
node_provider_tests -.->|"verifies"| node_forecast_mapper

click node_ui_bootstrap "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/main.tsx"
click node_ui_root "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/App.tsx"
click node_ui_service "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/services/weatherApi.ts"
click node_ui_types "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/types/weather.ts"
click node_vite_proxy "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/vite.config.ts"
click node_api_host "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs"
click node_weather_endpoint "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Weather/WeatherEndpoints.cs"
click node_weather_contract "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Weather/WeatherResponse.cs"
click node_rate_limit "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/RateLimiting/WeatherRateLimitOptions.cs"
click node_response_cache "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs"
click node_health_endpoint "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs"
click node_provider_client "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs"
click node_provider_models "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiForecastResponse.cs"
click node_forecast_mapper "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiForecastMapper.cs"
click node_provider_options "https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiOptions.cs"
click node_api_test_host "https://github.com/stevenb32/weatherapp/blob/main/tests/WeatherApp.Api.Tests/WeatherAppFactory.cs"
click node_endpoint_tests "https://github.com/stevenb32/weatherapp/blob/main/tests/WeatherApp.Api.Tests/WeatherEndpointTests.cs"
click node_provider_tests "https://github.com/stevenb32/weatherapp/blob/main/tests/WeatherApp.Api.Tests/WeatherApiClientTests.cs"

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_ui_bootstrap,node_ui_root,node_ui_service,node_ui_types,node_vite_proxy toneBlue
class node_api_host,node_weather_endpoint,node_weather_contract,node_rate_limit,node_response_cache,node_health_endpoint toneAmber
class node_provider_client,node_provider_models,node_forecast_mapper,node_provider_options toneMint
class node_api_test_host,node_endpoint_tests,node_provider_tests toneRose
class node_weatherapi toneNeutral
```

## Components

### React UI

- [React bootstrap](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/main.tsx): Vite entry · `src/WeatherApp.Ui/src/main.tsx`
- [UI root shell](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/App.tsx): React component · Early MVP client shell. · `src/WeatherApp.Ui/src/App.tsx`
- [Weather API service](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/services/weatherApi.ts): TypeScript client · Uses relative /api requests. · `src/WeatherApp.Ui/src/services/weatherApi.ts`
- [Client weather types](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/src/types/weather.ts): TypeScript contract · `src/WeatherApp.Ui/src/types/weather.ts`
- [Vite dev proxy](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Ui/vite.config.ts): proxy boundary · Routes same-origin API requests locally. · `src/WeatherApp.Ui/vite.config.ts`

### ASP.NET Core API

- [API composition](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs): Minimal API host · Registers DI, policies, caching, health checks, and routes. · `src/WeatherApp.Api/Program.cs`
- [GET /api/weather](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Weather/WeatherEndpoints.cs): route handler · Validates inputs and translates weather failures. · `src/WeatherApp.Api/Weather/WeatherEndpoints.cs`
- [Weather response contract](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Weather/WeatherResponse.cs): public DTO · Stable API response with unit selection. · `src/WeatherApp.Api/Weather/WeatherResponse.cs`
- [Weather rate limit](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/RateLimiting/WeatherRateLimitOptions.cs): fixed-window policy · Applies only to weather requests. · `src/WeatherApp.Api/RateLimiting/WeatherRateLimitOptions.cs`
- [In-memory cache](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs): response cache · Caches provider-backed weather responses. · `src/WeatherApp.Api/Program.cs`
- [GET /health](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/Program.cs): health endpoint · Outside the weather rate-limit boundary. · `src/WeatherApp.Api/Program.cs`

### WeatherAPI boundary

- [WeatherAPI client](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs): typed HTTP client · Owns outbound requests and timeout handling. · `src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs`
- [Provider DTOs and errors](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiForecastResponse.cs): internal schema · Prevents provider schema leakage. · `src/WeatherApp.Api/WeatherApi/WeatherApiForecastResponse.cs`
- [Forecast mapper](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiForecastMapper.cs): transformation · Creates current, 24-hour, and three-day API forecasts. · `src/WeatherApp.Api/WeatherApi/WeatherApiForecastMapper.cs`
- [Provider options](https://github.com/stevenb32/weatherapp/blob/main/src/WeatherApp.Api/WeatherApi/WeatherApiOptions.cs): typed configuration · Validates base URL, timeout, cache duration, and credentials. · `src/WeatherApp.Api/WeatherApi/WeatherApiOptions.cs`

### Verification

- [API integration host](https://github.com/stevenb32/weatherapp/blob/main/tests/WeatherApp.Api.Tests/WeatherAppFactory.cs): test factory · Hosts the API with a simulated provider. · `tests/WeatherApp.Api.Tests/WeatherAppFactory.cs`
- [Endpoint tests](https://github.com/stevenb32/weatherapp/blob/main/tests/WeatherApp.Api.Tests/WeatherEndpointTests.cs): integration tests · Verify API behavior without provider calls. · `tests/WeatherApp.Api.Tests/WeatherEndpointTests.cs`
- [Client and mapper tests](https://github.com/stevenb32/weatherapp/blob/main/tests/WeatherApp.Api.Tests/WeatherApiClientTests.cs): focused tests · Cover outbound client and transformation behavior. · `tests/WeatherApp.Api.Tests/WeatherApiClientTests.cs`

### Other components

- **WeatherAPI**: external service · Only external runtime dependency.

## Connections

- React bootstrap → UI root shell: mounts
- UI root shell → Weather API service: uses
- Weather API service → Client weather types: uses
- Weather API service → Vite dev proxy: /api request
- Vite dev proxy → GET /api/weather: forwards in development
- API composition → GET /api/weather: maps
- API composition → GET /health: maps
- API composition → Weather rate limit: configures
- GET /api/weather → Weather rate limit: applies
- GET /api/weather → In-memory cache: checks
- GET /api/weather → WeatherAPI client: fetches on cache miss
- WeatherAPI client → Provider options: uses
- WeatherAPI client → WeatherAPI: HTTPS forecast request
- WeatherAPI → Provider DTOs and errors: forecast payload
- WeatherAPI client → Provider DTOs and errors: deserializes
- Provider DTOs and errors → Forecast mapper: source payload
- Forecast mapper → Weather response contract: maps to
- GET /api/weather → Weather response contract: returns
- API integration host → API composition: hosts
- Endpoint tests → API integration host: exercises
- Client and mapper tests → WeatherAPI client: verifies
- Client and mapper tests → Forecast mapper: verifies
