This is a Spring Boot-based social media platform application with user authentication and management features. The project is structured to follow best practices for security and maintainability.
- Java 17 or higher
- Docker (for containerization)
- Maven
-
Clone the repository:
git clone git@github.com:bk-kaizen/social-media-platform.git cd social-media-platform -
Build the project with Maven:
./mvnw clean install
The docker-compose.yml file is used to set up the necessary services like Postgresql and redis for running the application.
To start the services:
docker-compose up -dOption -d added for detached mode.
Using Maven:
./mvnw spring-boot:runAfter the application has started, you can verify its status using the following endpoint: Health Status: http://localhost:8080/actuator/health
Access the API documentation using this endpoint: Swagger API Documentation: http://localhost:8080/api/swagger
The application uses a properties file located at src/main/resources/application.properties. Adjust the configuration
as needed for your environment.
The application uses JWT for authentication and authorization. The security configuration is managed
in SecurityConfiguration.java.
JWT (JSON Web Token) is used for securing the APIs. The authentication process involves the following steps:
- User Registration: Register a new user to obtain credentials.
- User Login: Authenticate with the credentials to receive a JWT token.
- Accessing APIs: Use the JWT token to access protected APIs.
Register a User:
POST /api/auth/register
Request Body:
{
"firstname": "john",
"lastname": "doe",
"email": "john@gmail.com",
"password": "12345678"
}Login to get JWT Token:
POST /api/auth/login
Request Body:
{
"username": "user",
"password": "password"
}The response will contain a JWT token:
{
"token": "your-jwt-token"
}Retrieve User Profile:
GET /api/users/:userid
The response will contain a User profile details:
{
"email": "john@gmail.com",
"firstName": "john",
"lastName": "doe"
}Access Protected APIs:
Use the JWT token in the Authorization header as a Bearer token:
Authorization: Bearer your-jwt-tokenThe Post Management APIs allow you to create, retrieve, update, and delete posts. The APIs are protected by JWT authentication.
Create a Post:
POST /api/posts
Authorization: Bearer your-jwt-token
Content-Type: application/jsonRequest Body:
{
"content": "This is a new post",
"userId": "user-uuid"
}Response Body
{
"id": 6,
"content": "This is a post",
"userId": "5e40bc30-82e4-43dd-b50c-5eef0e9fe9d4"
}Retrieve Posts:
GET /api/posts
Authorization: Bearer your-jwt-tokenResponse Body
{
"totalElements": 5,
"totalPages": 1,
"size": 8,
"content": [
{
"id": 6,
"content": "This is a post",
"userId": "5e40bc30-82e4-43dd-b50c-5eef0e9fe9d4"
},
{
"id": 5,
"content": "This is a post",
"userId": "5e40bc30-82e4-43dd-a50c-5eef0e9fe9d4"
}
],
"number": 0,
"sort": {
"empty": false,
"sorted": true,
"unsorted": false
},
"pageable": {
"pageNumber": 0,
"pageSize": 8,
"sort": {
"empty": false,
"sorted": true,
"unsorted": false
},
"offset": 0,
"paged": true,
"unpaged": false
},
"first": true,
"last": true,
"numberOfElements": 5,
"empty": false
}Retrieve a Post by ID:
GET /api/posts/{postId}
Authorization: Bearer your-jwt-tokenResponse Body
{
"id": 6,
"content": "This is a post",
"userId": "5e40bc30-82e4-43dd-b50c-5eef0e9fe9d4"
}
Update a Post:
PUT /api/posts/{postId}
Authorization: Bearer your-jwt-token
Content-Type: application/jsonRequest Body:
{
"content": "Updated post content",
"userId": "user-uuid"
}Response Body
{
"id": 6,
"content": "This is a updated post",
"userId": "5e40bc30-82e4-43dd-b50c-5eef0e9fe9d4"
}
Delete a Post:
DELETE /api/posts/{postId}
Authorization: Bearer your-jwt-tokenResponse Says 200 OK.
For detailed API documentation and example requests, refer to the Postman collection located in the docs directory.
The application integrates Redis caching to improve response times for frequently accessed endpoints. Caching is applied to the retrieval of post.
- Implemented custom JWT flow authentication using
jjwt-apidependencies. - Simplified post management by excluding image or media content.
- Added API documentation in the Controller using
springdoc-openapi-starter-webmvc-ui.