Full Stack Airbnb Clone with Next.js, Tailwind CSS, Zustand and Amplication
Tags: nextjs, webdev, react, javascript
Published: 2023-08-14 10:33:47

In this blog post you'll learn how to create a Full Stack Airbnb Clone using Amplication.

## Features of the AirBnb Clone
- Built using Next.js
- Styled with Tailwind CSS
- Backend generated using Amplication
- State Management with Zustand
- Realtime Maps using Mapbox API 
- Login Signup using JWT Tokens
- API Call's using Axios

## Functionalites of the AirBnb Clone
- Create Listings
- View Listings
- Book Listings
- Delete Listings
- Add Listing to Wishlist
- Remove Listing from Wishlist
- View booked Listings
- Search Listings
- Search Listings using Map
- View Listings Data on Map

This blog post is a part of my Youtube video. Check out the amazing video.

{% youtube nkmPmUpUM6U %}

## Unleashing the Power of Amplication: Accelerating Software Development with Ease

[Amplication](https://amplication.com/) is an open-source development tool designed to simplify and expedite the process of building web applications. With its user-friendly interface and a wealth of features, Amplication empowers both developers and organizations to create robust and scalable applications quickly, saving valuable time and resources in the process.

The platform is centered around the concept of a low-code development environment, which allows developers to build applications by configuring and connecting pre-built building blocks rather than writing code from scratch. This approach dramatically reduces the amount of manual coding required, enabling teams to focus on creating business logic and delivering a polished end product.

### Step 1: Fork the starter git repository:

Clone this [git repository](https://github.com/koolkishan/nextjs-airbnb-clone-starter) to get starter files for the Airbnb Clone.

### Step 2: Create a amplication account

Head over to [amplication login](https://app.amplication.com/login) and connect your github.


![Amplication login page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9x4nuy88unfzoxwnz44.png)

### Step 3: Create your first service

Now you need to create a service for amplication which in turn generate your backend code. Give it a meaningful name.

We are going to name it AirBnb and hit continue.

![Amplication Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/etr3m647nhe2fmmat7l1.png)

### Step 4: Connect with Github and Select Repository

Now you need to connect with Git. There are various options available but we are going to use Github for our git provider.

![Git Providers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fwy573zbl15d4ea7u0gr.png)

After you connect with github you need to select a repository. Select the airbnb repo.

![Selected Git Repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eidwznfp3n75rt2o85es.png)

Now hit continue.

### Step 5: Selecting GraphQL / RestAPI & Swagger UI / Admin UI

In this step you can enable the options for support of the GraphQL API, the REST API & Swagger UI and the Admin UI provided by Amplication.

![API Selection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6kuts1n86jn0t38w8s7d.png)

We are going to enable all the options here. Though we will not be using the GraphQL API for the app but for the demo purposes we are enabling it.

We are going to use the REST API's through out the AirBnb clone. Also we will be using Swagger to test out the API's.

### Step 6: Selecting the type of backend structure generated by Amplication.

Amplication provides two types of structure for the generated code.

- Polyrepo
If you are using a polyrepo, Amplication will push the code to the root of the repo in separate folders for the server and the admin-ui.

- Monorepo
If you are using a monorepo, you can select the folder where you want to save the code of the service. “apps”, “packages”, “ee/packages” all are valid.

We are going to use the Polyrepo option for this project.

![Amplication Polyrepo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xn1qvuywcwsenh2946m.png)

It will generate two folders into the root of our repository, named as server and admin-ui

![Code Directory](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cgq6d0go066sxk28m69.png)

Now hit continue.

### Step 7: Select the database.

Amplication provides three types of database at the moment.

- PostgreSQL
- MongoDB
- MySQL

![Amplication databases](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxat2r5e1g7ip48hhmix.png)

Amplication generates the service with all the required configuration and code to start working with a DB.

You can easily change the type of the DB later in the plugins page

For this AirBnb Clone we are going to use the PostrgreSQL DB.

Now hit continue.

### Step 8: Selecting a Templates for your Project

Amplication provides two options for your entities.

- Empty
Manually define your own entities and fields

- Use a Template
Pre-defined set of entities and fields Address, Orders, User

You can start from scratch or select a demo template.

We are going to select the empty option here.

![Templates](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bvgzoa5wk3ntbhfri8i.png)

Hit continue.

### Step 9: Selecting Auth Services

Amplication provides in built auth module that pre generates code for you authorization and authentication.

For this Amplication provides two options

- Include Auth Module
Generate the code needed for authentication and authorization

- Skip Authentication
Do not include code for authentication

For our AirBnb clone we are going to use the auth module provided by Amplication so we are going to select Include Auth Module Option.

![Amplication Auth](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9doyp8mw9aixkgadxwq.png)

Now hit continue 

All the initial setup is done and now Amplication will generate the code. Wait for it to generate. This may take a minute or two.

![Amplication code generated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4etoxaf8t681ghzqhol.png)

After the code is generated you can see the following screen that the code has been generated.

Now you select view my code button and it will redirect you to the Github Page

### Step 10: Merge the pull request generated by amplication

Now after every change in Amplication service it will generate a new pull request that needs to be merged in Github  with our code.

Now on the Github Pull Request page you have to merge the code with Merge pull Request button.

![Merge Pull Request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ry0s969fh8pmoth7nqtc.png)

You can also check the code generated by Amplication by clicking the Files Changed Option

![Github Files Changed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12xx1itbynetzewm0xbh.png)

This will show you all the code generated by Amplication.

Now head over to the amplication tab and hit continue.

You will see the success page.

![Amplication Setup Success](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w08agk6klwfj9xf68s3e.png)

You have successfully setup your Amplication app.

Now click on create entities option to create entities.

![Amplication Create Entities Option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yny1pu8km90o6f2iw662.png)

Entities are like table in DB.

Now there is a predefined entity here which is for users in your application.

![User Entity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k17bpvo4552zm82ol73v.png)

## Setting up Amplication Entities

We will be using four entities in our AirBnb Clone

- **user:**
Manages all users with their details.
- **listings:**
This will store all entities created by a user.
- **trips:**
If a user books a listing then it would be stored in this entity.
- **wishlists:**
If a user add a listing into their wihshlists then this would be stored in the Wishlists entity.

![Amplication Entities](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/viuhctfs3vev6irkceuh.png)


### Setup Listings

Now click on Add Entity button on Top Right Corner

![Create Entity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dpn8pvslwj0s8ep9wvz.png)

On the new Entity Modal screen type listings as the name of new entity and hit create entity.

![New entity modal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bkhq1tkfae2geqask1n.png)

Now you will be redirected to the listings entity details page.

From here you can add new fields to your entity or even give granular permissions to the entity according to the roles.

![Listings Entity Details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19y2gyrw1bhpsftychqo.png)

Now from here we need to create some fields that we are going to use for our AirBnb Clone.

### title Field

Click on the add field button 

![Entity Add Field](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ew8mg3wgoutqcgrzdrzw.png)

Write title as the name and click on + right beside it.

You can see that the the new field is created and there are various options to configure.

We are going to mark this field as `required`.

Also we will select the Data Type as `Single Line Text` from the dropdown.

![New Entity Config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwwjjdazibgcpytgaipc.png)

Amplication provides various Data Type according to your needs an takes care of the constraints on your code as needed according to the data type.

![Types of data types](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0npx5s247djcpl2gq5xk.png)

Now amplication auto saves everything after each change so your selections are already selected

### description Field

Do the same process for description, but for the datatype we will change to `Multi Line Text`.

![Multi Line Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5e1k20suxyiwu93h3wnh.png)

### locationType Field

This field will store the type of location of the listing, whethere it is a house, flat, bunglow, etc.

Do the same process as we followed for the title field.

### placeType Field

This field will store the details like if there is a full room to this place, is this place shared, etc. 

Do the same process as we followed for the title field.

### price Field 

This field will store the price of the listing.

For the datatype we will use the `Whole Number` type.

The minimum and maximum value would be set by default. We do not need to change it.

![price field](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otg6npj1l1ecf7aj8t1g.png)

### mapData Field

This field will store the maps cordinates for the Mapbox to load the specific location with the accurate marker.

For this field we will select the datatype as the `Json` type, because we will have json data inside of it.

![mapdata field](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf2e1bzg867pxk7u1kd6.png)

### locationData Field

This field will store the location Data like the pincode, address, city, etc.

This will be a `Json` data type.

### placeSpace Field

This will store the total rooms and total guests the place can have.

This will be a `Json` data type.
 
### photos Field

This will store the links of the photos for the listings.

This will be a `Json` data type.

### listingCreatedBy field

This field will store the data of the user that created this listing.

This would be relation to the User entiity.

Select the data type as `Relation to entiity`.

In the Relation Entity Dropdown Select the `User` Entity.

And select the `One 'listings' can be related to one 'listingCreatedBy'` option.

This means that one user can create many listings.

![Relation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evc9q94xck2l5mt5lh5n.png)


That's it. With this we have created our listings Entity.

### Setup Wishlists

This entity will store the wishlists of the user.

### user field

This will store which user has added the listing.

The data type will be `Relation to Entity` with the user, with the `One 'wishlists' can be related to one 'user'` option toggled.


![user field](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rs1bhzgdj27tcvykjqk.png)


### listing Field

This will store which listing has added by the user.

The data type will be `Relation to Entity` with the user, with the `One 'wishlists' can be related to one 'listing'` option toggled.

![listing entity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3s0zp1673i332zsi6d0t.png)

That's it for the wishlists entity.

### Setup Trips

This will store the trips that has been booked by the user.

We will follow the same procedure for the trips as we did for the wishlists with the same field names and same relations.


![Trips](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwo96dqkm05334vvram9.png)

And that's all for the Trips entity.

Now we have created all the entities that is required and we can build our app and push the code over to github.

## Build and publish the code to Github

You can see that we have some pending changes in the right sidebar. We need to push these changes to github to integrate it with our app.

![Pending Changes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nb9qidcv5h1cqhx897zv.png)

Click on the `Commit Changes & build` button.

![Commit Changes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hk732c0r9b0nod0szbqu.png)

With this Amplication will start building your code.

![Build Screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ycz2jpi69td91oa9gmc3.png)

As soon as the build would be successfull the code would be pushed over to the Github.

Now head over to your github repository.

Now click on the Pull requests

![Pull Requests](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xxawwavebvhprff36a2.png)

Click on the pending pull request that is generated by the Amplication bot.

![Pull request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipcnuj9mnyd1da3ryfue.png)

Now you will see the request page. You can either check the code or merge the pull request to merge it with the main source code.

![Repoi](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xw3da2ib7fizk5w17knu.png)

Now we have successfully generated the backend code with Amplication.

### Setup Local App

Now we need to setup the app on our local machine.

For that clone the repository or pull your source code from git.

Now to setup the app we need to install the dependencies.

For this there's already a pacakge.json file created in the root of the directory.

You need to run `npm install`.

This will install the root dependencies.

After this you need to run the `npm run postinstall` script to install the frontend, backend and the admin-ui dependencies.

![Package.json file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/akzqz7c138ivjvu0vhhw.png)

After the process is completed your app is successfully setup with the backend code generated with Amplication.

Now for starting the app you can run `npm run start`.

## Amplication REST API's with Swagger

If you want to check the API's generated by Amplication, head over to `http://localhost:3000/api`.

This will open the Swagger UI with all the API's. You can test out API's here.

![API's](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilxcbquq12khrv9wmcrl.png)

But wait there's something more,


## Amplication introduces a groundbreaking feature: Upload Prisma Schema.

If you find yourself in the midst of the development phase and wish to seamlessly transition to Amplication's services, this powerful tool will be a game-changer.

![Prisma Upload Schema](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pgx01fyaebbbw5h9cdf.png)


Imagine having the ability to effortlessly import your Prisma schema into Amplication, enabling the automatic generation of entities and relationships required for your application. This simplifies the migration process, saving you time and effort while ensuring a smooth transition to Amplication's services.

With Amplication's Upload Prisma Schema feature, you can take your development project to the next level, leveraging the platform's robust capabilities to accelerate your app's progress. The integration of your existing Prisma schema will pave the way for a more efficient and productive development experience.

Here's what the process looks like,

![Prisma upload schema process](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g74b8bsmwr2702i78tao.png)

This feature is still in beta mode and would be available to end users shortly.

## Conclusion

This blog post has taken you through the process of creating a Full Stack Airbnb Clone using Amplication, a powerful open-source development tool. With Amplication's low-code development environment, developers can build web applications by configuring and connecting pre-built building blocks, reducing the amount of manual coding required. The post covered the various features and functionalities of the Airbnb Clone, including real-time maps, JWT-based authentication, API calls using Axios, and more.

The step-by-step guide walked you through setting up the project using Amplication, creating entities for listings, wishlists, and trips, and how to push the code to GitHub for integration. Additionally, it demonstrated how to test the REST APIs generated by Amplication using Swagger UI.

By leveraging Amplication's capabilities, developers and organizations can accelerate software development, saving valuable time and resources, and deliver robust and scalable applications. Whether you're a seasoned developer or just starting, Amplication provides a user-friendly platform for building impressive web applications with ease. So, go ahead and unleash the power of Amplication in your next development project! Happy coding!

This tutorial was a part of my Youtube video. Check out the entire video.

{% youtube nkmPmUpUM6U %}