How stevenb32/weatherapp works
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: WeatherEndpoints.cs GET /api/weather · WeatherApiClient.cs WeatherAPI client · Program.cs API composition · weatherApi.ts Weather API service
Components 19
React UI
- React bootstrap
src/WeatherApp.Ui/src/main.tsx - UI root shell · Early MVP client shell.
src/WeatherApp.Ui/src/App.tsx - Weather API service · Uses relative /api requests.
src/WeatherApp.Ui/src/services/weatherApi.ts - Client weather types
src/WeatherApp.Ui/src/types/weather.ts - Vite dev proxy · Routes same-origin API requests locally.
src/WeatherApp.Ui/vite.config.ts
ASP.NET Core API
- API composition · Registers DI, policies, caching, health checks, and routes.
src/WeatherApp.Api/Program.cs - GET /api/weather · Validates inputs and translates weather failures.
src/WeatherApp.Api/Weather/WeatherEndpoints.cs - Weather response contract · Stable API response with unit selection.
src/WeatherApp.Api/Weather/WeatherResponse.cs - Weather rate limit · Applies only to weather requests.
src/WeatherApp.Api/RateLimiting/WeatherRateLimitOptions.cs - In-memory cache · Caches provider-backed weather responses.
src/WeatherApp.Api/Program.cs - GET /health · Outside the weather rate-limit boundary.
src/WeatherApp.Api/Program.cs
WeatherAPI boundary
- WeatherAPI client · Owns outbound requests and timeout handling.
src/WeatherApp.Api/WeatherApi/WeatherApiClient.cs - Provider DTOs and errors · Prevents provider schema leakage.
src/WeatherApp.Api/WeatherApi/WeatherApiForecastResponse.cs - Forecast mapper · Creates current, 24-hour, and three-day API forecasts.
src/WeatherApp.Api/WeatherApi/WeatherApiForecastMapper.cs - Provider options · Validates base URL, timeout, cache duration, and credentials.
src/WeatherApp.Api/WeatherApi/WeatherApiOptions.cs
Verification
- API integration host · Hosts the API with a simulated provider.
tests/WeatherApp.Api.Tests/WeatherAppFactory.cs - Endpoint tests · Verify API behavior without provider calls.
tests/WeatherApp.Api.Tests/WeatherEndpointTests.cs - Client and mapper tests · Cover outbound client and transformation behavior.
tests/WeatherApp.Api.Tests/WeatherApiClientTests.cs
Other components
- WeatherAPI · Only external runtime dependency.
Connections 22
- 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