# jitashi-arora/smart-kitchen architecture

> Architecture diagram of the GitHub repository jitashi-arora/smart-kitchen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jitashi-arora/smart-kitchen
- Repository: https://github.com/jitashi-arora/smart-kitchen

## Overview

This is a **single-process Java CLI application** (no server, no database, no networked components) whose purpose is to:
- Maintain an in-memory **fridge inventory**
- Track **expiration dates** (perishable vs non-perishable)
- Maintain an in-memory **recipe book**
- Run a **matching/priority engine** that finds cookable recipes and prioritizes those that prevent waste (expiring ingredients)

- Entry point + UI flow
- Domain models
- Engine/service logic
- Data stores (in-memory collections)
- Key algorithms (expiry checks + recipe matching)

##### File structure analysis (what components exist)
Only two code files exist:

- `KitchenApp.java`
- Application entry point
- CLI menus, user prompts, input parsing
- Calls into core logic

- `Models.java`
- Domain entities + engine:
- `Ingredient` (abstract)
- `Perishable`, `NonPerishable`
- `Recipe` (with `HashMap` of ingredient requirements)
- `KitchenEngine` (manages lists and smart matching)

There are **no persistence, external APIs, or deployment concerns** in this repo; everything is local and in-memory.

##### What the README reveals (important behaviors to represent)
- **Expiry tracking** using `java.time.LocalDate` and `ChronoUnit`
- “Expiring soon” threshold (within **3 days**) and UI flagging
- Matching engine that:
- Scans inventory vs recipe requirements
- Produces classifications: `[READY]` vs `[URGENT - SAVE FOOD]`
- Collections:
- `ArrayList` for inventory and recipe book
- `HashMap` inside `Recipe` for ingredient->quantity requirements

##### Domain Model Layer
- `Ingredient` (abstract)
- Common fields: name, quantity, unit, food group (as implied)
- Common behaviors: `toString()`
- `Perishable extends Ingredient`
- expiry date
- `isExpiringSoon()` logic (or equivalent)
- `NonPerishable extends Ingredient`
- no expiry date, or always “not expiring”

##### Recipe Model
- `Recipe`
- name
- requirements: `HashMap<IngredientName/Key, Quantity>` (key specifics depend on code)
- methods to add requirement lines, render details

##### Application / Service Layer
- `KitchenEngine`
- owns/manages:
- `inventory: ArrayList<Ingredient>`
- `recipes: ArrayList<Recipe>`
- operations:
- Ingredient
- Recipe
- Fridge (and mark expiring soon)
- match recipes against inventory
- prioritize “urgent” recipes that use expiring-soon ingredients

##### Runtime / Libraries
- Java Runtime + standard library
- `java.time.LocalDate`
- `ChronoUnit`
- `ArrayList`, `HashMap`

Even though “Java standard library” isn’t usually a component, here it’s architecturally relevant because expiration and matching depend on those APIs.

**Primary control flow:**
- `User` → `KitchenApp (CLI)` → `KitchenEngine`
- “Add Ingredient” command calls engine add method
- “Add Recipe” command calls engine add method
- “Show Fridge” calls engine list method
- “Find What I Can Cook” calls engine match method

**Domain usage:**
- `KitchenEngine` → uses/contains → `Ingredient` instances (Perishable/NonPerishable)
- `KitchenEngine` → uses/contains → `Recipe` instances
- `Recipe` → contains → `HashMap` of requirements

**Expiration logic:**
- `KitchenEngine` and/or `Perishable` → uses → `LocalDate/ChronoUnit`
- `KitchenApp` → displays → “expiring soon” flag (data comes from engine/model)

- `KitchenEngine.matchRecipes()`
- reads `inventory (ArrayList<Ingredient>)`
- reads `recipes (ArrayList<Recipe>)` + each recipe’s `requirements (HashMap)`
- produces `MatchResult` conceptually (even if not a class) that includes:
- status: READY / URGENT / NOT READY
- missing ingredients and/or soon-to-expire ingredients used

Even if the code prints directly instead of returning structured results, represent the *conceptual output* of the engine to the UI.

##### Architectural patterns/design principles used

- **Layering**: CLI (presentation) vs Engine (application logic) vs Models (domain)
- **OOP inheritance & polymorphism**:
- `Ingredient` → (`Perishable`, `NonPerishable`)
- different `toString()` / expiration behavior
- **In-memory repository pattern (implicit)**:
- `KitchenEngine` acts like a repository/service holding lists (no DB)
- **Rules/Policy**:
- “expiring soon = within 3 days” is a business rule; annotate it near the expiry component

##### Technologies/frameworks
In labels or side notes:
- Language: Java (JDK 8+)
- Collections: `ArrayList`, `HashMap`
- Dates: `LocalDate`, `ChronoUnit`
- Execution: CLI single JVM process

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actor
    U["User"]:::actor

    %% Layers (single-process CLI app)
    subgraph "Presentation Layer (CLI)"
        KA["KitchenApp (CLI / Entry Point)\nMenu loop • Input parsing • Output formatting\nShows: [READY] / [URGENT - SAVE FOOD] / EXPIRING SOON"]:::presentation
    end

    subgraph "Application / Service Layer"
        KE["KitchenEngine (Service / Core Logic)\nManages inventory+recipes • Matching • Prioritization"]:::service

        subgraph "In-memory State (Collections)"
            INV[("Inventory\nArrayList<Ingredient>")]:::datastore
            RB[("RecipeBook\nArrayList<Recipe>")]:::datastore
        end

        subgraph "Core Algorithms / Rules"
            EXP["Expiry Tracking\nRule: (expiryDate - today) ≤ 3 days\nFlags: EXPIRING SOON"]:::rule
            MATCH["Recipe Matching\nREADY: all requirements satisfied\nURGENT: uses any expiring-soon ingredient"]:::rule
        end
    end

    subgraph "Domain Model Layer"
        ING["Ingredient (abstract)\nname • quantity • unit • toString()"]:::domain
        PER["Perishable\nexpiryDate • isExpiringSoon()"]:::domain
        NON["NonPerishable\n(no expiry date)"]:::domain

        REC["Recipe\nname • details"]:::domain
        REQ[("Requirements\nHashMap<ingredientKey, qty>")]:::datastore
    end

    subgraph "Runtime / Standard Library"
        JT["java.time\nLocalDate • ChronoUnit"]:::external
        JC["java.util\nArrayList • HashMap"]:::external
    end

    %% Primary control/data flow (vertical)
    U -->|"inputs_commands"| KA
    KA -->|"calls_engine_ops()"| KE
    KE -->|"returns_view_models\n(fridge+flags,recipe_matches)"| KA

    %% Engine owns in-memory collections
    KE -->|"contains"| INV
    KE -->|"contains"| RB

    %% Inventory holds ingredients (polymorphic)
    INV -->|"stores_instances"| ING
    PER -->|"extends"| ING
    NON -->|"extends"| ING

    %% Recipe book holds recipes; recipe contains requirements map
    RB -->|"stores"| REC
    REC -->|"contains"| REQ

    %% Algorithms use domain+collections+runtime APIs
    KE -->|"uses"| EXP
    KE -->|"uses"| MATCH
    EXP -->|"reads_dates_from"| PER
    EXP -->|"uses"| JT
    MATCH -->|"reads"| INV
    MATCH -->|"reads"| RB
    MATCH -->|"reads"| REQ
    INV -->|"uses"| JC
    RB -->|"uses"| JC
    REQ -->|"uses"| JC

    %% Click events (mapped components)
    click KA "https://github.com/jitashi-arora/smart-kitchen/blob/main/KitchenApp.java"
    click KE "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click ING "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click PER "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click NON "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click REC "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click REQ "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click INV "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click RB "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click EXP "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"
    click MATCH "https://github.com/jitashi-arora/smart-kitchen/blob/main/Models.java"

    %% Documentation (behavior/usage semantics)
    DOC["README\nCLI flows • READY/URGENT semantics • usage notes"]:::doc
    KA -.->|"guided_by"| DOC
    KE -.->|"behavior_defined_in"| DOC
    click DOC "https://github.com/jitashi-arora/smart-kitchen/blob/main/README.md"

    %% Styles
    classDef actor fill:#111827,stroke:#0f172a,color:#ffffff,stroke-width:1px
    classDef presentation fill:#1d4ed8,stroke:#1e3a8a,color:#ffffff,stroke-width:1px
    classDef service fill:#7c3aed,stroke:#4c1d95,color:#ffffff,stroke-width:1px
    classDef domain fill:#16a34a,stroke:#14532d,color:#ffffff,stroke-width:1px
    classDef datastore fill:#6b7280,stroke:#374151,color:#ffffff,stroke-width:1px
    classDef external fill:#f59e0b,stroke:#92400e,color:#111827,stroke-width:1px
    classDef rule fill:#ef4444,stroke:#7f1d1d,color:#ffffff,stroke-width:1px
    classDef doc fill:#0ea5e9,stroke:#075985,color:#ffffff,stroke-width:1px
```
