# danilobaptistads/smartkiwi architecture

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

- Interactive diagram: https://gitdiagram.com/danilobaptistads/smartkiwi
- Repository: https://github.com/danilobaptistads/smartkiwi

## Overview

##### Project Type and Purpose
- SmartKiwi is a console‐based queue management system written in C#.
- It demonstrates layered architecture (UI, Services, Models) to simulate real‐world queue operations: check‐in, attendant calls, dynamic priority, aging, cycle checks.

##### File Structure Analysis
- Top-level:
- Program.cs & App.cs – application entry and bootstrap
- SmartKiwi.sln / .csproj – .NET solution and project files
- Models/ – domain objects: Client, Node, Queue (linked-queue implementation)
- Services/ – business logic modules:
- CheckIn, Attendant, QueueBuilder, QueueController (orchestrator), Aging, PrioritiesMatcher, CycleChecker
- Controller/ – console UI screens: InitialUi, MainUi, CheckInUi, AttendantUi, QueueBuilderUi

##### README Insights
- Clear separation of concerns: UI layer, Services (business rules), Models (data structures)
- Key features: linked queues, priority matching, aging, cycle detection
- No external persistence or web layer (future DB / dashboard modules are planned but not yet implemented)

a. Main Components
- Application Bootstrap: Program.cs → App.cs
- UI Layer: Controller/*Ui.cs classes
- Service Layer: QueueController + specialized services (CheckIn, Attendant, QueueBuilder, Aging, PrioritiesMatcher, CycleChecker)
- Data Model Layer: Node, Queue, Client
- Infrastructure: .NET 9.0 runtime, Console I/O

b. Relationships and Interactions
1. Program.cs initializes App, which constructs the main UI (MainUi).
2. MainUi listens for user input and delegates to sub-UIs (CheckInUi, AttendantUi, QueueBuilderUi).
3. Each UI invokes the appropriate service(s) via QueueController:
– CheckInUi → QueueController.CheckInService → Models (Client → Node → Queue)
– AttendantUi → QueueController.AttendantService → Queue (dequeue, update Client)
– QueueBuilderUi → QueueController.QueueBuilderService
4. Background tasks (Aging, CycleChecker, PrioritiesMatcher) are invoked periodically or within QueueController to recalculate priorities or detect cycles.

c. Architectural Patterns and Principles
– Layered Architecture: clearly separate UI, business logic, data model
– Single Responsibility: each service handles one aspect (check‐in, aging, etc.)
– Dependency Injection (lightweight): App.cs wires up UI → QueueController → individual services
– Modularization: each service is an independent module, enabling future extension (e.g., persistence, web API)

d. Technologies and Frameworks
– C# 9.0 / .NET 9.0
– Console I/O for UI layer
– Custom in‐memory linked list for queue model

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Initialization Layer
    subgraph "Application Initialization" 
        direction TB
        Prog["Program.cs"]:::infra
        App["App.cs"]:::infra
        Prog -->|"Initializes"| App
    end

    %% Console UI Layer
    subgraph "Console UI Layer" 
        direction TB
        MainUI["MainUi"]:::ui
        InitialUI["InitialUi"]:::ui
        CheckInUI["CheckInUi"]:::ui
        AttendantUI["AttendantUi"]:::ui
        QueueBuilderUI["QueueBuilderUi"]:::ui
        App -->|"Constructs"| MainUI
        MainUI -->|"Shows initial screen"| InitialUI
        MainUI -->|"Delegates to"| CheckInUI
        MainUI -->|"Delegates to"| AttendantUI
        MainUI -->|"Delegates to"| QueueBuilderUI
    end

    %% Service Layer
    subgraph "Service Layer" 
        direction TB
        QueueCtrl["QueueController"]:::service
        CheckInSvc["CheckIn"]:::service
        AttendantSvc["Attendant"]:::service
        QBldrSvc["QueueBuilder"]:::service
        AgingSvc["Aging"]:::service
        PrioritySvc["PrioritiesMatcher"]:::service
        CycleSvc["CycleChecker"]:::service

        CheckInUI -->|"Invoke CheckIn()"| QueueCtrl
        AttendantUI -->|"Invoke Attendant()"| QueueCtrl
        QueueBuilderUI -->|"Invoke BuildQueue()"| QueueCtrl

        QueueCtrl -->|"Enqueue(Client)"| CheckInSvc
        QueueCtrl -->|"Dequeue() / Update(Client)"| AttendantSvc
        QueueCtrl -->|"BuildQueue()"| QBldrSvc

        QueueCtrl -->|"InvokePeriodically()"| AgingSvc
        QueueCtrl -->|"InvokePeriodically()"| PrioritySvc
        QueueCtrl -->|"InvokePeriodically()"| CycleSvc
    end

    %% Model Layer
    subgraph "Data Model Layer" 
        direction TB
        ClientM["Client"]:::model
        NodeM["Node"]:::model
        QueueM["Queue"]:::model

        CheckInSvc -->|"Creates Client / Node"| ClientM
        CheckInSvc -->|"Adds Node"| NodeM
        CheckInSvc -->|"Enqueue Node"| QueueM

        AttendantSvc -->|"Dequeues Node"| QueueM
        PrioritySvc -->|"RecalculatePriority() on Client"| ClientM
        CycleSvc -->|"DetectCycle() on Node"| NodeM
        QBldrSvc -->|"Uses Queue"| QueueM
    end

    %% Infrastructure / Project Definition
    subgraph "Project Definition & Docs" 
        direction TB
        Sln["SmartKiwi.sln"]:::infra
        Cproj["SmartKiwi.csproj"]:::infra
        Readme["README.md"]:::infra
    end

    %% Click Events
    click Prog "https://github.com/danilobaptistads/smartkiwi/blob/main/Program.cs"
    click App "https://github.com/danilobaptistads/smartkiwi/blob/main/App.cs"
    click InitialUI "https://github.com/danilobaptistads/smartkiwi/blob/main/Controller/InitialUi.cs"
    click MainUI "https://github.com/danilobaptistads/smartkiwi/blob/main/Controller/MainUi.cs"
    click CheckInUI "https://github.com/danilobaptistads/smartkiwi/blob/main/Controller/CheckInUi.cs"
    click AttendantUI "https://github.com/danilobaptistads/smartkiwi/blob/main/Controller/AttendantUi.cs"
    click QueueBuilderUI "https://github.com/danilobaptistads/smartkiwi/blob/main/Controller/QueueBuilderUi.cs"
    click QueueCtrl "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/QueueController.cs"
    click CheckInSvc "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/CheckIn.cs"
    click AttendantSvc "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/Attendant.cs"
    click QBldrSvc "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/QueueBuilder.cs"
    click AgingSvc "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/Aging.cs"
    click PrioritySvc "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/PrioritiesMatcher.cs"
    click CycleSvc "https://github.com/danilobaptistads/smartkiwi/blob/main/Services/CycleChecker.cs"
    click ClientM "https://github.com/danilobaptistads/smartkiwi/blob/main/Models/Client.cs"
    click NodeM "https://github.com/danilobaptistads/smartkiwi/blob/main/Models/Node.cs"
    click QueueM "https://github.com/danilobaptistads/smartkiwi/blob/main/Models/Queue.cs"
    click Sln "https://github.com/danilobaptistads/smartkiwi/blob/main/SmartKiwi.sln"
    click Cproj "https://github.com/danilobaptistads/smartkiwi/blob/main/SmartKiwi.csproj"
    click Readme "https://github.com/danilobaptistads/smartkiwi/blob/main/README.md"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085
    classDef service fill:#d4edda,stroke:#155724,color:#155724
    classDef model fill:#fff3cd,stroke:#856404,color:#856404
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
