CRUD Blog in Angular 15 and NestJs with MongoDB and Google Authentication. It has factory method design pattern and unit tests coverage over 95%.
Follow the steps to run both the applications on local:
cd myblog-api
- Install modules
npm install
- Setup the
.env
file with the reference of this example.env file - Run NestJs dev command
npm run start:dev
cd myblog-ui
- Install modules
npm install
- Run angular serve command
ng s
- Open http://localhost:4200 in browser
Login Page
Login with Google Account
Dashboard Page
New Blog Post
Blog Detail page. Its a public page.
I have built an UI Application in Angular, Backend Service in NestJs, Api Performance Load Tester Script in Python with the help of Locust and finally a Bulk Dummy Data Generator script in Node.Js.
Let's start with discussing each of the applications with their features.
A Front End application that will be visible to users is built in Angular using RxJS Observables and Operators. It has features like:
- Login through Google Account
- A dashboard page to list all the blogs that user will create
- A create blog page where user can enter Blog Title, Body, Category and some Tags and hit save
- A blog detail page that opens when user clicks on a blog title from at the dashboard page
- Logout
There are some additional features that I have impplemented in the UI:
Infinite Scroll is implemented on the dashboard page for blog listings to get paginated records. It gets recent created blogs first and scrolls through the list. As soon as user reaches to the end of page, application hits get all blogs endpoint with next page number.
A Backend service created in NestJs with MongoDB database. There are several features implemented in this service:
- Authenticate user through Google account
- Generates an application specific JWT Access token once the Google auth is successful and the same access token is returned to the front end application
- NestJs Passport and JWT libraries are used to Authenticate the user
- NestJs decorator is used to check the Bearer Access Token present in request headers
- Get all blogs created by the user
- Create a blog
- Get a sigle blog by slug
Some additional features are implemented like:
- I have used Factory Method design pattern
- Unit Test Cases are written for each of the repositories, services, and helper methods with coverage over 95% (attached screenshot for reference)
- E2E Test cases are written to check Get Blogs, Get Single Blog and Create Blog Apis are performing as expected
- Environment config is setup to access configuratiob based values
I have written unit test cases to covers 95% of the backend codes.
I have setup Locust performance load tester script in Python.
Steps to run the Locust script:
- Install Python
- Install Locust using command
pip3 install locust
- Run Locust command
locust
. It will run the script and you can open the url in browser to configure the host and requests per second value. - More details on setup.
Check the url here that shows a detailed report about the performance load tested locally.
I have created a bulk data generator script in Node.Js. It has features like:
- Calls the endpoint to insert blogs one by one on an interval of 20ms. It can insert almost 100k records in 3-5 mins
- A bulk data generator script that directly inserts data into mongodb database
- Automatically generates random article title, body, category and tags to insert
- Install modules
npm install
- Run
node app.js
to insert data by calling api one by one. It can insert upto 100k records in 3-5 mins - Run
node bulk-generator.js
to insert data in bulk. It can insert upto 300k records in just 30-50 seconds
I have generated 1.1 million records in my local MongoDB database. Each document has 100-200kb size of data. The api performs good on load tester with upto 600 requests per second.
The DB size is more than 4 GB but still it works good due to indexes I have used. Here is the time taken by a query to search for a slug in 1.1 Million records
I have setup Dockerfile in both applications ui and backend to deploy it to cloud.
- Go to UI App
- Build the docker image
- Go to Backend App
- Build the docker image
- Run Docker compose
docker compose up
that will install the required softwares