Side project: Life-Advise Web App
Tags: webdev, javascript, programming, react
Published: 2022-06-04 10:25:02


## Side Project: Life-Advise Web App

### Offline-first PWA for fetching advice and sending notifications to users.

![[First page](https://life-advise.netlify.app/)](https://cdn-images-1.medium.com/max/2000/1*q5JU7wP70Ho3bsasbiKOOg.png)

---


## About the app:

offline first, full-featured quotes and advice generator web app to get some wonderful advice about life, success, money …etc.
[**Life - Advise**](https://life-advise.netlify.app/random)

The main goal is to read random advice and quotes, you can save the quote you like and add some notes about it.

The app will send you daily notifications if you want, the notifications contain random advice and quotes, you can either save it without the need to or open the app, or if you want to see it in the app you can open it and add notes and save it or just see other ones.

### Repos for the app:
[**GitHub - osama865/life-advice-client**](https://github.com/osama865/life-advice-client)
[**GitHub - osama865/life-advise-server**](https://github.com/osama865/life-advise-server)
[**osama865 - Overview**](https://github.com/osama865/)

---

## App pages:

### Favourites:

this page contains your favourite advice, you can modify the note you wrote along with the advice or remove it from the saved.

![Saved Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5r4of62chzlcloo2i3z.png)
 

### Random:

Fetch random advice from the database and show it to you so you can save it or fetch another one.

![Random page](https://cdn-images-1.medium.com/max/2130/1*SEw8tgzH2AyxZ-E_z9vYNg.png)

### All :

If you liked the given advice and want to read a lot of them, this page is for you, you can go through hundreds or even thousands of devices, on the random page you only have one piece of advice per time but here there is no limit so feel free and read as much as you want.

![All page](https://cdn-images-1.medium.com/max/2286/1*WX_kMGOdrwLpMbRtARJAqQ.png)

---

## Technologies I used:

### Client-Side Technologies:

***react:*** 
My main Stack is MERN where I always use react for building interactive UIs,· Components Based apps with the reusability in mind.
[**React - A JavaScript library for building user interfaces**](https://reactjs.org/)

***react-router:
*A tool that allows you to handle routes in a web app, using dynamic routing**.
To handle routing and navigation through the app’s pages
[**Declarative routing for React apps at any scale | React Router**](https://reactrouter.com/)

***service workers:***
>  A service worker is a type of web worker. It’s essentially **a JavaScript file that runs separately from the main browser thread, intercepting network requests, caching or retrieving resources from the cache, and delivering push messages**.

To make my web app installable and add more features like receiving notifications and taking actions without the need to open up the app.

***PWA:
***Progressive Web Apps (PWAs) are *web apps that use service workers, manifests, and other web-platform features in combination with progressive enhancement to give users an experience on par with native apps.*
[**Progressive Web Apps**](https://web.dev/progressive-web-apps/)

***IndexedDB and dexie.js:***
>  The Indexed Database API is a JavaScript application programming interface provided by web browsers for managing a NoSQL database of JSON objects.

I decided to go along with [indexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) for saving user advice over storing users’ favourites on the server for more simplicity and performance and to discover new technologies.
[**Dexie.js**](https://dexie.org/)

simply when you want to save advice, it will be stored in indexedDB storage and will be fetched whenever you want even when you go offline.

you can also modify notes, and delete the saved ones without the need for an internet connection (since the indexedDB is browser storage, no data will be transferred over the network).

***Cache:
***The backbone of offline applications is the cache, when the app loads for the first time it stores the needed pages in the cache so the next time your pages will be served from the cache instead of the server.

There are a few cache strategies for your app, here are useful links
[**5 Service Worker Caching Strategies for Your Next PWA App**](https://blog.bitsrc.io/5-service-worker-caching-strategies-for-your-next-pwa-app-58539f156f52)
[**Frontend caching strategies**](https://medium.com/@brockreece/frontend-caching-strategies-38c57f59e254)
[**The Power of Caching in JavaScript**](https://jsmanifest.com/the-power-of-caching-in-javascript/)

---


## Notification Part:

![double opt-in a two-step permission request](https://cdn-images-1.medium.com/max/2000/1*w1X7Co-1S-j32SPKjb_lEQ.png)

I choose to use **Double opt-in a two-step permission request** push notification for a good user experience and more. **
**The first pop-up will tell you why the app needs notification permission and when you feel okay with that the real permission request will show to you.

Why you should always use **double opt-in a two-step permission request:
**it's more user friendly by giving the user a brief description of how your app will use the notification, instead of the ugly standard permission request that tells the user nothing but request to allow or block

when you use a single opt-in a one-step permission request your users won't be able to know why you need to push notifications for them! maybe they will think you are scamming them and the worst thing that will happen is they will block your site from pushing notifications.

The opposite goes with double opt-in a two-step permission request when users are aware of why you need notifications and they will be comfier about your app and that increases the chances for your permission request to be allowed

The most important thing about using double opt-in a two-step permission request is that you’ll have another chance to ask your users for notifications permission.
[**Everything You Need to Know About PWAs — Push Notifications**](https://betterprogramming.pub/everything-you-need-to-know-about-pwas-push-notifications-e870bb54e14f)
[**How To Optimize Progressive Web Apps: Going Beyond The Basics - Smashing Magazine**](https://www.smashingmagazine.com/2020/12/progressive-web-apps/#user-friendly-notifications-and-permission-requests)

When you click confirm on the first pop-up, the real one appears and asks for permission.

![permission request](https://cdn-images-1.medium.com/max/2000/1*nm-J7ai-8u0ZaNqgiAP7og.png)

When allowed, a welcoming sample notification will be sent to you with the unsubscribe option to stop receiving notifications if you're not satisfied with this feature.

![Welcoming notification with unsubscribe button from this feature](https://cdn-images-1.medium.com/max/2000/1*NM0ZTe2XhHZYiYdFJqO57Q.png)

Typical notifications will look like this one, the advice or the quoted text with who said it or the author.

![usual notification will be like this](https://cdn-images-1.medium.com/max/2000/1*qFkFKrYERbeXeqjf-pbrLg.png)

### Buttons :

Save button will add the advice or the quote to your favourite whiteout opening the app. magic right ?!

The open button will open the app and you will be able to see the clicked advice or quote in the app so you can add notes and save them or see other ones.

i wish i can add more buttons to the notifications so the user can have more actions to take.

---


## Server-side technologies:

### Node.js:

Node.js is a free, open-sourced, cross-platform JavaScript run-time environment that lets developers write command-line tools and server-side scripts outside of a browser.

in the back-end, I’m using node js to run my server code.
[**Node.js**](https://nodejs.org/)

### express.js:

Express is a minimal and flexible **Node**.**js** web application framework that provides a robust set of features for web and mobile applications.

I use express to create endpoints and handle requests and responses with ease
[**Express - Node.js web application framework**](https://expressjs.com/)

### web push:

Web push requires that push messages triggered from a backend be done via the [Web Push Protocol](https://tools.ietf.org/html/draft-ietf-webpush-protocol) and if you want to send data with your push message, you must also encrypt that data according to the [Message Encryption for Web Push spec](https://tools.ietf.org/html/draft-ietf-webpush-encryption).

This module makes it easy to send messages and will also handle legacy support for browsers relying on GCM for message sending/delivery.

I make use of the web-push library to send notifications from my server to the users.
[**web-push**](https://www.npmjs.com/package/web-push)
[**Getting Started with Push Notifications in Node.js using Service Workers**](https://www.section.io/engineering-education/push-notification-in-nodejs-using-service-worker/)

### mongodb.js:

The official MongoDB Node.js driver allows Node.js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to interact with MongoDB using Promises or via traditional callbacks.

I used the mongodb.js driver for simplicity and fast development, it's used to connect your server with your database (mongo atlas for example)
[**MongoDB official MongoDB driver for Node.js. Upgrading to version 4? Take a look at our upgrade guide here! Think you've…
**](https://www.npmjs.com/package/mongodb)
[**MongoDB and Node.js Tutorial - CRUD Operations**](https://www.mongodb.com/developer/quickstart/node-crud-tutorial/)
[**Node JS with MongoDB CRUD Operations: 6 Easy Steps - Learn | Hevo**](https://hevodata.com/learn/node-js-with-mongodb-crud/)

---


## Deployment:

### Netlify:

Netlify is **a web development platform that multiplies productivity**. By unifying the elements of the modern decoupled web, from local development to advanced edge logic, Netlify enables a 10x faster path to much more performant, secure, and scalable websites and apps.

For me, netlify was always my go-to when it comes to deploying my react or any client-side projects.

I highly recommend using netlify for its unique features and it makes it easy to deploy and maintain your applications with features like continuous deployment
[**Netlify: Develop & deploy the best web experiences in record time**](https://www.netlify.com/)
[**Guide to Deploying a React App to Netlify**](https://stackabuse.com/guide-to-deploying-a-react-app-to-netlify/)

### Heruko:

Heroku is a container-based cloud Platform as a Service (PaaS). Developers use Heroku **to deploy, manage, and scale modern apps**. Our platform is elegant, flexible, and easy to use, offering developers the simplest path to getting their apps to market.

When I want to deploy the node js app, the only host I can think of is heruko.
although it has its cons with the free plan and their pricing is a little more expensive than other solutions but I still like it
[**Getting Started on Heroku with Node.js**](https://devcenter.heroku.com/articles/getting-started-with-nodejs)
[**Build and Deploy a Node.js App to Heroku**](https://developer.okta.com/blog/2022/02/28/build-deploy-node-app-heroku)

### Database:

***MongoDB Atlas:***
MongoDB Atlas is **a fully-managed cloud database that handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice** (AWS, Azure, and GCP). MongoDB Atlas is the best way to deploy, run, and scale MongoDB in the cloud.
[**MongoDB Atlas Tutorial**](https://www.mongodb.com/basics/mongodb-atlas-tutorial)

---

## Coming Features :

### Settings page :

make the app fully customised by the user 
user can modify the themes and set the notifications numbers per day
personalise tags for advice to get only advice that matter to you ( relationships, success, money, inspiration …etc)
notifications setting like when you like the app to send notifications and also notification sound and if you want to unsubscribe from this feature
as well as what buttons you want to see with the notifications.

### Search advice:

a small icon that allows you to do a simple search about the advice and its author.

### Animations:

Make them feel good and work smoothly with animations so the user never gets bored by the strict view.

### Copy advice:

a small icon that allows you to copy the advice you see and its author and send it to your friends.

### Create APIs for third-party services:

I want to share my database with other devs, so in future, I’ll Expose APIs for the database so anyone can fetch and use the data there.

And much more enhancement and improvement in the app performance and make it more customized and user friendly.

---


***PLEASE*** if you have any questions or features you want or advice for me to improve my app, or you want to report a bug, feel free to contact me any time.

[Twitter](https://twitter.com/Osam1010), [Email](http://osama0000ibrahim@gmail.com), here in medium or visit [my portfolio](http://o-portfolio.netlify.com/).

---

## Resources That helped me:
[**Progressive Web Apps Training | Google Developers**](https://developers.google.com/web/ilt/pwa)

[**Progressive Web Apps**](https://web.dev/progressive-web-apps/)
[**Progressive web apps (PWAs) | MDN**](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps)
[**PWAs Power Tips－firt.dev**](https://firt.dev/pwa-design-tips)

[**How To Optimize Progressive Web Apps: Going Beyond The Basics - Smashing Magazine**](https://www.smashingmagazine.com/2020/12/progressive-web-apps/)

[**Everything You Need to Know About PWAs — Push Notifications**](https://betterprogramming.pub/everything-you-need-to-know-about-pwas-push-notifications-e870bb54e14f)

[**Push Notification UX: The Full Guide 2022 (Updated)**](https://uxcam.com/blog/push-notification-guide/)

[**How To Optimize Progressive Web Apps: Going Beyond The Basics - Smashing Magazine**](https://www.smashingmagazine.com/2020/12/progressive-web-apps/#the-application-works-offline-as-it-does-online)

---

Thanks for reading, and feel free to ask any question about javascript or this series, and I appreciate any feedback to improve My content.

Find me on [twitter](https://twitter.com/Osam1010), [github](https://github.com/osama865/) and [my portfolio](http://o-portfolio.netlify.com/).