# alexnika/2026-02-otus-microservices-nikolaev architecture

> Architecture diagram of the GitHub repository alexnika/2026-02-otus-microservices-nikolaev, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexnika/2026-02-otus-microservices-nikolaev
- Repository: https://github.com/alexnika/2026-02-otus-microservices-nikolaev

## Overview

#### Scope and Evolution
This is an OTUS Microservice Architecture course repository organized as incremental assignments (`hw01`–`hw07`). Early modules demonstrate a standalone Spring Boot HTTP service and Kubernetes deployment; `hw04`–`hw06` evolve it into a PostgreSQL-backed, monitored, JWT-secured user service. `hw07` is the architectural culmination: a multi-service order/billing/notification system.

#### Primary Entry Points
The deployable runtime units in `hw07` are independent Java/Spring Boot applications:
- User/authentication service: `hw07/USERService/src/main/java/ru/otus/hw/UserServiceApplication.java`
- Order service: `hw07/ORDERService/src/main/java/ru/otus/hw/OrderServiceApplication.java`
- Billing service: `hw07/BILLINGService/src/main/java/ru/otus/hw/BillingServiceApplication.java`
- Notification service: `hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/NotificationServiceApplication.java`

The root Gradle build defines the multi-module project at `hw07/build.gradle` and `hw07/settings.gradle`. Local composition is represented by `hw07/DEV/docker-compose.yaml`; Kubernetes deployment is packaged as `hw07/hw07chart`.

#### User and Identity Boundary
`USERService` owns users, profiles, roles, credential handling, and JWT issuance/validation. Its REST resources split authentication, role administration, user CRUD, and profile operations:
- `hw07/USERService/src/main/java/ru/otus/hw/controller/AuthResource.java`
- `hw07/USERService/src/main/java/ru/otus/hw/controller/UserResource.java`
- `hw07/USERService/src/main/java/ru/otus/hw/security/JwtAuthenticationFilter.java`

JWT security and BCrypt configuration form the external-client authorization boundary. User registration/service behavior can call Billing through `hw07/USERService/src/main/java/ru/otus/hw/client/BillingServiceClient.java`, likely establishing an account as part of user lifecycle. User data has dedicated Flyway migrations under `hw07/USERService/src/main/resources/db/migration`.

#### Order Processing and Synchronous Billing
`ORDERService` owns order persistence and the public order API:
- `hw07/ORDERService/src/main/java/ru/otus/hw/controller/OrderResource.java`
- `hw07/ORDERService/src/main/java/ru/otus/hw/service/OrderServiceImpl.java`
- `hw07/ORDERService/src/main/java/ru/otus/hw/models/Order.java`

Order creation flows through the service layer to its database, then uses `BillingServiceClient` for synchronous billing operations (`hw07/ORDERService/src/main/java/ru/otus/hw/client/BillingServiceClient.java`). This is a direct service-to-service boundary configured via REST-client and billing-URL configuration.

#### Billing and Internal API Boundary
`BILLINGService` owns accounts and transaction records:
- `hw07/BILLINGService/src/main/java/ru/otus/hw/controller/AccountResource.java`
- `hw07/BILLINGService/src/main/java/ru/otus/hw/controller/InternalAccountResource.java`
- `hw07/BILLINGService/src/main/java/ru/otus/hw/service/TransactionServiceImpl.java`

It exposes both account-facing and internal account/order resources. `InternalApiFilterConfig` in billing and order services indicates protected internal calls using an API-key boundary:
- `hw07/BILLINGService/src/main/java/ru/otus/hw/config/InternalApiFilterConfig.java`
- `hw07/ORDERService/src/main/java/ru/otus/hw/config/InternalApiFilterConfig.java`

Account and transaction schemas are independently migrated in `hw07/BILLINGService/src/main/resources/db/migration`.

#### Asynchronous Notification Pipeline
After order activity, `ORDERService` publishes a shared notification event through RabbitMQ:
- `hw07/ORDERService/src/main/java/ru/otus/hw/producer/NotificationEventPublisher.java`
- `hw07/COMMONDomain/src/main/java/ru/otus/hw/dto/NotificationEvent.java`

`NOTIFICATIONService` consumes that event, persists notifications, and exposes a notification API:
- `hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/consumer/NotificationConsumer.java`
- `hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/service/NotificationServiceImpl.java`
- `hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/config/RabbitMQListenerConfig.java`

This separates notification delivery from the synchronous order/billing path. `COMMONDomain` is the explicit shared contract module for cross-service DTOs, errors, and common entity abstractions.

#### Infrastructure and Operations
Each service has its own Dockerfile and application configuration, while the Helm chart provisions application deployments/services, PostgreSQL stateful infrastructure, RabbitMQ, secrets/configuration, and ingress:
- `hw07/hw07chart/templates/app-deployment.yaml`
- `hw07/hw07chart/templates/postgres-statefulset.yaml`
- `hw07/hw07chart/templates/rabbitmq.yaml`

Earlier `hw05` adds Prometheus/Grafana deployment assets, including service monitors and a PostgreSQL exporter, under `hw05/prometheus-grafana-chart`. The principal material runtimes are Java/Spring Boot, Gradle (final multi-service module), PostgreSQL with Flyway migrations, RabbitMQ, Docker, Kubernetes/Helm, and NGINX Ingress.

Main entry points: [`hw07/hw07chart`](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/hw07chart) (NGINX Ingress), [`hw07/USERService/src/main/java/ru/otus/hw/UserServiceApplication.java`](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/UserServiceApplication.java) (User service), [`hw07/ORDERService/src/main/java/ru/otus/hw/service/OrderServiceImpl.java`](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/service/OrderServiceImpl.java) (Order workflow), [`hw07/BILLINGService/src/main/java/ru/otus/hw/BillingServiceApplication.java`](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/BILLINGService/src/main/java/ru/otus/hw/BillingServiceApplication.java) (Billing service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hw07["HW07 services"]
  node_user["User service<br/>Spring Boot service"]
  node_user_api["Auth and user API<br/>REST controllers<br/>[AuthResource.java]"]
  node_jwt["JWT security<br/>security filter"]
  node_order["Order service<br/>Spring Boot service"]
  node_order_logic["Order workflow<br/>service layer"]
  node_billing["Billing service<br/>Spring Boot service"]
  node_billing_api["Account APIs<br/>REST controllers"]
  node_notification["Notification service<br/>Spring Boot service"]
  node_common["Common domain contract<br/>shared Gradle module"]
end

subgraph group_data["State and messaging"]
  node_user_db[("User PostgreSQL<br/>service database")]
  node_order_db[("Order PostgreSQL<br/>service database<br/>[Order.java]")]
  node_billing_db[("Billing PostgreSQL<br/>service database")]
  node_notification_db[("Notification store<br/>service database")]
  node_rabbitmq["RabbitMQ<br/>event broker<br/>[rabbitmq.yaml]"]
end

subgraph group_platform["Deployment and operations"]
  node_ingress["NGINX Ingress<br/>kubernetes ingress"]
  node_helm{{"Helm deployment chart<br/>Kubernetes packaging"}}
  node_observability["Prometheus and Grafana<br/>monitoring stack"]
end

node_client(("External clients"))

node_client -->|"HTTP"| node_ingress
node_ingress -->|"routes"| node_user
node_ingress -->|"routes"| node_order
node_ingress -->|"routes"| node_billing
node_ingress -->|"routes"| node_notification
node_user -->|"serves"| node_user_api
node_user_api -->|"secured by"| node_jwt
node_user -->|"user data"| node_user_db
node_user -->|"account setup"| node_billing_api
node_order -->|"executes"| node_order_logic
node_order_logic -->|"persists"| node_order_db
node_order_logic -->|"synchronous billing"| node_billing_api
node_billing -->|"serves"| node_billing_api
node_billing -->|"accounts and transactions"| node_billing_db
node_order_logic -->|"publishes notification event"| node_rabbitmq
node_rabbitmq -->|"delivers event"| node_notification
node_notification -->|"persists notifications"| node_notification_db
node_common -.->|"event contract"| node_order
node_common -.->|"event contract"| node_notification
node_helm -.->|"provisions"| node_ingress
node_helm -.->|"provisions"| node_rabbitmq
node_observability -.->|"monitors"| node_user
node_observability -.->|"monitors"| node_order
node_observability -.->|"monitors"| node_billing

click node_ingress "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/hw07chart"
click node_user "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/UserServiceApplication.java"
click node_user_api "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/controller/AuthResource.java"
click node_jwt "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/security/JwtAuthenticationFilter.java"
click node_order "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/OrderServiceApplication.java"
click node_order_logic "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/service/OrderServiceImpl.java"
click node_billing "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/BILLINGService/src/main/java/ru/otus/hw/BillingServiceApplication.java"
click node_billing_api "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/BILLINGService/src/main/java/ru/otus/hw/controller/InternalAccountResource.java"
click node_notification "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/NotificationServiceApplication.java"
click node_common "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/COMMONDomain/src/main/java/ru/otus/hw/dto/NotificationEvent.java"
click node_user_db "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/USERService/src/main/resources/db/migration"
click node_order_db "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/models/Order.java"
click node_billing_db "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/BILLINGService/src/main/resources/db/migration"
click node_notification_db "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/service/NotificationServiceImpl.java"
click node_rabbitmq "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/hw07chart/templates/rabbitmq.yaml"
click node_helm "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/hw07chart/templates/app-deployment.yaml"
click node_observability "https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw05/prometheus-grafana-chart"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_user,node_user_api,node_jwt,node_order,node_order_logic,node_billing,node_billing_api,node_notification,node_common toneBlue
class node_user_db,node_order_db,node_billing_db,node_notification_db,node_rabbitmq toneAmber
class node_ingress,node_helm,node_observability toneMint
class node_client toneNeutral
```

## Components

### HW07 services

Multi-service order and billing system.

- [User service](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/UserServiceApplication.java): Spring Boot service · Owns identity, profiles, roles, and JWTs. · `hw07/USERService/src/main/java/ru/otus/hw/UserServiceApplication.java`
- [Auth and user API](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/controller/AuthResource.java): REST controllers · `hw07/USERService/src/main/java/ru/otus/hw/controller/AuthResource.java`
- [JWT security](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/USERService/src/main/java/ru/otus/hw/security/JwtAuthenticationFilter.java): security filter · JWT validation and BCrypt authorization boundary. · `hw07/USERService/src/main/java/ru/otus/hw/security/JwtAuthenticationFilter.java`
- [Order service](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/OrderServiceApplication.java): Spring Boot service · Owns the public order API and order lifecycle. · `hw07/ORDERService/src/main/java/ru/otus/hw/OrderServiceApplication.java`
- [Order workflow](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/service/OrderServiceImpl.java): service layer · Persists orders, bills synchronously, and publishes events. · `hw07/ORDERService/src/main/java/ru/otus/hw/service/OrderServiceImpl.java`
- [Billing service](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/BILLINGService/src/main/java/ru/otus/hw/BillingServiceApplication.java): Spring Boot service · Owns accounts and transaction records. · `hw07/BILLINGService/src/main/java/ru/otus/hw/BillingServiceApplication.java`
- [Account APIs](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/BILLINGService/src/main/java/ru/otus/hw/controller/InternalAccountResource.java): REST controllers · Separates account-facing and internal account operations. · `hw07/BILLINGService/src/main/java/ru/otus/hw/controller/InternalAccountResource.java`
- [Notification service](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/NotificationServiceApplication.java): Spring Boot service · Consumes order events and exposes notifications. · `hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/NotificationServiceApplication.java`
- [Common domain contract](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/COMMONDomain/src/main/java/ru/otus/hw/dto/NotificationEvent.java): shared Gradle module · Shared DTOs, errors, and entity abstractions. · `hw07/COMMONDomain/src/main/java/ru/otus/hw/dto/NotificationEvent.java`

### State and messaging

- [User PostgreSQL](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/USERService/src/main/resources/db/migration): service database · Flyway-managed user schema. · `hw07/USERService/src/main/resources/db/migration`
- [Order PostgreSQL](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/ORDERService/src/main/java/ru/otus/hw/models/Order.java): service database · `hw07/ORDERService/src/main/java/ru/otus/hw/models/Order.java`
- [Billing PostgreSQL](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/BILLINGService/src/main/resources/db/migration): service database · Flyway-managed account and transaction schema. · `hw07/BILLINGService/src/main/resources/db/migration`
- [Notification store](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/service/NotificationServiceImpl.java): service database · `hw07/NOTIFICATIONService/src/main/java/ru/otus/hw/service/NotificationServiceImpl.java`
- [RabbitMQ](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/hw07chart/templates/rabbitmq.yaml): event broker · `hw07/hw07chart/templates/rabbitmq.yaml`

### Deployment and operations

- [NGINX Ingress](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw07/hw07chart): kubernetes ingress · `hw07/hw07chart`
- [Helm deployment chart](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/blob/master/hw07/hw07chart/templates/app-deployment.yaml): Kubernetes packaging · Deploys services, PostgreSQL, RabbitMQ, configuration, and ingress. · `hw07/hw07chart/templates/app-deployment.yaml`
- [Prometheus and Grafana](https://github.com/alexnika/2026-02-otus-microservices-nikolaev/tree/master/hw05/prometheus-grafana-chart): monitoring stack · Earlier course deployment monitoring assets. · `hw05/prometheus-grafana-chart`

### Other components

- **External clients**: clients

## Connections

- External clients → NGINX Ingress: HTTP
- NGINX Ingress → User service: routes
- NGINX Ingress → Order service: routes
- NGINX Ingress → Billing service: routes
- NGINX Ingress → Notification service: routes
- User service → Auth and user API: serves
- Auth and user API → JWT security: secured by
- User service → User PostgreSQL: user data
- User service → Account APIs: account setup · REST client call during user lifecycle.
- Order service → Order workflow: executes
- Order workflow → Order PostgreSQL: persists
- Order workflow → Account APIs: synchronous billing · Protected internal REST call.
- Billing service → Account APIs: serves
- Billing service → Billing PostgreSQL: accounts and transactions
- Order workflow → RabbitMQ: publishes notification event
- RabbitMQ → Notification service: delivers event
- Notification service → Notification store: persists notifications
- Common domain contract → Order service: event contract
- Common domain contract → Notification service: event contract
- Helm deployment chart → NGINX Ingress: provisions
- Helm deployment chart → RabbitMQ: provisions
- Prometheus and Grafana → User service: monitors
- Prometheus and Grafana → Order service: monitors
- Prometheus and Grafana → Billing service: monitors
