Skip to content

abhijeetnishal/Microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices Architecture with Spring Boot

Overview

This project is a microservices-based application built using Spring Boot. It currently includes a User Service, with the potential to add more services like Post Service and others in the future. Each service is designed to be independent, scalable, and maintainable, and communicates with others using REST APIs. We are using MySQL as the database for our services.

Technologies and Frameworks Used

The project leverages several modern technologies and frameworks to ensure robustness, security, and ease of development:

  • Java 21: Stable version of Java.
  • MySQL: Database for storing user information.
  • Maven: Build automation tool.
  • Sentry: For application monitoring and error tracking.
  • Spring Boot 3.3.0: Framework for building Java-based applications.
    • Spring Boot Starter Data JPA: For database access using JPA.
    • Spring Boot Starter Data Redis: For integrating with Redis.
    • Spring Boot Starter Mail: For email functionalities.
    • Spring Boot Starter OAuth2 Client: For OAuth2 authentication and authorization.
    • Spring Boot Starter Security: For securing the application.
    • Spring Boot Starter Validation: For input validation.
    • Spring Boot Starter Web: For building web, including RESTful, applications.
    • Spring Boot DevTools: For developer productivity.
  • JUnit & Spring Security Test: For unit and integration testing.
  • Lombok: To reduce boilerplate code.

Features

  • User Management: Create, update, delete, and retrieve user information.
  • Authentication & Authorization: Secure endpoints using Spring Security and OAuth2.
  • Email Notifications: Send emails for various user actions (e.g., registration, login, etc).
  • Validation: Robust input validation using Spring Validation.
  • Monitoring: Application monitoring and error tracking with Sentry.

Architecture

The microservices architecture follows a modular approach where each service is independently deployable and scalable. The Users service communicates with other potential services (like Post, Comments, etc.) through RESTful APIs. Key components include:

  • Controllers: Handle incoming HTTP requests and delegate to the service layer.
  • Services: Contain business logic and interact with repositories.
  • Repositories: Interact with the database using Spring Data JPA.
  • Entities: Represent the data model for the application.
  • Configuration: Externalized configuration settings for different environments.
  • Utilities: Helper classes and methods to support common operations.
  • Security: Configured to handle authentication and authorization.

Configuration

  • Got to src/main/resources/application.properties file and add required credentials to setup the application.

API Endpoints for Users Service

Create User

View Details

Request

  • Method: POST
  • URL: api/v1/users
  • Headers: Content-Type: application/json
  • Body:
    {
      "name": "John Doe",
      "email": "[email protected]"
    }

Response

  • Status Code: 201 Created

  • Body:

    {
      "id": 1,
      "name": "John Doe",
      "email": "[email protected]"
    }

Get User by ID

View Details

Request

  • Method: GET
  • URL: api/v1/users/{id}
  • Path Variable: id

Response

  • Status Code: 200 ok

  • Body:

    {
      "id": 1,
      "userName": "John Doe",
      "email": "[email protected]"
    }

Update User by ID

View Details

Request

  • Method: PUT

  • URL: api/v1/users/{id}

  • Path Variable: id

  • Headers: Content-Type: application/json

  • Body:

    {
      "id": 1,
      "userName": "John Doe",
      "email": "[email protected]"
    }

Response

  • Status Code: 200 ok

  • Body:

    {
      "id": 1,
      "userName": "John Doe",
      "email": "[email protected]"
    }

Delete User by ID

View Details

Request

  • Method: DELETE
  • URL: api/v1/users/{id}
  • Path Variable: id

Response

  • Status Code: 200 ok

API Endpoints for Auth Service

OAuth2 Sign-In

View Details

Request

  • Method: GET
  • URL: /v1/auth/oauth2
  • Headers: Content-Type: application/json
  • Query Parameters:
    • type: The type of OAuth2 provider (e.g., google, github)
    • code: The authorization code from the OAuth2 provider

Response

  • Status Code: 200 OK
  • Body:
    {
      "status": "success",
      "message": "User created",
      "data": {
        "id": 1,
        "userName": "john.doe",
        "firstName": "John",
        "lastName": "Doe",
        "email": "[email protected]",
        "profileImage": "http://example.com/profile.jpg"
      }
    }

Email Signup

View Details

Request

  • Method: GET
  • URL: /v1/auth/signup/email
  • Headers: Content-Type: application/json
  • Body:
    {
      "email": "[email protected]"
    }

Response

  • Status Code: 200 OK
  • Body:
    {
      "message": "Verification code sent",
      "data": null
    }

Verify Email

View Details

Request

  • Method: POST
  • URL: /v1/auth/signup/verify
  • Headers: Content-Type: application/json
  • Query Parameters:
    • code: The authorization code from the OAuth2 provider
  • Body:
    {
      "email": "[email protected]"
    }

Response

  • Status Code: 200 OK
  • Body:
    {
      "status": "success",
      "message": "Verification successful",
      "data": {
        "id": 1,
        "userName": "john.doe"
      }
    }

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages