# pallava/spring-boot-with-microservice architecture

> Architecture diagram of the GitHub repository pallava/spring-boot-with-microservice, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pallava/spring-boot-with-microservice
- Repository: https://github.com/pallava/spring-boot-with-microservice

## Overview

##### Project Type and Purpose
- This repository is a “Spring-boot-with-microservice” demo showcasing a set of backend microservices built on Spring Cloud.
- Key modules:
- cloud-config – a centralized configuration server
- application-service-registry – a Eureka service registry
- api-gateway – a Zuul/Spring Cloud Gateway entry point with routing and fallback
- department – a simple Department microservice (REST + JPA)
- user-service – a User microservice that uses Feign to call Department

##### File Structure
- Top-level folders correspond to each microservice. Each follows the standard Maven layout: src/main/java, src/main/resources, Dockerfile, pom.xml.
- Presence of bootstrap.yml and application.yml in each service indicates Spring Cloud configuration.
- api-gateway contains a CustomFilter and FallBackController, pointing to a gateway pattern with circuit-breaker fallback.
- user-service has a feignclients package and DTO for Department—showing inter-service communication.

##### README for Insights
- Very brief (“Simple demo with Spring boot and Microservice”).

##### Main Components & Their Roles
a. Client (e.g., Postman or UI)
– Initiates all HTTP requests.
b. API Gateway
– Single entry point. Routes incoming calls to the appropriate microservice.
– Implements filters (authentication, logging) and circuit-breaker fallbacks.
c. Service Registry (Eureka)
– Keeps track of service instances and their health.
– Gateway and microservices register themselves here.
d. Config Server
– Serves centralized configuration to all microservices at startup.
e. Microservices
– department: CRUD REST API backed by a relational database (via Spring Data JPA).
– user-service: User REST API that, when requested, calls department service via Feign load-balanced client.
f. Databases (one per microservice)
– department-db and user-db (could be separate instances or schemas).

##### Relationships & Data Flows
1. Client → API Gateway: all requests go through gateway.
2. API Gateway → Eureka: on startup, gateway queries Eureka for route mappings.
3. API Gateway → Config Server: gateway fetches its config.
4. API Gateway → department / user-service: routes based on path (/department/**, /user/**).
5. user-service → Eureka: registers itself; Eureka returns department instances for Feign.
6. user-service → Config Server: fetches config.
7. user-service → department-service: inter-service call via Feign + Ribbon for load balancing.
8. Each service → its own Database: reads/writes entities.

##### Architectural Patterns & Principles
- Microservices: each service is independently deployable, with its own codebase and data store.
- Service Discovery: Eureka-based registration and lookup.
- API Gateway: single entry point, encapsulating cross-cutting concerns (security, rate-limiting, circuit breakers).
- Externalized Configuration: Spring Cloud Config for dynamic, centralized configuration.
- Client-side Load Balancing: Netflix Ribbon (used implicitly by Feign).
- Circuit Breaker / Fallback: Hystrix-style fallback implemented in API gateway.

##### Technologies & Frameworks
- Spring Boot, Spring Cloud (Config, Netflix Eureka, Netflix Zuul/Gateway, Netflix Feign, Ribbon, Hystrix)
- Maven for build
- Dockerfiles for containerization
- Spring Data JPA (for persistence)

##### Step-by-Step Creation
4. “Eureka Service Registry” in the center/top; connect Gateway and services bi-directionally.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (Postman/UI)"]:::client

    %% API Gateway
    subgraph "API Gateway"   
        direction TB
        GatewayApp["ApiGatewayApplication"]:::gateway
        CustomFilter["CustomFilter"]:::gateway
        FallbackController["FallBackController"]:::gateway
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        ConfigServer["Config Server"]:::config
        Eureka["Eureka Service Registry"]:::registry
    end

    %% Department Microservice
    subgraph "Department Service"
        direction TB
        DeptApp["DepartmentApplication"]:::dept
        DeptController["DepartmentController"]:::dept
        DeptService["DepartmentService"]:::dept
        DeptRepo["DepartmentRepository"]:::dept
        DeptEntity["Department Entity"]:::dept
        DeptDB["Department DB"]:::db
    end

    %% User Microservice
    subgraph "User Service"
        direction TB
        UserApp["UserServiceApplication"]:::user
        UserController["UserController"]:::user
        UserDTO["Department DTO"]:::user
        FeignConfig["DepServiceLoadBalConfig"]:::user
        FeignClient["DepartmentFeignClient"]:::user
        CommonService["CommonService"]:::user
        BusinessService["Userservice"]:::user
        UserRepo["UserRepository"]:::user
        UserEntity["User Entity"]:::user
        UserDB["User DB"]:::db
    end

    %% Flows
    Client -->|HTTP/REST| GatewayApp
    GatewayApp -->|"routes via Eureka"| DeptApp
    GatewayApp -->|"routes via Eureka"| UserApp
    GatewayApp -->|fallback| FallbackController

    DeptApp -->|JPA| DeptDB
    UserApp -->|JPA| UserDB

    UserApp -->|"Feign+Ribbon"| DeptApp

    %% Service Discovery
    GatewayApp ---|Eureka REST API| Eureka
    DeptApp ---|register/discovery| Eureka
    UserApp ---|register/discovery| Eureka

    %% Config flows
    GatewayApp -.->|ConfigClient| ConfigServer
    DeptApp -.->|ConfigClient| ConfigServer
    UserApp -.->|ConfigClient| ConfigServer

    %% DB style
    class DeptDB,UserDB db

    %% Click Events for component mapping
    click ConfigServer "https://github.com/pallava/spring-boot-with-microservice/blob/main/cloud-config/src/main/java/com/springboot/cloudconfig/CloudConfigApplication.java"
    click Eureka "https://github.com/pallava/spring-boot-with-microservice/blob/main/application-service-registry/src/main/java/com/example/demo/ApplicationServiceRegistryApplication.java"
    click GatewayApp "https://github.com/pallava/spring-boot-with-microservice/blob/main/api-gateway/src/main/java/com/springboot/demo/apigateway/ApiGatewayApplication.java"
    click CustomFilter "https://github.com/pallava/spring-boot-with-microservice/blob/main/api-gateway/src/main/java/com/springboot/demo/apigateway/CustomFilter.java"
    click FallbackController "https://github.com/pallava/spring-boot-with-microservice/blob/main/api-gateway/src/main/java/com/springboot/demo/apigateway/FallBackController.java"
    click DeptApp "https://github.com/pallava/spring-boot-with-microservice/blob/main/department/src/main/java/com/department/department/DepartmentApplication.java"
    click DeptController "https://github.com/pallava/spring-boot-with-microservice/blob/main/department/src/main/java/com/department/department/controller/DepartmentController.java"
    click DeptEntity "https://github.com/pallava/spring-boot-with-microservice/blob/main/department/src/main/java/com/department/department/entity/Department.java"
    click DeptRepo "https://github.com/pallava/spring-boot-with-microservice/blob/main/department/src/main/java/com/department/department/repository/DepartmentRepository.java"
    click DeptService "https://github.com/pallava/spring-boot-with-microservice/blob/main/department/src/main/java/com/department/department/services/DepartmentService.java"
    click UserApp "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/UserServiceApplication.java"
    click UserController "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/controller/UserController.java"
    click UserDTO "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/dto/Department.java"
    click FeignConfig "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/feignclients/DepServiceLoadBalConfig.java"
    click FeignClient "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/feignclients/DepartmentFeignClient.java"
    click UserEntity "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/entity/User.java"
    click UserRepo "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/repository/UserRepository.java"
    click CommonService "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/services/CommonService.java"
    click BusinessService "https://github.com/pallava/spring-boot-with-microservice/blob/main/user-service/src/main/java/com/springboot/demo/userservice/services/Userservice.java"

    %% Styles
    classDef client fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef gateway fill:#cfa1ff,stroke:#663399,stroke-width:1px
    classDef registry fill:#ffd699,stroke:#cc8400,stroke-width:1px
    classDef config fill:#99ccff,stroke:#336699,stroke-width:1px
    classDef dept fill:#ccffcc,stroke:#339933,stroke-width:1px
    classDef user fill:#99ffcc,stroke:#009966,stroke-width:1px
    classDef db fill:#dddddd,stroke:#999999,stroke-width:1px,shape:cylinder
```
