Spring E-commerce Project is a simple microservice project with spring cloud and various other technologies
- Architecture Diagram
- Events Diagram
- Infrastructure Services
- Application Services
- Development
- Testing
- Java 22 spring boot 3.3
- Spring cloud eureka server
- Java 22 spring boot 3.3
- Spring cloud config server
- Encrypt a value using config server
curl <CONFIG_SERVICE_URL>/encrypt -s -d <VALUE>
- Encrypt a value using config server
- Spring actuator
- Refresh variables
curl -X POST <APPLICATION_SERVICE_URL>/actuator/refresh
- Refresh variables
- Java 22 spring boot 3.3
- Spring cloud gateway
- Spring cache
- Caffeine
- Central swagger for services through gateway
<GATEWAY_SERVICE_URL>/swagger
- Eureka dashboard through gateway
<GATEWAY_SERVICE_URL>/eureka-dashboard
- Graphiql ui through gateway
<GATEWAY_SERVICE_URL>/graphiql?path=/aggregator/graphql
- Jwt filter for authentication
- Manges products.
- Java 22 spring boot 3.3
- Spring web
- Classical controllers
- Relational db
- MySql
- Flyway migrations
- Specification pattern
- Spring cache
- Redis
- In memory cache as fallback
- Event sourcing
- Kafka
- Retry and dlt topics
- Circuit breaker pattern
- Resilience4j
- Structured logging
- Logback
- Elk stack
- Authentication
- Keycloak
- Helpers
- Feign client
- Tests
- Unit tests
- Without starting spring container
- Integration tests
- H2 db
- Embedded kafka
- Coverage
- Jacoco
mvn clean verify
,mvn jacoco:report
- Jacoco
- Unit tests
- Manages user payments.
- Java 22 spring boot 3.3
- Spring webflux
- Handlers
- Functional api
- No-sql db
- Mongodb
- Event sourcing
- Kafka
- Retry and dlt topics
- Circuit breaker pattern
- Resilience4j
- Structured logging
- Logback
- Elk stack
- Authentication
- Keycloak
- Tests
- Unit tests
- Without starting spring container
- Integration tests
- Test containers mongo
- Embedded kafka
- Coverage
- Jacoco
mvn clean verify
,mvn jacoco:report
- Jacoco
- Unit tests
- Saves event sourced resources to elasticsearch, exposes endpoints for fuzzy search for saved resources.
- Java 22 spring boot 3.3
- Kotlin 2.0.0
- Kotlin for pojo classes
- Spring web
- Classical controllers
- No-sql db
- Elasticsearch
- Event sourcing
- Kafka
- Retry and dlt topics
- Circuit breaker pattern
- Resilience4j
- Structured logging
- Logback
- Elk stack
- Authentication
- Keycloak
- Helpers
- Feign client
- Tests
- Unit tests
- Without starting spring container
- Integration tests
- Test containers elasticsearch
- Coverage
- Jacoco
mvn clean verify
,mvn jacoco:report
- Jacoco
- Unit tests
- Aggregates resources from other services, caches responses per user, exposes them as graphql.
- Java 22 spring boot 3.3
- Spring graphql
- GraphQL query mappers
- Spring cache
- Hazelcast
- Eureka discovery for cluster
- In memory cache as fallback
- Hazelcast
- Event sourcing
- Kafka
- Retry and dlt topics
- Circuit breaker pattern
- Resilience4j
- Structured logging
- Logback
- Elk stack
- Authentication
- Keycloak
- Helpers
- Feign client
- Tests
- Unit tests
- Without starting spring container
- Integration tests
- Coverage
- Jacoco
mvn clean verify
,mvn jacoco:report
- Jacoco
- Unit tests
mvn spring-boot:run
You need to run many infrastructure services before starting the actual applications, to have a better dev experience I suggest running infrastructure related applications on a cloud vps.
- Preliminary steps
- Have
Java >22
,Maven >3
andKotlin >2
on your path - Move to project's root folder
- Commands are adjusted for project's root
- Have
- Run infrastructure in docker
- Check Infrastructure Setup for more details
- Create internal network
docker network create sep-bridge-network
- Run containers
docker compose -f sep-infra/docker-compose-mysql.yaml up -d
docker compose -f sep-infra/docker-compose-mongo.yaml up -d
docker compose -f sep-infra/docker-compose-kafka.yaml up -d
docker compose -f sep-infra/docker-compose-keycloak.yaml up -d
- (Optional)
docker compose -f sep-infra/docker-compose-redis.yaml up -d
- (Optional)
docker compose -f sep-infra/docker-compose-elk.yaml up -d
- Populate config files under
/sep-config
- Global config
<KEYCLOAK-REALM-PUBLIC-KEY> <KEYCLOAK-HOST> <REDIS-HOST> (Optional) <KAFKA-HOST> <LOGSTASH-HOST> (Optional) <ELASTIC-HOST>
- Product service
<MYSQL-HOST> <MYSQL-PASSWORD> <KEYCLOAK-CLIENT-SECRET>
- Payment service
<MONGO-HOST> <MONGO-PASSWORD> <KEYCLOAK-CLIENT-SECRET>
- Search service
<KEYCLOAK-CLIENT-SECRET>
- Aggregator service
<KEYCLOAK-CLIENT-SECRET>
- Init a local git repo for config files under
/sep-config
- Config service uses git repo for dynamic config values
git -C sep-config init
git -C sep-config add .
git -C sep-config commit -m "init"
- Global config
- Run Spring cloud services
mvn -f sep-discovery-service/pom.xml spring-boot:run
mvn -f sep-config-service/pom.xml spring-boot:run
mvn -f sep-gateway-service/pom.xml spring-boot:run
(optional)- You can use gateway to access all services from a single place
- eureka-dashboard from gateway http://localhost:8093/eureka-dashboard
- Swagger ui for all services from gateway http://localhost:8093/swagger
- Graphiql ui for aggregator service from gateway http://localhost:8093/graphiql?path=/aggregator/graphql
- Run application services for development with your ide
- Authentication while developing
- Get token from Keycloak with any service name and secret key.
curl -X POST https://<KEYCLOAK_SERVER>/realms/sep/protocol/openid-connect/token -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=<SERVICE-NAME>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials"
- Swagger-ui's has
Authorize
section for the jwt - GraphiQL has headers section, add authorization header with jwt
{ "Authorization": "Bearer <jwt>" }
- Get token from Keycloak with any service name and secret key.
- Go to service directory
mvn clean verify
mvn jacoco:report