How I built a real world project for the first time 🌈
Tags: react, javascript, node, reactnative
Published: 2020-11-21 16:56:33

I have been learning web development for a year and I have just delivered my very first MVP for a client, this is a huge step forward in my journey to become a real world developer.

In this article, I will write about the building process and design thinking in general. This is not a tutorial by any means, I will simply share my experience with anyone interested.

#Table of contents
<ol>
<li><a href="#intro">Project Introduction</a></li>
<li><a href="#tech">Tech Stack</a></li>
<li><a href="#design">Wireframe & Design</a></li>
<li><a href="#data">Data modeling</a></li>
<li><a href="#project">Project Organization</a></li>
<li><a href="#frontend">Sprint 01: Frontend</a></li>
<li><a href="#backend">Sprint 02: Backend</a></li>
<li><a href="#features">Sprint 03: Implementing features</a></li>
<li><a href="#deploy">Sprint 04: Fix & Deploy</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>

<h1 id="intro">Project Introduction 👋</h1>

Let me introduce the project first. We have to build an MVP for a mobile app that works on both [Android](https://www.android.com/intl/fr_fr/) and [IOS](https://www.apple.com/befr/ios/ios-14/). This app's name is [Allergio](https://www.allergio.net/) and aims to make people with food allergies' life easier.

Thanks to [Allergio](https://www.allergio.net/), you can create a profile for your relatives, register their allergies and share their profiles with your contacts. 

The core feature is the scanner. Open up your phone's front camera, point it towards any food product and a list of the potential allergens will be displayed.

In order to complete this mission, I teamed up with my friend Walid. He is a talented growing JavaScript developer, and it is a pleasure to share this experience with him.

<h1 id="tech">Tech Stack ⚛️</h1>

To build this app, we decided to rely on the very popular [MERN](https://medium.com/@blockchain_simplified/what-is-mern-stack-9c867dbad302) stack which includes:
➡️ [MongoDB](https://www.mongodb.com/)
➡️ [Express](https://expressjs.com/fr/)
➡️ [React Native](https://reactnative.dev/docs/getting-started)
➡️ [Node](https://nodejs.org/en/)

Although these are technologies I am familiar with, I never worked with [React Native](https://reactnative.dev/docs/getting-started) and I don't know much about Mobile development concepts. 

We are considering [AWS](https://aws.amazon.com/fr/free/?trk=ps_a134p000003yhSxAAI&trkCampaign=acq_paid_search_brand&sc_channel=ps&sc_campaign=acquisition_BENELUX&sc_publisher=google&sc_category=core-main&sc_country=BENELUX&sc_geo=&sc_outcome=Acquisition&sc_detail=aws&sc_content=Brand_Core_aws_e&sc_matchtype=e&sc_segment=458573551165&sc_medium=ACQ-P|PS-GO|Brand|Desktop|SU|Core-Main|Core|BENELUX|EN|Text&s_kwcid=AL!4422!3!458573551165!e!!g!!aws&ef_id=Cj0KCQiAkuP9BRCkARIsAKGLE8WFycroaf307gztU0MH5DgKk8A-Ivnm2AYYF2RhsK9G3BGyv7_uNGgaAmrXEALw_wcB:G:s&s_kwcid=AL!4422!3!458573551165!e!!g!!aws&all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc) and [Heroku](https://dashboard.heroku.com/) to host the Backend part and for file management but I will provide more details in the <a href="#deploy">Fix & Deploy</a> section.

It already sounds like a great and exciting challenge 🤩

Here is a list of tools I usually work with to enhance my programming experience:
➡️ OS: [MacOS](https://www.apple.com/)
➡️ Terminal: [iterm2](https://iterm2.com/)
➡️ IDE:[VSCode](https://code.visualstudio.com/)
➡️ Versioning: [Git](https://git-scm.com/)
➡️ Package Manager: [NPM](https://www.npmjs.com/)
➡️ iOS Emulator: [Xcode](https://developer.apple.com/xcode/)
➡️ Andorid Emulator: [Android studio](https://developer.android.com/studio)
➡️ Communication: [Slack](https://slack.com)
➡️ Project Organization: [Trello](https://trello.com)

<h1 id="design">Wireframe & Design 🎨</h1>

Our client Xavier provided simple wireframes and we reworked them a little to make it look "modern" and improve UI/UX.

We mainly worked with [Figma](https://www.figma.com/login) which is a great tool that I 100% recommend. Let me show you a few examples.

Splash Screen:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3kifao1wgao9kmt25le5.png)


Login Screen:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/etyasmyvknuzaa7kep8i.png)

Of course, we redesigned the app following 2020's mobile development conventions, and we took inspiration from famous applications such as [Yuka](https://yuka.io/), [Shazam](https://www.shazam.com/fr), [Spotify](www.spotify.com), ...

<h1 id="data">Data modeling 💾</h1>

Since we are building a Full-Stack application, we must store and manage data. It would be crazy to jump into the coding process without a clear and well-designed action plan.

What kind of data are we playing with:

Users 👤
```JavaScript
{
  email: { type: String, required: true, unique: true },
  password: { type: String, required: true },
  name: { type: String, required: true },
  lastName: { type: String, required: true },
  image: { type: String },
  profiles: [{ type: mongoose.Types.ObjectId, ref: 'Profile' }],
  allergens: [{ type: mongoose.Types.ObjectId, ref: 'Allergen' }],
  contacts: [{ type: mongoose.Types.ObjectId, ref: 'User' }],
}
```

Profiles 👨‍👩‍👧‍👦 (Created by the user for his relatives)
```JavaScript
{
  name: { type: String, required: true },
  image: { type: String, required: true },
  allergens: [{ type: mongoose.Types.ObjectId, ref: 'Allergen' }],
  readers: [{ type: mongoose.Types.ObjectId, ref: 'User' }],
  owner: { type: mongoose.Types.ObjectId, ref: 'User', required: true }
}
```

➡️ Allergens 🥜
```JavaScript
{
  name: { type: String, required: true },
  image: { type: String, required: true },
  description: { type: String, required: true },
  reaction: { type: String, required: true }
}
```

*PS: Unique IDs are provided by MongoDB by default.*

Awesome, we now know what our data looks like but this is not enough. To make our app able to create, read, delete and update data, we must give it the chance to communicate with our server.

You might already know it, [Express](https://expressjs.com/fr/) makes it really easy to build Rest API and that is exactly what we are about to do!

*If you are not familiar with API architecture, I recommend you skip this section.*

API routes:

Users 👤 ⏩ /api/users/
➡️ (GET /:uid ) Get user by ID.
➡️ (POST /signup ) Create user account.
➡️ (POST /login ) Log user in.
➡️ (PUT / ) Edit user information.

Profiles 👨‍👩‍👧‍👦 ⏩ /api/profiles/
➡️ (GET /:uid/all ) Get all profiles of user.
➡️ (GET /:pid ) Get profile by ID.
➡️ (POST / ) Create a new profile.
➡️ (PUT /:pid ) Edit profile information.

Contacts 👥 ⏩ /api/contacts/
➡️ (GET /:uid ) Get user's contacts.
➡️ (POST /search ) Search new contacts.
➡️ (POST /share ) Share profiles with contact.
➡️ (POST / ) Add a contact.
➡️ (DELETE / ) Delete a contact.
➡️ (POST /unshare ) Unshare profiles with contact.

Allergens 🥜 ⏩ /api/allergens/
➡️ (GET /:aid ) Get allergen by ID.
➡️ (GET / ) Get all allergens.
➡️ (GET /name/:name ) Get allergen by name.

We are almost good to go, before you head to the next section, I want to have a quick word about file management.

This is one of the trickiest topic we came across when building [Allergio](https://www.allergio.net/) and I thought it would be interesting to share the solution we came up with.

Here is the problem: how to store images ?

Uploading images directly to the database would slow it down and most image hosting services require you to pay monthly fees.

We decided to build a very simple custom image uploader service that stores images on the server itself and provides a URL to fetch them. This simple server is hosted on an [Ubuntu](https://ubuntu.com/) instance running in the cloud.

This is definitely not the best solution but considering the huge amount of work we have to achieve in a relatively short period of time, it does the job.

{% github KillianFrappartDev/image-manager no-readme %}

<h1 id="project">Project Organization 🗂️</h1>

I will never tell this enough: Organization is the key! 🔑

The organization relies mostly on the [Agile Methodology](https://fr.wikipedia.org/wiki/M%C3%A9thode_agile) because we were introduced to it during our coding bootcamp.

The building process is split in 4 sprints of 5 days (each sprint has its own section) and every one of them must have clearly defined tasks.

On Monday morning, we used to group up to establish an exhaustive list of tasks for the whole week. We used [Trello](www.trello.com) to create little cards for every task.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qpxksyryigri18e9mixo.png)

Every Friday, there was a meeting with our client. He was always happy to have a little demo and thanks to his weekly feedback we could finally deliver a product close to his initial expectations.

Moreover, we tried to stick to daily stand-up in the morning and day retrospective around 5.30 pm.

There is another organization key point whenever you start a brand-new project and it is workflow setup.

We are working with [GitHub](https://github.com/) following Git flow's recommendations as much as possible.

➡️ Not familiar with Git flow ? No worries, have a look to my article! 🧐 

{% link https://dev.to/killianfrappartdev/git-flow-introduction-42c6 %}

Finally, let me show you the folder structure we worked with:

Allergio 📂

- Backend/
--- controllers/
--- models/
--- routes/
--- utils/ 
--- middlewares/

- Frontend/
--- app/
------ assets/
------ components/
------ screens/
------ context/
------ utils/
------ navigation/

<h1 id="frontend">Sprint 01: Frontend 📲</h1>

Time has finally come to start coding! 🔥

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zkfvxwpsyz64cxx9vwma.gif)

Shout out to [Expo](https://docs.expo.io/) that litteraly made this project possible. [Expo](https://docs.expo.io/) is a framework for React applications, it provides a set of tools to start building your application in a matter of minutes and hides most of the complexity when setting up a new project.

It was very scary at first to work with [React Native](https://reactnative.dev/docs/getting-started) because we never used it before but [Expo](https://docs.expo.io/)'s documentation is well-written and I felt like doing mobile development forever in a couple days only.

After we initialized the project, setting up in-app navigation is a great starting point. Very similar to [React Router] (https://reactrouter.com/web/guides/quick-start) for Web, [React Navigation](https://reactnavigation.org/) is a great library that is easy to get started with and provides a good solution for every use cases.

We decided to implement a bottom tab navigation for optimal user experience:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/o1t29mqrg69zgdk0ll95.gif)

Another important step is to setup a global context. Every React developer knows how tidious it might be to lift state up through props when you project is growing bigger.

To answer that need of a global state, we went for [React Context](https://fr.reactjs.org/docs/context.html) mainly to store user information such as name, last name, image and wether he is logged or not.

Everything seems to work fine so far, let's build our screens and components. We have about 10 screens to build (There is inner navigation for each tab) and around twice as much components like buttons, cards, inputs, bottom sheets and much more.

At this point, we are working with dummy hard coded data. Our components are mostly function components and their state is managed with [React Hooks](https://fr.reactjs.org/docs/hooks-intro.html).

Hopefully, we have enough time to implement camera features and request to an external API to gather information about food products before the end of the first sprint.

<h1 id="backend">Sprint 02: Backend 📊</h1>

As I mentionned before, this project's backend is a Node/Express Rest API linked to a cloud [MongoDB](https://www.mongodb.com/) database.

In order to make it work, we start by installing dependencies such as [cors](https://developer.mozilla.org/fr/docs/Web/HTTP/CORS), [body-parser](https://www.npmjs.com/package/body-parser), [mongoose](https://mongoosejs.com/), [nodemon](https://www.npmjs.com/package/nodemon), ... 

When working with MongoDB, I highly recommend you work with [mongoose](https://mongoosejs.com/) as well. It makes your life so much easier. Define mongoose models for your data, connect to the database and you are good to go ✅

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7t00fefksy3891ga4o0f.png)

Then, we register routes just like I already explained <a href="#data">here</a> and connect each route to a dedicated controller.

Every controller's behavior must be tested and for that you can give [Postman](www.postman.com) a try.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/28uqrq5umgeh2fm8bwlm.png)

Finally, we improve our server's robustness with proper error handling middleware and enhance development experience with nodemon and environement variables.

<h1 id="features">Sprint 03: Implementing features 
⭐</h1>

This is by far the most exciting week, when we finally see the result of everything we did before. 

We spend this entire week connecting Frontend user interface to Backend controllers via HTTP requests and update the database in real time.

HTTP request are done using [Axios](https://github.com/axios/axios) which is a personnal preference.

There are many features to implement this week:
➡️ Login/Signup with Email and password.
➡️ Create and update profiles.
➡️ Edit user information.
➡️ Add/remove contacts.
➡️ Share profiles with contacts.
➡️ Upload images from phone's gallery.
➡️ Send SMS to invite friends.
➡️ ...

Native functionnalities such as SMS, camera and photo gallery could be implemented thanks to Expo's incredible [doc](https://docs.expo.io/) 🌟

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zd5fsi8u372najwtxiz3.jpg)

<h1 id="deploy">Sprint 04: Fix & Deploy ☁️</h1>

Last week of this incredibly enriching adventure. I already learned a lot and spent so much time and energy. We are getting tired but there is still work to do before we send our project to the client.

Thousands of lines are waiting to be refactored and plenty of little bugs still remain. Let's start by cleaning this up and fixing as many style issues as possible.

[AWS](aws.amazon.com) has a cloud service called EC2. We create an Ubuntu instance and connect via SSH. After a bit of setting things up, our server and image manager are running in the cloud.

Right now, the app is only available through Expo's hosting but we are looking to deploy it on App store and play store soon.

<h1 id="conclusion">Conclusion ✅</h1>

Four intensive weeks have passed, we are tired, the project is still a little buggy but the client is happy and that is what matters the most.

In my opinion, my friend Walid and I did a great job here, working on a real project for the first time and facing obstacles made us better developers.

I wanted to provide a link to the app's demo or source code with this article but since this project is in the alpha phase, the client would like to keep some information confidential. 

Thank you very much for reading!

I would love to have a feedback from you, any tips to improve as a developer or as a blogger is very appreciated 😇