Skip to content

Imagine a SAAS project which allows you to build your own relatively non-trivial first FrontEnd application, something along the lines of a very famous product which allows you to host other people in your space πŸ˜†

License

Notifications You must be signed in to change notification settings

aquib-J/createYourBread-N-Breakfast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

createYourBreadAndBreakfast (cybnb)

CI | Deploy to DO Droplet

What is this project about?

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.

Tech stack and services used

  • Express on Node 12 for Application server

  • PostgreSQL as primary data store with Sequelize as the ORM

  • Redis for session caching and also as a QUEUE

  • NGINX as a reverse proxy and also for load balancing

  • AWS S3 for Image storage

  • Docker & Docker Compose for Containerization and simple service orchestration

  • Github Actions & Digital Ocean for CI & Deployments

  • Razorpay for Payment Integration

  • Bull for Queue management

  • bull-board as an UI for the Queues

  • Nodemailer for Emails

  • Redis Commander as an UI for the Redis clusters

  • Swagger for API documentation

Design and Architecture


Dashboards

The project comes with Dashboards/UI for

CI and Deployment Pipeline

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

API documentation

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

http://139.59.71.89/api-docs/

or at

http://localhost:{PORT}/api-docs/ ( if running locally)

Payment Flow

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


We have Listings, which we want to book by payment.

To Book a Listing

  • We create a booking, if the booking is successfull, we get back a bookingId
  • We create a Payment Order for the payment with the bookingId passed in the payload as receipt || 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
  • Post Checkout, the standart recommended way to verify payments in prod is by registering webhooks 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 a booking, we receive a gatewayPaymentId in the response payload,
  • We create a Payment Refund for the gatewayPaymentId, that's all.

The heavy lifting is done behind the scenes by the webhook processors, we've written.

Building and Testing

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 the root directory by copying over .env-sample file from the repo and fill up the appropriate credentials.

  • Please refer to .env-sample file from the repo for the commplete reference

  • Directly using npm script and a local .env file

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
  • Using docker-compose

# 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

TODOs :

List of Items to do, to convert it to a standalone generic SAAS like platform

Roadmap

  • 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,

TODO besides Roadmap

  • Write Mocks for all the APIs
  • convert the entire project to TypeScript

For feature request & contributions/corrections

About

Imagine a SAAS project which allows you to build your own relatively non-trivial first FrontEnd application, something along the lines of a very famous product which allows you to host other people in your space πŸ˜†

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published