a full-stack clone of airbnb. i built it solo as a react/redux front end on top of an express and sequelize back end with postgres underneath. the goal was to get as close to the real site as i could so i pulled in the airbnb cereal font family and spent a lot of time matching spacing and the way the listing cards sit next to the map.

the data model is seven tables. users, places, bookings, reviews, images, favourites and applications. places are full crud for anyone with a host account, and every place has a set of images, a rating from its reviews, and a latitude and longitude. the back end is a plain rest api under /api with one router per table, plus a search route that the search bar hits.
auth is a jwt in an http-only cookie. every protected route goes through a two-step middleware array. the first step reads the token off the cookie and attaches the user to the request, the second step rejects the request if nothing got attached. a bad or expired token clears the cookie instead of throwing.
const restoreUser = (req, res, next) => {
const { token } = req.cookies;
return jwt.verify(token, secret, null, async (err, jwtPayload) => {
if (err) return next();
try {
const { id } = jwtPayload.data;
req.user = await User.scope("currentUser").findByPk(id);
} catch (e) {
res.clearCookie("token");
return next();
}
if (!req.user) res.clearCookie("token");
return next();
});
};
const requireAuth = [
restoreUser,
function (req, res, next) {
if (req.user) return next();
const err = new Error("Unauthorized");
err.status = 401;
return next(err);
},
];bookings are a date range on a place. a place can't be booked on days it already has a booking, so the calendar on a listing greys out the days that are taken before you can pick them.

hosting is gated behind an application. a normal user applies to become a host, and admins get a panel where they can approve or reject applications. approving is a single put on the applicant's id. the user's account type is flipped to host and the application row is deleted in the same handler, so there is never an approved application sitting in the table.
router.put(
"/:userId",
asyncHandler(async (req, res) => {
const { id } = req.body;
const applicant = await User.findByPk(req.params.userId);
await applicant.update({ accountType: 2 });
await Application.destroy({ where: { id } });
res.json({ applicant });
})
);favourites are a many-to-many between users and places so you can keep a list of homes you liked and come back to them. removing one is a delete keyed on both ids rather than the row id, which saves the client from having to know the favourite's primary key.

search is a case-insensitive ilike on the place name with the owner joined in which is all the real search bar needed for this scale of data.
router.get(
"/:term",
asyncHandler(async (req, res) => {
const searchResults = await Place.findAll({
where: { name: { [Op.iLike]: `%${req.params.term}%` } },
include: User,
});
return res.json({ searchResults });
})
);the map on the right uses google maps. every place in the current result set gets a marker from its coordinates and clicking a marker expands it into a small card with the listing's info. the map and the list share the same state so filtering one filters the other.
