Skip to content

Diasporism/weather_app

Repository files navigation

Weather App

A simple weather app demonstrating the power of Rails + Hotwire. You enter an address and it gives you the current weather and 7 day forecast.

Get Up and Running

Pre-requisites:

You'll need to have Ruby, Node, and Yarn installed on your machine. I recommend going with RVM and NVM but you do you.

Install Gems/Packages:

$ bundle
$ yarn install

Run the Server:

$ rails s

Run the Asset Compilers and ActionCable/ActiveJob:

$ ./bin/dev

Architecture & Design

The overall design for this weather app is simple. In fact, other than the in memory cache it's completely stateless.

  1. a user interacts with a form which submits a weather request for an address
  2. the backend validates the correctness of that request and queues it to be performed asynchronously
  3. the background job checks the cache for existing results
    • if the result is found, it broadcasts the result immediately
    • if the result is not found, it fetches the weather from external APIs, caches it, and broadcasts the result

Turbo and ActionCable are used for as the pubsub mechanism. A unique session_id is given to each user on the site and used for the broadcasting address (this is in lieu of having actual users with IDs).

About Those 3rd Party APIs...

I used Pirate Weather as a Dark Sky alternative to fetching weather forecast data and Maps.co for geocoding. Both services are using a free tier and are severly rate limited to prevent abuse. You'll find their simple wrapper clients in app/lib.

The API keys are encrypted and checked into the repository using Rails Credentials and I have knowingly leaked the master decryption key so that others can test this without having to signup for their own keys.

There's a good chance in the near future I will rotate/deactivate the keys and you'll have to replace them yourself.

Further Reading

You can read more about Hotwire here - I'd highly recommend it. Additionally, I used Tailwind for styling cause it's just easier™. If it's new to you I'd start here.

About

A simple weather app demonstrating the power of Rails + Hotwire.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors