# nvakulenko/architecture-lab4 architecture

> Architecture diagram of the GitHub repository nvakulenko/architecture-lab4, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nvakulenko/architecture-lab4
- Repository: https://github.com/nvakulenko/architecture-lab4

## Overview

1. This is a small Spring Boot backend centered on two business areas: **accounts** and **flight bookings**. The entry point is `BookingApplication`, and the app is organized as two feature modules rather than layered globally.

2. The architecture follows a consistent **controller → service → repository → persistence model** flow. Each feature has its own API package, service package, and repository package, which keeps the account and booking logic separated.

3. The **account subsystem** exposes `AccountRestController` for HTTP access, `AccountService` for business logic, `AccountRepository` for persistence, and the `Account` entity as the stored model. `AccountDto` is used to transfer account data through the API boundary.

4. The account domain has an important rule from the README: the `amount` field must never be below zero. That constraint is part of the persistence/domain boundary, because it protects the balance data that booking operations depend on.

5. The **flight booking subsystem** mirrors the same structure: `FlyRestApiController`, `FlyBookingService`, `FlyBookingRepository`, and the `FlyBooking` entity, with `FlyBookingDto` at the API boundary. This suggests a classic REST-to-service-to-database path for booking operations.

6. The main business flow is: a client calls the booking API, the booking service checks the customer’s account balance, and then a booking is created while the account is debited. The README explicitly describes the “enough funds” check as a required rule.

7. The two subsystems are coupled through the **shared account balance**. Booking is not a standalone write; it depends on account state and must fail if the balance is insufficient. That dependency is the key integration boundary in the system.

8. Error handling is explicit in the service layer. There are custom exceptions for account problems (`AccountException`, `AccountNotFoundException`) and booking problems (`FlyBookingException`), which indicates that business validation failures are intended to be translated into API-level error responses.

9. Persistence is repository-based and likely uses Spring Data/JPA-style abstractions, given the repository interfaces and entity classes. The repositories are the only direct data access boundary; controllers should not touch entities directly.

10. `application.properties` holds runtime configuration, while `Fly Booking Service.postman_collection.json` is provided for manual API testing and documentation of the HTTP contract. There is no frontend in this repository.

11. For an architecture diagram, the most important boundaries are:
   - external client / Postman collection
   - REST controllers
   - business services
   - repositories / database
   - shared account balance dependency used by booking logic

12. In short, this is a backend service that manages customer accounts and flight bookings, enforcing a non-negative balance and “sufficient funds before booking” rule through the service layer.

Main entry points: [`src/main/java/org/example/flybooking/service/FlyBookingService.java`](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/service/FlyBookingService.java) (Booking Service), [`src/main/java/org/example/account/api/AccountRestController.java`](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/api/AccountRestController.java) (Account API), [`src/main/java/org/example/flybooking/api/FlyRestApiController.java`](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/api/FlyRestApiController.java) (Booking API), [`src/main/java/org/example/account/service/AccountService.java`](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/service/AccountService.java) (Account Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_booking_app["BookingApp<br/>spring boot app"]
  node_app_props["Config"]
end

subgraph group_account["Accounts"]
  node_account_controller["Account API<br/>rest controller"]
  node_account_dto["Account DTO<br/>api dto<br/>[AccountDto.java]"]
  node_account_service["Account Service<br/>business service"]
  node_account_repo["Account Repo<br/>data repository"]
  node_account_model[("Account<br/>entity<br/>[Account.java]")]
  node_account_errors{{"Account Errors<br/>domain exceptions"}}
end

subgraph group_booking["Bookings"]
  node_fly_controller["Booking API<br/>rest controller"]
  node_fly_dto["Booking DTO<br/>api dto<br/>[FlyBookingDto.java]"]
  node_fly_service["Booking Service<br/>business service"]
  node_fly_repo["Booking Repo<br/>data repository"]
  node_fly_model[("FlyBooking<br/>entity<br/>[FlyBooking.java]")]
  node_fly_errors{{"Booking Errors<br/>domain exceptions"}}
end

subgraph group_integration["External"]
  node_client(("Client<br/>external actor"))
  node_postman["Postman<br/>api collection"]
end

node_client -->|"calls"| node_account_controller
node_client -->|"calls"| node_fly_controller
node_postman -.->|"exercises"| node_account_controller
node_postman -.->|"exercises"| node_fly_controller
node_booking_app -->|"wires"| node_account_controller
node_booking_app -->|"wires"| node_fly_controller
node_booking_app -->|"loads"| node_app_props
node_account_controller -->|"uses"| node_account_service
node_account_controller -.->|"maps"| node_account_dto
node_account_service -->|"persists"| node_account_repo
node_account_service -.->|"throws"| node_account_errors
node_account_repo -->|"stores"| node_account_model
node_fly_controller -->|"uses"| node_fly_service
node_fly_controller -.->|"maps"| node_fly_dto
node_fly_service -->|"persists"| node_fly_repo
node_fly_service -->|"checks balance"| node_account_service
node_fly_service -.->|"throws"| node_fly_errors
node_fly_repo -->|"stores"| node_fly_model
node_fly_service -.->|"reads balance"| node_account_repo

click node_postman "https://github.com/nvakulenko/architecture-lab4/blob/main/Fly Booking Service.postman_collection.json"
click node_booking_app "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/BookingApplication.java"
click node_app_props "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/resources/application.properties"
click node_account_controller "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/api/AccountRestController.java"
click node_account_dto "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/api/dto/AccountDto.java"
click node_account_service "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/service/AccountService.java"
click node_account_repo "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/repository/AccountRepository.java"
click node_account_model "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/repository/model/Account.java"
click node_account_errors "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/service/exception/AccountException.java"
click node_fly_controller "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/api/FlyRestApiController.java"
click node_fly_dto "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/api/dto/FlyBookingDto.java"
click node_fly_service "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/service/FlyBookingService.java"
click node_fly_repo "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/repository/FlyBookingRepository.java"
click node_fly_model "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/repository/FlyBooking.java"
click node_fly_errors "https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/service/exception/FlyBookingException.java"

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_booking_app,node_app_props toneBlue
class node_account_controller,node_account_dto,node_account_service,node_account_repo,node_account_model,node_account_errors toneAmber
class node_fly_controller,node_fly_dto,node_fly_service,node_fly_repo,node_fly_model,node_fly_errors toneMint
class node_client,node_postman toneRose
```

## Components

### Application

Spring Boot entry point and runtime config

- [BookingApp](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/BookingApplication.java): spring boot app · Application entry point · `src/main/java/org/example/BookingApplication.java`
- [Config](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/resources/application.properties): runtime config · Application properties · `src/main/resources/application.properties`

### Accounts

Customer account API, service, and persistence

- [Account API](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/api/AccountRestController.java): rest controller · HTTP boundary for accounts · `src/main/java/org/example/account/api/AccountRestController.java`
- [Account DTO](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/api/dto/AccountDto.java): api dto · Account data transfer object · `src/main/java/org/example/account/api/dto/AccountDto.java`
- [Account Service](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/service/AccountService.java): business service · Account rules and balance operations · `src/main/java/org/example/account/service/AccountService.java`
- [Account Repo](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/repository/AccountRepository.java): data repository · Persistence access for accounts · `src/main/java/org/example/account/repository/AccountRepository.java`
- [Account](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/repository/model/Account.java): entity · Stored account model · `src/main/java/org/example/account/repository/model/Account.java`
- [Account Errors](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/account/service/exception/AccountException.java): domain exceptions · Account validation and not-found failures · `src/main/java/org/example/account/service/exception/AccountException.java`

### Bookings

Flight booking API, service, and persistence

- [Booking API](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/api/FlyRestApiController.java): rest controller · HTTP boundary for flight bookings · `src/main/java/org/example/flybooking/api/FlyRestApiController.java`
- [Booking DTO](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/api/dto/FlyBookingDto.java): api dto · Booking data transfer object · `src/main/java/org/example/flybooking/api/dto/FlyBookingDto.java`
- [Booking Service](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/service/FlyBookingService.java): business service · Checks funds and creates bookings · `src/main/java/org/example/flybooking/service/FlyBookingService.java`
- [Booking Repo](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/repository/FlyBookingRepository.java): data repository · Persistence access for bookings · `src/main/java/org/example/flybooking/repository/FlyBookingRepository.java`
- [FlyBooking](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/repository/FlyBooking.java): entity · Stored booking model · `src/main/java/org/example/flybooking/repository/FlyBooking.java`
- [Booking Errors](https://github.com/nvakulenko/architecture-lab4/blob/main/src/main/java/org/example/flybooking/service/exception/FlyBookingException.java): domain exceptions · Booking validation failures · `src/main/java/org/example/flybooking/service/exception/FlyBookingException.java`

### External

Client-facing and manual testing integration

- **Client**: external actor · Calls the REST API
- [Postman](https://github.com/nvakulenko/architecture-lab4/blob/HEAD/Fly%20Booking%20Service.postman_collection.json): api collection · Manual API testing and contract reference · `Fly Booking Service.postman_collection.json`

## Connections

- Client → Account API: calls · HTTP access to account operations
- Client → Booking API: calls · HTTP access to booking operations
- Postman → Account API: exercises · Manual requests for account endpoints
- Postman → Booking API: exercises · Manual requests for booking endpoints
- BookingApp → Account API: wires · Bootstraps account API
- BookingApp → Booking API: wires · Bootstraps booking API
- BookingApp → Config: loads · Runtime configuration
- Account API → Account Service: uses · Delegates account operations
- Account API → Account DTO: maps · API payload boundary
- Account Service → Account Repo: persists · Reads and updates account state
- Account Service → Account Errors: throws · Business validation failures
- Account Repo → Account: stores · Account entity persistence
- Booking API → Booking Service: uses · Delegates booking operations
- Booking API → Booking DTO: maps · API payload boundary
- Booking Service → Booking Repo: persists · Reads and writes bookings
- Booking Service → Account Service: checks balance · Validates sufficient funds before booking
- Booking Service → Booking Errors: throws · Booking validation failures
- Booking Repo → FlyBooking: stores · Booking entity persistence
- Booking Service → Account Repo: reads balance · Accesses account state for fund checks
