# pomozovalexander/astondreamteamproject architecture

> Architecture diagram of the GitHub repository pomozovalexander/astondreamteamproject, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pomozovalexander/astondreamteamproject
- Repository: https://github.com/pomozovalexander/astondreamteamproject

## Overview

##### Main Components
- Application Entry Points: The primary classes (App.java and LocalTestApp.java) that bootstrap the application. They handle the central loop of reading user input and orchestrating operations.
- Domain Models: The custom classes (Book, Car, RootVegetable) which represent the entities being sorted.
- Service Layer: Service classes (e.g., BookService, CarService, RootVegetableService) housed under the service package to manage business logic. The ServiceFactory plays a crucial role in assembling and providing the right service based on context.
- Strategy Modules: A set of interfaces and concrete implementations in the strategy package. These include:
- DataInputStrategy: Determines how input is gathered (CLI, file, or random).
- SortingStrategy: Houses the ShellSort implementation for generic arrays.
- OutputStrategy: For processing output, likely involving writing results to a file (as required by the additional task).
- SearchStrategy: Implements generic binary search functionality.
- ExitStrategy: Controls exiting the main application loop.
- Utility Modules: Organized in sub-packages:
- CLI utilities (e.g., BookArrayCLIBuilder, CarArrayCLIBuilder, etc.) for building command-line interfaces.
- File loader utilities to load data from JSON files.
- Finder utilities to perform binary search for each domain model.
- Generator utilities that randomly generate domain objects.
- Comparators and Sorting utilities (the sorter package) that provide various Comparator implementations to help with custom sorting on multiple fields.
- Resources: The input and results directories (inside src/main/resources) that store sample data and output files.

##### Relationships and Interactions
- Each Service uses a combination of Strategy implementations. For example, based on the user’s choice, the service selects an appropriate DataInputStrategy and SortingStrategy.
- The CLI utilities (in utils/cli) are used by the Application Layer for user interactions.
- File loader, generator, and finder utilities provide supporting functions and are invoked by both services and strategies.
- The comparators (under utils/sorter) are “plugged in” to the SortingStrategy (ShellSorter) as parameters to enable custom ordering.
- The binary search (a part of SearchStrategy) takes sorted collections (the result of ShellSort) and performs search operations.

##### Architectural Patterns and Design Principles
- Strategy Pattern: Every key operation (input, output, sorting, searching, exit) is encapsulated in its own strategy interface and concrete implementation.
- Generics: Sorting and search utilities are designed to work with any type of custom objects.
- Separation of Concerns: Clearly distinct layers for data models, business logic (services), strategies (algorithms/operations), and utilities.
- Reusability: Modular utilities (CLI builders, file loaders, comparators) are designed to serve different parts of the system without tight coupling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        A1["App.java"]:::application
        A2["LocalTestApp.java"]:::application
    end

    %% Domain Models
    subgraph "Domain Models"
        BM["Book"]:::domain
        CM["Car"]:::domain
        RM["RootVegetable"]:::domain
    end

    %% Service Layer
    subgraph "Service Layer"
        SF["ServiceFactory"]:::service
        BS["BookService"]:::service
        CS["CarService"]:::service
        RS["RootVegetableService"]:::service
    end

    %% Strategy Modules
    subgraph "Strategy Modules"
        DIS["DataInputStrategy"]:::strategy
        SOS["SortingStrategy"]:::strategy
        SSS["SearchStrategy"]:::strategy
        OS["OutputStrategy"]:::strategy
        ES["ExitStrategy"]:::strategy
    end

    %% Utility Layer
    subgraph "Utility Layer"
        subgraph "CLI Utilities"
            CLI["CLI Utilities"]:::utility
        end
        subgraph "File Loader Utilities"
            FL["File Loader Utilities"]:::utility
        end
        subgraph "Finder Utilities"
            FI["Finder Utilities"]:::utility
        end
        subgraph "Generator Utilities"
            GEN["Generator Utilities"]:::utility
        end
        subgraph "Comparator & Sorting Utilities"
            COMP["Comparator & Sorting Utilities"]:::utility
        end
    end

    %% Resources
    subgraph "Resources"
        R1["Input Data (resources)"]:::resource
        R2["Results (resources)"]:::resource
    end

    %% Connections from Application to Service Factory
    A1 -->|"boots"| SF
    A2 -->|"boots"| SF

    %% Service Factory creates specific Services
    SF -->|"creates"| BS
    SF -->|"creates"| CS
    SF -->|"creates"| RS

    %% Each Service uses Strategy Modules
    %% Book Service
    BS -->|"uses"| DIS
    BS -->|"uses"| SOS
    BS -->|"uses"| SSS
    BS -->|"uses"| OS
    BS -->|"uses"| ES

    %% Car Service
    CS -->|"uses"| DIS
    CS -->|"uses"| SOS
    CS -->|"uses"| SSS
    CS -->|"uses"| OS
    CS -->|"uses"| ES

    %% RootVegetable Service
    RS -->|"uses"| DIS
    RS -->|"uses"| SOS
    RS -->|"uses"| SSS
    RS -->|"uses"| OS
    RS -->|"uses"| ES

    %% Strategies interacting with Domain Models
    SOS -->|"sorts"| BM
    SOS -->|"sorts"| CM
    SOS -->|"sorts"| RM

    SSS -->|"searches in"| BM
    SSS -->|"searches in"| CM
    SSS -->|"searches in"| RM

    %% Utilities assisting Strategies and Application
    CLI -->|"supports"| DIS
    FL -->|"feeds"| DIS
    FI -->|"assists"| SSS
    COMP -->|"assists"| SOS
    GEN -->|"generates"| BM
    GEN -->|"generates"| CM
    GEN -->|"generates"| RM

    %% Application layer interacts with CLI Utilities
    A1 -->|"user input"| CLI
    A2 -->|"user input"| CLI

    %% File loader uses Resources for input
    FL -->|"loads from"| R1

    %% Output strategy writes to Results
    OS -->|"writes to"| R2

    %% Define Styles
    classDef application fill:#f9c,stroke:#333,stroke-width:2px;
    classDef domain fill:#ccf,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef strategy fill:#fc9,stroke:#333,stroke-width:2px;
    classDef utility fill:#cff,stroke:#333,stroke-width:2px;
    classDef resource fill:#f99,stroke:#333,stroke-width:2px;

    %% Click Events for Application Entry Points
    click A1 "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/App.java"
    click A2 "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/LocalTestApp.java"

    %% Click Events for Domain Models
    click BM "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/model/Book.java"
    click CM "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/model/Car.java"
    click RM "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/model/RootVegetable.java"

    %% Click Events for Service Layer
    click SF "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/service/ServiceFactory.java"
    click BS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/service/BookService.java"
    click CS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/service/CarService.java"
    click RS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/service/RootVegetableService.java"

    %% Click Events for Strategy Modules
    click DIS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/strategy/DataInputStrategy.java"
    click SOS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/strategy/SortingStrategy.java"
    click SSS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/strategy/SearchStrategy.java"
    click OS "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/strategy/OutputStrategy.java"
    click ES "https://github.com/pomozovalexander/astondreamteamproject/blob/main/src/main/java/ru/aston/shellsorter/strategy/ExitStrategy.java"

    %% Click Events for Utilities
    click CLI "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/java/ru/aston/shellsorter/utils/cli/"
    click FL "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/java/ru/aston/shellsorter/utils/fileloader/"
    click FI "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/java/ru/aston/shellsorter/utils/finder/"
    click GEN "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/java/ru/aston/shellsorter/utils/generator/"
    click COMP "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/java/ru/aston/shellsorter/utils/sorter/"

    %% Click Events for Resources
    click R1 "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/resources/inputdata"
    click R2 "https://github.com/pomozovalexander/astondreamteamproject/tree/main/src/main/resources/results"
```
