# foxriver-2005/smartcafe architecture

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

- Interactive diagram: https://gitdiagram.com/foxriver-2005/smartcafe
- Repository: https://github.com/foxriver-2005/smartcafe

## Overview

Based on your project file tree and README, SmartCafe is a Raspberry Pi–based food ordering and payment system designed to run on a Raspberry Pi 3B+. Its primary function is to allow users to interact with the system via a physical keypad and view information on a 16×2 LCD display. The system interacts with a local SQLite database for user verification, menu retrieval, and payment processing.

##### Main Components
- Hardware Interfaces:
- Keypad (handled in Keypad.py): Captures user inputs such as access codes and food item selection.
- LCD Display (handled in lcd.py): Displays menus, messages, and payment confirmations.
- Raspberry Pi 3B+: The central processing unit running the software, interfacing with the keypad, LCD via I2C, and the database.
- Software Core:
- Main Orchestration Module (main.py): Coordinates the overall workflow, including user verification, interacting with input/output modules, and database operations.
- Database (SQLite): Embedded in the Raspberry Pi and used for storing valid user codes, food menus, prices, account details, etc.

##### Relationships and Interactions
- The system begins with the user entering a code on the keypad.
- main.py listens to keypad input via Keypad.py and, upon completion (triggered by the '#' key), validates the input against the SQLite database.
- After successful authentication, main.py triggers the LCD display routines in lcd.py to present the menu.
- When a user selects food items using the keypad, main.py calculates the order total, performs payment processing, and updates the SQLite database (deducting funds) accordingly.
- All hardware-related interactions (display and keypad) are directly managed on the Raspberry Pi, which acts as the controlling unit.

##### Architectural Patterns and Design Principles
- Modular Programming: The project is split into distinct modules (Keypad.py, lcd.py, main.py) which encapsulate specific functionalities.
- Hardware Abstraction: Separate modules abstract hardware interactions (e.g., LCD and Keypad) from the main business logic.
- Database Integration: The design cleanly separates database interaction logic from user interface handling.
- IoT/Embedded System Considerations: Given the limited resources of the Raspberry Pi 3B+ and the use of direct GPIO/I2C communications, efficient hardware interfacing is emphasized.

##### Relevant Technologies and Frameworks
- Raspberry Pi 3B+ running Raspbian OS.
- Python 3 for scripting, with smbus for I2C communication with the LCD.
- SQLite for lightweight, local data storage.
- Standard GPIO and possibly serial communication libraries for keypad and UART-based peripherals.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User"):::user

    subgraph "Raspberry Pi 3B+"
        direction TB
        K("Keypad Module"):::hardware
        M("Main Controller"):::controller
        L("LCD Module"):::hardware
        S("SQLite Database"):::database
    end

    U -->|"enters_code"| K
    K -->|"sends_input"| M
    M -->|"displays_menu"| L
    M -->|"validates_order"| S

    click K "https://github.com/foxriver-2005/smartcafe/blob/main/Keypad.py"
    click M "https://github.com/foxriver-2005/smartcafe/blob/main/main.py"
    click L "https://github.com/foxriver-2005/smartcafe/blob/main/lcd.py"

    classDef user fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef hardware fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef controller fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef database fill:#ffebcc,stroke:#333,stroke-width:2px;
```
