# ndat99/pbl3_coffeehome architecture

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

- Interactive diagram: https://gitdiagram.com/ndat99/pbl3_coffeehome
- Repository: https://github.com/ndat99/pbl3_coffeehome

## Overview

##### Project type and purpose
- This is a desktop, full-stack “CoffeeHome” management application built on .NET WinForms with a classic 4-tier layered architecture.
- It supports multiple user roles (Admin, Barista, Cashier, Login) and manages menu items, inventory, orders, revenues, discounts, and user accounts via an underlying SQL database (accessed through Entity Framework).

##### File structure
- Top-level solution (`PBL3_CoffeeHome.sln`) and project folder (`PBL3_CoffeeHome`).
- Layers:
- GUI (WinForms UIs organized by role: Admin, Barista, Cashier, Login)
- BLL (Business Logic Layer): services such as OrderBLL, InventoryBLL, RevenueBLL, UserBLL, etc.
- DAL (Data Access Layer): `CoffeeDbContext.cs` plus repository classes (`*DAL.cs`) implementing CRUD via EF.
- DTO (Data Transfer Objects): simple POCO models for entities and ViewModels.
- Config and Properties: `App.config`, EF connection strings, resources.

##### Key insights (README is minimal)
- No external microservices or cloud components. All business logic is on the client-side application.
- Uses repository pattern over EF for data operations.

##### Detail
- BLL and DAL service class or group services logically
- Explicitly show the EF DbContext as the point of mapping to the SQL database
- Flow of DTO objects through the layers
- Every tier and its responsibilities are clearly annotated, so a new engineer can instantly grasp how UI events propagate down to database calls and back.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "GUI Layer"
        AdminUI["Admin UI"]:::ui
        BaristaUI["Barista UI"]:::ui
        CashierUI["Cashier UI"]:::ui
        LoginUI["Login UI"]:::ui
        ProgramCS["Program.cs"]:::ui
    end

    subgraph "Business Logic Layer (BLL)"
        OrderBLL["OrderBLL"]:::bll
        InventoryBLL["InventoryBLL"]:::bll
        RevenueBLL["RevenueBLL"]:::bll
        UserBLL["UserBLL"]:::bll
        DiscountBLL["DiscountBLL"]:::bll
    end

    subgraph "Data Transfer Objects (DTO)"
        DTOModels["DTO Models"]:::dto
    end

    subgraph "Data Access Layer (DAL)"
        CoffeeDbContext["CoffeeDbContext"]:::dal
        Repositories["Repositories Folder"]:::dal
    end

    SQLDB["SQL Database"]:::db
    AppConfig["App.config"]:::config

    %% Connections
    LoginUI -->|"Authenticate()"| UserBLL
    AdminUI -->|"ManageUsers()"| UserBLL
    BaristaUI -->|"GetOrders()"| OrderBLL
    CashierUI -->|"RecordRevenue()"| RevenueBLL
    AdminUI -->|"ApplyDiscount()"| DiscountBLL
    BaristaUI -->|"UpdateInventory()"| InventoryBLL
    ProgramCS -->|"Start Application"| OrderBLL

    OrderBLL -->|"Uses DTOs"| DTOModels
    InventoryBLL -->|"Uses DTOs"| DTOModels
    RevenueBLL -->|"Uses DTOs"| DTOModels
    UserBLL -->|"Uses DTOs"| DTOModels
    DiscountBLL -->|"Uses DTOs"| DTOModels

    OrderBLL -->|"calls Repository"| Repositories
    InventoryBLL -->|"calls Repository"| Repositories
    RevenueBLL -->|"calls Repository"| Repositories
    UserBLL -->|"calls Repository"| Repositories
    DiscountBLL -->|"calls Repository"| Repositories

    Repositories -->|"uses DbContext"| CoffeeDbContext
    CoffeeDbContext -->|"executes ORM"| SQLDB

    AppConfig -->|"Connection Strings"| CoffeeDbContext

    %% Click Events
    click ProgramCS "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/Program.cs"
    click OrderBLL "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/BLL/OrderBLL.cs"
    click InventoryBLL "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/BLL/InventoryBLL.cs"
    click RevenueBLL "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/BLL/RevenueBLL.cs"
    click UserBLL "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/BLL/UserBLL.cs"
    click DiscountBLL "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/BLL/DiscountBLL.cs"
    click DTOModels "https://github.com/ndat99/pbl3_coffeehome/tree/master/PBL3_CoffeeHome/DTO"
    click CoffeeDbContext "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/DAL/CoffeeDbContext.cs"
    click Repositories "https://github.com/ndat99/pbl3_coffeehome/tree/master/PBL3_CoffeeHome/DAL/Repository"
    click AppConfig "https://github.com/ndat99/pbl3_coffeehome/blob/master/PBL3_CoffeeHome/App.config"

    %% Styles
    classDef ui fill:#D5E8FF,stroke:#6C8EBF,color:#034A80;
    classDef bll fill:#E1F5A9,stroke:#7FB800,color:#4B6500;
    classDef dal fill:#FFE0B2,stroke:#FF9800,color:#BF360C;
    classDef dto fill:#FFF59D,stroke:#FDD835,color:#F57F17;
    classDef db fill:#B0BEC5,stroke:#546E7A,color:#263238;
    classDef config fill:#F8BBD0,stroke:#C2185B,color:#880E4F;
```
