# untaljon/making-coffee architecture

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

- Interactive diagram: https://gitdiagram.com/untaljon/making-coffee
- Repository: https://github.com/untaljon/making-coffee

## Overview

##### Project Type and Purpose
- This is a small command-line simulation tool (CLI) for a coffee machine, built in JavaScript (or TypeScript) and run on the Bun runtime.
- Its purpose is to model the behavior of a coffee machine: presenting menu options, managing resources, and brewing coffee types.

##### File Structure Analysis
Top-level files:
- main.js      – Entry point that wires everything together and handles user I/O
- CoffeeMachine.js – Core engine orchestrating brewing logic and resource checks
- Coffee.js    – Coffee object module, defines how a coffee is constructed (ingredients, quantities)
- CoffeeType.js – Enum or collection of available coffee types and their recipes
- MenuOption.js – Module defining the menu interface (e.g., “espresso”, “latte”, “off”)
- Resource.js  – Tracks the current state of ingredients (water, milk, beans, money)
- requirements.md – Business requirements/specs for each branch
- package.json, bun.lock, tsconfig.json – Bun/TypeScript configuration and dependency lock
- README.md    – Basic install & run instructions

##### README Insights
- Confirms Bun runtime, entry via `index.ts` (in practice `main.js`), and the existence of alternate requirement sets in `requirements.md`.

a. Main Components
1. Bun Runtime (container for the entire application)
2. CLI Interface (main.js)
3. CoffeeMachine Core
4. Domain Modules:
– MenuOption Module
– CoffeeType Module
– Coffee Module
– Resource Module
b. Relationships & Data Flow
- User → CLI Interface (text input)
- CLI Interface → CoffeeMachine: invokes methods like `selectMenuOption()`, `makeCoffee()`
- CoffeeMachine → Resource: check & update ingredient levels
- CoffeeMachine → CoffeeType: retrieve recipe for selected type
- CoffeeMachine → Coffee: instantiate coffee objects according to recipes
- CoffeeMachine → CLI Interface: prints status, errors, and final report
c. Architectural Patterns & Principles
- Single Responsibility: Each module handles one concept (menu, resource, recipe, brew logic).
- Dependency Injection: main.js injects modules into CoffeeMachine.
- In-memory State: no external database or APIs; all state is in the Resource module.
d. Key Technologies & Frameworks
- Bun runtime (fast JavaScript/TypeScript engine)
- ES module imports/exports
- (Optionally) TypeScript types from tsconfig.json

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User["User"]:::external

    %% Bun Runtime Container
    subgraph "Bun Runtime"
        direction TB
        CLI["CLI Interface"]:::io
        Core["CoffeeMachine Core"]:::core
        subgraph "Domain Modules"
            direction TB
            MenuOption["MenuOption Module"]:::domain
            CoffeeType["CoffeeType Module"]:::domain
            Coffee["Coffee Module"]:::domain
            Resource["Resource Module"]:::domain
        end
        subgraph "Documentation & Config"
            direction TB
            Requirements["requirements.md"]:::docs
            Readme["README.md"]:::docs
            Config["package.json, bun.lock, tsconfig.json"]:::docs
        end
    end

    %% Connections: User to CLI
    User -->|"enter command"| CLI

    %% CLI to Core
    CLI -->|"selectMenuOption() / makeCoffee()"| Core

    %% Core to Domain
    Core -->|"getMenuOptions()"| MenuOption
    Core -->|"getRecipe()"| CoffeeType
    Core -->|"instantiate()"| Coffee
    Core -->|"checkResources() / updateResources()"| Resource

    %% Core back to CLI
    Core -->|"printStatus() / errors"| CLI

    %% Click events
    click CLI "https://github.com/untaljon/making-coffee/blob/main/main.js"
    click Core "https://github.com/untaljon/making-coffee/blob/main/CoffeeMachine.js"
    click MenuOption "https://github.com/untaljon/making-coffee/blob/main/MenuOption.js"
    click CoffeeType "https://github.com/untaljon/making-coffee/blob/main/CoffeeType.js"
    click Coffee "https://github.com/untaljon/making-coffee/blob/main/Coffee.js"
    click Resource "https://github.com/untaljon/making-coffee/blob/main/Resource.js"
    click Requirements "https://github.com/untaljon/making-coffee/blob/main/requirements.md"
    click Readme "https://github.com/untaljon/making-coffee/blob/main/README.md"
    click Config "https://github.com/untaljon/making-coffee/blob/main/package.json"

    %% Styles
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef io fill:#D6EFFF,stroke:#333,stroke-width:1px
    classDef core fill:#FFE2D6,stroke:#333,stroke-width:1px
    classDef domain fill:#E2F7E1,stroke:#333,stroke-width:1px
    classDef docs fill:#F0F0F0,stroke:#333,stroke-width:1px
```
