A production-ready weather service with a modern layered architecture, featuring an interactive web interface, futuristic API documentation, and dual-layer caching. Built with Go, React + TanStack, and OpenStreetMap.
- ποΈ Layered Architecture: Clean separation with handlers β services β repository β models
- π Dual-Layer Caching: Redis (fast in-memory) + SQLite (persistent storage)
- π‘οΈ Temperature Conversion: API returns both Celsius and Fahrenheit
- πΊοΈ NWS Integration: Uses National Weather Service API for accurate forecasts
- π Health Monitoring: Built-in health check endpoint
- π Error Handling: Comprehensive validation and error responses
- π¨ Swiss Luxury Design: Premium, minimalist aesthetic inspired by high-end spas
- πΊοΈ Interactive Map: OpenStreetMap via Leaflet with click-to-weather functionality
- π Temperature Toggle: Switch between Celsius and Fahrenheit on the fly
- π± Fully Responsive: Adapts gracefully from desktop to mobile
- π― Lucide Icons: No emojis - only high-quality Lucide React icons
- β‘ Bun: Fast package management and builds
- π Futuristic UI: Modern sci-fi inspired design at
/docs - π§ Stoplight Elements: Interactive OpenAPI documentation (not Swagger)
- π¨ Dark Theme: Gradient backgrounds with glass-morphism effects
- π Auto-Generated: OpenAPI spec generated automatically from Go code
# Clone the repository
git clone https://github.com/4cecoder/weather-api-go.git
cd weather-api-go
# Run everything (backend + frontend)
./run.sh # macOS/Linux
# OR
.\run.ps1 # WindowsThen open:
- Main App: http://localhost:3000
- API Docs: http://localhost:3000/docs
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down# Backend
go build -o weather-api .
./weather-api
# Frontend (in another terminal)
cd frontend
bun install
bun run dev| Service | URL | Description |
|---|---|---|
| Main App | http://localhost:3000 | Interactive weather map |
| Frontend Dev | http://localhost:5173 | React dev server (if running) |
| API Docs | http://localhost:3000/docs | Futuristic API documentation |
| Health Check | http://localhost:3000/api/health | Service health status |
| Weather API | http://localhost:3000/api/weather?lat=40.7128&lon=-74.0060 | Get weather data |
Returns current weather forecast for coordinates with both Celsius and Fahrenheit.
Parameters:
lat(required): Latitude (-90 to 90)lon(required): Longitude (-180 to 180)
Example Request:
curl "http://localhost:3000/api/weather?lat=40.7128&lon=-74.0060"Example Response:
{
"forecast": "Partly Cloudy",
"temperature": "moderate",
"temperature_c": 22.5,
"temperature_f": 72.5
}Health check endpoint.
Example Response:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00Z"
}Futuristic interactive API documentation - Stoplight Elements with:
- Auto-generated from OpenAPI spec
- Try-it-out functionality
- Dark gradient theme with glow effects
- Links to GitHub repo
internal/
βββ handlers/ # HTTP handlers (Fiber)
β βββ weather.go # Weather endpoint handlers
β βββ docs.go # API documentation
βββ services/ # Business logic
β βββ weather.go # Weather service with temp conversion
β βββ nws_client.go # NWS API client
βββ repository/ # Data access layer
β βββ weather.go # Redis + SQLite caching
βββ models/ # Data structures
βββ weather.go # Request/response types
frontend/
βββ src/
β βββ App.tsx # Main app with TanStack Query
β βββ App.test.tsx # Unit tests
β βββ index.css # Swiss luxury spa styling
βββ e2e/ # Playwright E2E tests
βββ package.json # Bun dependencies
- Redis (Primary): Sub-millisecond response times
- SQLite (Fallback): Persistent storage for durability
Cache TTL: 1 hour
- Hot: β₯ 30Β°C (86Β°F) - shown in coral
- Cold: β€ 10Β°C (50Β°F) - shown in blue
- Moderate: 10Β°C - 30Β°C - shown in green
# Run all Go tests
make backend-test
# With coverage
make test-coverage# Run unit tests
make frontend-test
# Run E2E tests
make e2e-test# Run everything (backend + frontend + build)
make ci# Backend
make backend-test # Stage 1: Run tests
make backend-build # Stage 2: Build binary
make backend-run # Stage 3: Run locally
# Frontend
make frontend-deps # Stage 1: Install deps
make frontend-test # Stage 2: Run tests
make frontend-build # Stage 3: Build production
# Full CI
make ci # Run complete pipeline| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
REDIS_URL |
Redis connection URL | localhost:6379 |
DATABASE_URL |
SQLite database path | ./weather_cache.db |
weather-api-go/
βββ cmd/weather-api/ # Application entry point
βββ internal/
β βββ handlers/ # HTTP handlers
β βββ services/ # Business logic
β βββ repository/ # Data access
β βββ models/ # Data structures
βββ frontend/ # React + TanStack frontend
β βββ src/
β βββ e2e/ # Playwright tests
β βββ package.json
βββ .github/workflows/ # CI/CD pipeline
βββ dist/frontend/ # Built frontend files
βββ Dockerfile # Multi-stage Docker build
βββ docker-compose.yml # Service orchestration
βββ run.sh # Unix startup script
βββ run.ps1 # Windows startup script
βββ Makefile # Organized build pipeline
βββ README.md # This file
Premium, minimalist aesthetic with Swiss luxury influences. Uses Lucide React icons exclusively (no emojis), neutral color palette, and responsive design from desktop to mobile.
-
Caching: Currently uses 1-hour TTL. For production:
- Consider stale-while-revalidate pattern
- Implement cache warming strategies
- Different TTLs for varying freshness needs
-
Database: SQLite for simplicity. For production:
- PostgreSQL or MySQL for better concurrency
- Connection pooling
- Database migrations
-
Testing: Unit + E2E tests present. Consider adding:
- Load tests
- Chaos engineering tests
- Contract tests
-
Monitoring: Add for production:
- Structured logging (e.g., Zap)
- Metrics collection (Prometheus)
- Distributed tracing
MIT License - See LICENSE file for details
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Follow the existing code style
- Add tests for new features
- Submit a pull request
- National Weather Service for weather data
- OpenStreetMap for map tiles
- Stoplight for Elements documentation
- TanStack for Query and modern React patterns
Built with β€οΈ by 4cecoder