# docesforg/kursovay-ygadai-chislo- architecture

> Architecture diagram of the GitHub repository docesforg/kursovay-ygadai-chislo-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/docesforg/kursovay-ygadai-chislo-
- Repository: https://github.com/docesforg/kursovay-ygadai-chislo-

## Overview

##### Project type and purpose
- This is a single-form desktop GUI application built with C++Builder (Borland/Embarcadero VCL).
- It implements the classic “Guess the Number” game: one player enters a secret number, the other makes guesses, and the app provides positional hints, tracks attempts, enforces limits, and logs results.

##### File structure
- Top-level build files: Project2.bpr (project file), Project2.cpp (auto-generated main), Project2.res, Project2.obj, Project2.exe.
- Unit1.*: the form definition and implementation (Unit1.dfm holds the VCL form, Unit1.cpp / Unit1.h contain event handlers and game logic).
- No frontend/backend split or external services—everything lives in one process.

##### Main components
a. UI Layer (Form1)
- Input fields and buttons for “set secret” and “make guess”
- Areas for hints, previous guesses, error messages, turn count
b. Game Engine (Business Logic)
- Secret-number storage
- Guess validation (range 0–1000, digit count ≤4, numeric only)
- Turn counter (max 10 turns)
- Hint generator (calculates correct digit positions)
- Error/validation routines
c. Session Manager
- Role selection (setter vs. guesser)
- State transitions (waiting for secret → guessing → game end)
d. Persistence / File Writer
- On game end (win/lose), write timestamped record to output.txt: secret, guesses, turn count, date/time
e. Auxiliary
- Error dialog service (pop-ups for invalid input)

##### Relationships and data flows
- User → UI Layer: clicks buttons and types numbers
- UI Layer → Game Engine: invokes validation and hint calculation on each guess
- Game Engine → UI Layer: returns hint strings, updates turn count, signals win/lose
- UI Layer → Session Manager: updates game state and role switching
- On game end: UI Layer / Session Manager → File Writer: dispatch a write-record operation

##### Architectural patterns and principles
- Lightweight MVC/MVP flavor:
- View (VCL Form) handles rendering and event capture
- Controller/Presenter (in Unit1.cpp) orchestrates validation and business rules
- Model (game state variables, guess history) lives in memory
- Single cohesive module—no microservices or external APIs
- Separation of concerns: UI, validation, core logic, and persistence each in distinct logical units

##### Relevant technologies
- Embarcadero C++Builder / Borland VCL framework
- Windows native dialogs and controls
- Standard C++ file I/O for output.txt

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    User(["User"]):::external

    %% UI Layer
    subgraph "UI Layer"
        Form1["Form1 (VCL Form)"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        GameEngine["GameEngine\n(secret storage,\nvalidation, hint generator,\nturn counter)"]:::logic
        SessionManager["SessionManager\n(role selection,\nstate transitions)"]:::logic
    end

    %% Persistence Layer
    FileWriter["FileWriter\n(writeRecord())"]:::persistence

    %% Auxiliary Services
    ErrorDialog["ErrorDialogService\n(pop-up dialogs)"]:::aux

    %% Relationships
    User -->|"interacts with"| Form1
    Form1 -->|"validateGuess() / generateHint()"| GameEngine
    GameEngine -->|"hintResult / status"| Form1
    Form1 -->|"updateState()"| SessionManager
    SessionManager -->|"onGameEnd"| FileWriter
    Form1 -->|"showError()"| ErrorDialog
    ErrorDialog -->|"acknowledge"| Form1

    %% Click Events
    click Form1 "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.dfm"
    click Form1 "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.cpp"
    click Form1 "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.h"
    click GameEngine "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.cpp"
    click GameEngine "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.h"
    click SessionManager "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.cpp"
    click SessionManager "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.h"
    click FileWriter "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.cpp"
    click ErrorDialog "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.cpp"
    click ErrorDialog "https://github.com/docesforg/kursovay-ygadai-chislo-/blob/main/Unit1.h"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef persistence fill:#FFA500,stroke:#333,stroke-width:1px
    classDef aux fill:#FFD700,stroke:#333,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
