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.
You'll need to have Ruby, Node, and Yarn installed on your machine. I recommend going with RVM and NVM but you do you.
$ bundle
$ yarn install$ rails s$ ./bin/devThe overall design for this weather app is simple. In fact, other than the in memory cache it's completely stateless.
- a user interacts with a form which submits a weather request for an address
- the backend validates the correctness of that request and queues it to be performed asynchronously
- 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).
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.
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.