Microservice based backend and Next.js frontend for a micro-blogging platform.
It offers four distinct API services that collectively enable various functionalities:
- Authentication: This service facilitates essential operations such as user
login,logout, andregistration, ensuring secure access to the platform. - Blog: The Blog service provides features for managing blog-related activities. Users can
create,update, anddeletetheir blog posts. Additionally, they have the ability tolikeordislikeposts, promoting user engagement and feedback. - User: This service focuses on user-related interactions. It allows users to
followorunfollowother users, enabling social connections within the platform. Furthermore, users candeletetheir account if desired. - Feed: The Feed service is responsible for curating and displaying relevant content to users. It offers multiple options for customizing the feed, including displaying
all posts, posts fromfollowedauthors,likedposts, posts by a specific user, or aparticular post. - Swagger - You can access the Swagger UI at
localhost:8084/swagger/index.html
Try this API service in postman.
- Each folder of the root directory in the codebase contains an
.env.examplefile. Follow the steps below to set up the necessary environment variables:
- Create a file named .env in each folder.
- Open the
.env.examplefile and copy its contents. - Paste the copied contents into the corresponding
.envfile. - Replace the placeholder values in the .env file with the suggested values provided in the
.env.examplefile.
- To set up the service locally, follow the steps below:
- Clone the repository to your local machine.
- Open a terminal and navigate to the cloned repository.
- Create a network using the command
docker network create my-network - Run the command
docker compose up.
Note: The
docker compose upcommand will automatically set up the database. However, if it fails, please refer to the "DB-Setup" section for further instructions.
Frontend is a Next.js 13.x application bootsrapped by create-next-app
After cloning the project:
- cd ./frontend
- npm i
- cp ./env.local.example ./env.local
- npm run dev
Navigate to http://localhost:3000 to access the frontend of this project.
After running docker compose up, perform the following steps:
- Open a new terminal window.
- Execute the command
docker exec -it db bash. - Run the command
psql -U postgresto access the PostgreSQL command-line interface. - Create a new database by executing the command
CREATE DATABASE blogx_db;. - Connect to the newly created database by executing the command
\c blogx_db. - Open the
init.sqlfile located in the\dbfolder. - Copy the contents of the
init.sqlfile. - Paste the copied contents into the terminal where the PostgreSQL command-line interface is running.
- Press Enter to execute the commands and initialize the database.
By following these steps, you should be able to set up the local environment and initialize the necessary database for the service.
| endpoint | method | success status code |
auth token requirement |
|---|---|---|---|
| / | GET | 200 | NO |
| /register | POST | 201 | NO |
| /login | POST | 200 | NO |
| /logout | POST | 202 | YES |
| endpoint | endpoint | success status code |
auth token requirement |
|---|---|---|---|
| / | GET | 200 | NO |
| /addBlog | POST | 200 | YES |
| /updateBlog | PATCH | 200 | YES |
| /deleteBlog | DELETE | 204 | YES |
| /like?post_id= | GET | 200 | YES |
| /dislike?post_id= | GET | 200 | YES |
| endpoint | method | success status code |
auth token requirement |
|---|---|---|---|
| / | GET | 200 | NO |
| /allPosts | GET | 200 | YES |
| /allPostsPageWise?page_no= | GET | 200 | YES |
| /postWithId?post_id= | GET | 200 | YES |
| /postWithUserId?user_id= | GET | 200 | YES |
| /myPosts | GET | 200 | YES |
| /followingUsersPosts | GET | 200 | YES |
| /myLikedPosts | GET | 200 | YES |
| endpoint | method | success status code |
auth token requirement |
|---|---|---|---|
| / | GET | 200 | NO |
| /delete | DELETE | 204 | YES |
| /follow?toFollowId= | POST | 200 | YES |
| /unfollow?toUnfollowId= | POST | 200 | YES |
As this is the first version of this backend, each service endpoint is preceded by
/v1/api
Database used - PostgreSQL
| Table name | Description |
|---|---|
| users | Stores the details of users. The password is not stored directly; it is hashed for security purposes. |
| posts | Stores the blog posts created by users. |
| user_followers | Represents the relationship between users, where the follower_id follows the following_id. |
| user_likes | Records the likes given by users (user_id) to specific posts (post_id). |
- Go
- Next.js (Type-script)
- PostgreSQL
- Redis
- Docker and Docker-compose
- HAProxy (load-balancer)
- SwaggerUI
