Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Weather API Service

GitHub Repository

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.

Weather API Screenshot

✨ Features

Backend (Go)

  • πŸ—οΈ 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

Frontend (React + TanStack)

  • 🎨 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

API Documentation

  • πŸš€ 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

πŸš€ Quick Start

Option 1: One-Command Startup (Recommended)

# 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         # Windows

Then open:

Option 2: Docker

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Option 3: Manual Development

# Backend
go build -o weather-api .
./weather-api

# Frontend (in another terminal)
cd frontend
bun install
bun run dev

🌐 Available URLs

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

πŸ“‘ API Endpoints

GET /api/weather

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
}

GET /api/health

Health check endpoint.

Example Response:

{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00Z"
}

GET /docs

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

πŸ—οΈ Architecture

Layered Backend Structure

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 Architecture

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

Caching Strategy

  1. Redis (Primary): Sub-millisecond response times
  2. SQLite (Fallback): Persistent storage for durability

Cache TTL: 1 hour

Temperature Classification

  • Hot: β‰₯ 30Β°C (86Β°F) - shown in coral
  • Cold: ≀ 10Β°C (50Β°F) - shown in blue
  • Moderate: 10Β°C - 30Β°C - shown in green

πŸ§ͺ Testing

Backend Tests

# Run all Go tests
make backend-test

# With coverage
make test-coverage

Frontend Tests

# Run unit tests
make frontend-test

# Run E2E tests
make e2e-test

Full Test Suite

# Run everything (backend + frontend + build)
make ci

πŸ› οΈ Development

Build Pipeline (Organized Stages)

# 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

Environment Variables

Variable Description Default
PORT Server port 3000
REDIS_URL Redis connection URL localhost:6379
DATABASE_URL SQLite database path ./weather_cache.db

πŸ“ Project Structure

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

🎨 Design

Premium, minimalist aesthetic with Swiss luxury influences. Uses Lucide React icons exclusively (no emojis), neutral color palette, and responsive design from desktop to mobile.

πŸ“ Development Notes

Trade-offs & Future Improvements

  1. Caching: Currently uses 1-hour TTL. For production:

    • Consider stale-while-revalidate pattern
    • Implement cache warming strategies
    • Different TTLs for varying freshness needs
  2. Database: SQLite for simplicity. For production:

    • PostgreSQL or MySQL for better concurrency
    • Connection pooling
    • Database migrations
  3. Testing: Unit + E2E tests present. Consider adding:

    • Load tests
    • Chaos engineering tests
    • Contract tests
  4. Monitoring: Add for production:

    • Structured logging (e.g., Zap)
    • Metrics collection (Prometheus)
    • Distributed tracing

πŸ“„ License

MIT License - See LICENSE file for details

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow the existing code style
  4. Add tests for new features
  5. Submit a pull request

πŸ™ Acknowledgments


Built with ❀️ by 4cecoder

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages