Giter VIP home page Giter VIP logo

weather-app's Introduction

Weather Forecast

Local Development with Docker

We'll use Docker for local development. Since we're not using databases or external local services that require their own Docker images, this is of limited value currently, but if we choose to add them on, then all the groundwork is there, and we can quickly add them into Docker Compose.

Dependencies

You need Docker installed to run this app. You can download it here

Installation

Clone this repo, then run docker-compose from the project root.

docker-compose up

Architecture Decisions

Next.JS

We'll use Next.JS for our front end framework. It wraps around React and gives us Static Rendering and Server Side Rendering if needed, which will be perfect fetching weather data from the API on the server rather than the client.

GraphQL

Since there are several pieces of information that we want regarding related data sets, it's a better idea to use GraphQL so that all this can be achieved in one request. Much simpler and easier to read.

TypeScript

Our data is coming from an external source, and this is where TypeScript really shines. We want to ensure that the incoming data is of a very specific shape so that it doesn't cause bugs in our app.

Styled Components

We want our code to be as semantic as possible, so that others can read it easily. Styled Components helps us achieve this in the best possible way. In my opinion <LocalWeatherTemp /> is much more readable than:

<div class="local-weather-temp weather-detail">{data}</div>

Data Flow

Weather Data Flow

When a User navigates to the site, the App makes a request to the local GraphQL API for the data that it needs to

Geolocation API

We'll use the Geolocation API to find out where the User is based, although they'll need to click "accept" when their browser prompts them. The reason for doing this is that it's far easier than getting them to input their city and then validating it. We will have to handle the situation where they refuse to accept the Geolocation request, though.

OpenWeatherMap API

Testing API Endpoints

We can use curl to test OpenWeatherMap API endpoints, like so:

curl https://api.openweathermap.org/data/2.5/weather?lat=31.768318&lon=35.213711&appid=9c5f6ab0d19802f72a11bec902d3ad00

Current Weather

We'll use the longitude and latitude we got from the Geo API for the OpenWeatherMap Current Weather API call:

api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={your api key}

Five Day Forecast

We'll also use them for the five day forecast API call:

api.openweathermap.org/data/2.5/forecast?lat=35&lon=139

Relevant Documentation

Here are links to the relevant API documentation:

Typeography

We'll use Google fonts:

  • Alata
  • Roboto

The should be called like so:

font-family: 'Alata', sans-serif;
font-family: 'Roboto', sans-serif;

Design

Our design is loosely based off of Accuweather.com. Kudos to their design team.

Secrets

Because this is a non-production app, managing secrets becomes a little tricky, since we don't want to go to all the trouble of using a Docker or Vercel secrets service. So we will store them as environment variables, with the understanding that if this became a production app, we'd store them much more securely.

Navigation

We want really fast page loads. Because we only have one other page, pre-fetching its data will not overburden the system, so we'll use Next.JS' link component to acheive that.

weather-app's People

Contributors

bengrunfeld avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.