- What is This Project About ?
- Major Tech Stack Used
- Design & Architecture
- Dashboards & links
- CI & Deployment Pipeline
- API documentation
- Payment Flow
- Building & Testing
- Todos and Roadmap
I started this project a recently in my spare time (however much remains after the day job 😆 ), just as an exercise mostly to reinforce some of the things I had picked up along the way and also to help a friend who was learning React to have a more or less functionally complete mini backend service , so that we both could practice building some non trivial front end applications around it. Along the way , I just kept on adding small additional changes, layer after layer.
It's still very much a work in progress and some of the earlier data modelling was not very carefully thought out, only to come around and bite me later, which made me add a lot of contrived logic which could have easily been avoided . The goal was never to have a serious project, but more of a curiosity project
which was more or less feature complete monolith application
which can stand on its own in real world usage.
To this end, I believe with some modification into it's models and the associated changes, it can be used as a stand-alone SAAS platform for people learning front end applications to make their own mini AIRBNB setup
with no hassle to set up the backend.
Express on Node 12 for Application server
PostgreSQL as primary data store with Sequelize as the ORM
Github Actions & Digital Ocean for CI & Deployments
-
Queues -> located at http://139.59.71.89/admin/queues
-
Redis -> located at http://139.59.71.89:8081/
-
UI for tinkering with Razorpay Payment Integration -> located at http://139.59.71.89/api/v1/payment/test-razorpay
-
API documentation & testing -> located at http://139.59.71.89/api-docs
The CI Pipeline is a fairly rudimentary one and consists of the following Github Action workflow which is triggered to run on every commit to 'main' branch.
All it does is directly ssh into the DO droplet and shuts down the running containers, cleans up the dangling images, pulls in the latest source code and rebuilds from the docker-compose file, most of the other service images are precached anyways and are not rebuilt everytime.
name: CI | Deploy to DO Droplet
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- name: login, shutdown container, pull latest master and trigger fresh build
uses: appleboy/ssh-action@master
with:
host: ${{secrets.DO_HOST}}
username: ${{secrets.DO_USERNAME}}
password: ${{secrets.DO_PASSWORD}}
script: |
cd createYourBread-N-Breakfast
#set all the env variables here
set -o allexport; source ~/.env; set +o allexport
#shut down all the containers:
docker-compose down
# remove all the dangling containers
docker rmi $(docker images -f dangling=true -q)
git checkout main
git pull
#rebuild from the existing app as and when required
docker-compose up --build -d
The repo contains the postman collection which can be used to test locally and the remote APIs.
The swagger API documentation can be found at
or at
http://localhost:{PORT}/api-docs/ ( if running locally)
We've integrated Razorpay Payment Gateway and the payment flow has been designed with that in mind, it's not a gateway agnostic design as of now
Razorpay Payment cycle consists of 3 major steps :
- order creation
- checkout creation ( triggers payment capture behind the scenes )
- payment verification
- UI we've built for tinkering with Razorpay Payment Integration -> located at http://139.59.71.89/api/v1/payment/test-razorpay
The static Page explains everything in great detail
We have Listings
, which we want to book
by payment
.
To Book a Listing
- We
create
abooking
, if the booking is successfull, we get back abookingId
- We
create
aPayment Order
for the payment with thebookingId
passed in thepayload
asreceipt
||receiptId
Checkout
is a stage which happens predominantly through the UI, once the checkout is complete, we can either pass- a>
callback url
, which is automatically redirected to on payment completion - b>
capture return values
, which can be used to verify the payment as we've used in the static page
- a>
Post Checkout
, the standart recommended way to verify payments in prod is by registeringwebhooks
which we've done and we've added a status api which can be used to check if a payment has been successfull.
To cancel a Booking
- We
cancel
abooking
, we receive agatewayPaymentId
in the response payload, - We create a
Payment Refund
for thegatewayPaymentId
, that's all.
The heavy lifting is done behind the scenes by the webhook processors, we've written.
If we're building and testing it locally, with/without docker, we'd have to set up all the associated services mentioned above and also, sign up with services such as `nodemailer`, `razorpay`, `aws s3` (for image upload).
-
Create an
.env
file in theroot directory
by copying over.env-sample
file from the repo and fill up theappropriate credentials
. -
Please refer to
.env-sample
file from the repo for the commplete reference
touch .env
#copy the relevant info from .env-sample
nvm use v12.20.1
npm install
# make sure, you have postgres set up, redis set up, or their flags sets up to disable their invocation
npm run start
# set up the environment variables, many ways to set up the env variables
printenv
#to verify the env variables have been set
#check into the root dir
docker-compose up -d
# to restart post some changes
docker-compose down
docker-compose up --build -d
# check the logs of the services to see if they've successfully started or if there's any issues
docker logs `serviceName` -f
- Add JOI/validation to all the routes
- Add transactions and appropriate isolation levels to all necessary db queries
- Add Naive Caching to the appropriate API responses
- Appropriate HTML templates for Emails
- conversion of a normal user to a host be more informative and step wise with each step being locked in and verified by an admin backend(to be built)
- Currently the Redis/commander and Queue UI are unsecured, Add a singular Admin Authentication on those routes
- Purchase a domain
- Set up
Certbot
on prod & get SSL certificate - Update the models to include more common user attributes like mobileNo etc as well as to convert all the data model to be more centralised tenant specific,
- Write Mocks for all the APIs
- convert the entire project to TypeScript
- Please feel free to create an Issue
- shoot a mail at aquib.jansher@gmail.com