# leduonng/pos_cafe architecture

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

- Interactive diagram: https://gitdiagram.com/leduonng/pos_cafe
- Repository: https://github.com/leduonng/pos_cafe

## Overview

##### Main Components
- Frontend (Presentation Layer):
- Flutter/Dart based UI located mainly in the lib/views folder.
- Different screen categories: Admin (e.g., dashboard, bill management, configuration), POS (e.g., cart, order management, QR code processing), CRUD screens (e.g., ingredients, menu, users).
- Reusable UI Widgets (lib/views/widgets) and state management through Provider.
- Business Logic Layer:
- Controllers located in lib/controllers that encapsulate the application’s business logic for various functions such as orders, payments, customer points, and more.
- Data Models:
- Models in lib/models that represent the domain entities (e.g., orders, bills, users, inventory items). These serve as the data contracts through the system.
- Data & External Services:
- Database: MySQL integration (via lib/connect_mysql.py) provides persistent storage for the business data.
- Local Storage: Usage of Hive for local data storage as indicated in the README.
- Python Scripts: For data processing tasks—note the presence of scripts in assets/data (craw_data.py) and additional utility scripts (lib/notification.py).
- Assets & Resources:
- Static assets such as images, fonts, animations, and CSV files found under the assets directory.
- These resources serve the UI, analytics (charts), and animations (using Rive).

##### Relationships and Interactions
- The Frontend (UI screens) interacts with the Controllers to send user events and receive processed data.
- Controllers utilize Models to validate and manipulate data.
- Controllers then interact with the database layer via the MySQL connection script for CRUD operations.
- The application uses additional libraries and external services (e.g., go_router for navigation, hive for caching, PDF and printing libraries) connected to relevant layers.
- Python scripts and other data processing utilities may interact with the database and asset data to support backend functionalities.

##### Architectural Patterns and Technologies
- MVC/MVVM Pattern: The division into Views (UI screens), Controllers (business logic), and Models (data structures) reflect a clear separation of concerns.
- Service Integration: Note the integration with external libraries for animations (Rive), charting (fl_chart, syncfusion_flutter_charts), and printing functionalities.
- Data Pipeline: Inclusion of data processing scripts (Python) that feed into static assets or help pre-process data before insertion into MySQL.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend (Flutter UI) Subgraph
    subgraph "Frontend (Flutter UI)"
        A1["Authentication Screens"]:::frontend
        A2["POS Screens"]:::frontend
        A3["Admin Screens"]:::frontend
        A4["CRUD Screens"]:::frontend
        A5["Reusable UI Widgets"]:::frontend
    end

    %% Business Logic (Controllers) Subgraph
    subgraph "Business Logic (Controllers)"
        B1["Controllers"]:::controllers
    end

    %% Data Models Subgraph
    subgraph "Data Models"
        C1["Models"]:::models
    end

    %% Data & External Services Subgraph
    subgraph "Data & External Services"
        D1["Database (MySQL)"]:::database
        D2["Local Storage (Hive)"]:::external
        D3["External Libraries (Rive,PDF,Charting)"]:::external
        subgraph "Python Data Processing"
            D4a["craw_data.py"]:::external
            D4b["notification.py"]:::external
        end
    end

    %% Assets & Resources Subgraph
    subgraph "Assets & Resources"
        E1["Static Assets"]:::assets
    end

    %% Connections: Frontend to Controllers
    A1 --> B1
    A2 --> B1
    A3 --> B1
    A4 --> B1
    A5 --> B1

    %% Controllers to Models and External Services
    B1 --> C1
    C1 --> D1
    B1 --> D2
    B1 --> D3
    B1 --> D4a
    B1 --> D4b

    %% Python Data Processing to Database
    D4a --> D1

    %% Assets integration into Frontend
    E1 --> A5

    %% Click Events
    click A1 "https://github.com/leduonng/pos_cafe/tree/master/lib/views"
    click A5 "https://github.com/leduonng/pos_cafe/tree/master/lib/views/widgets"
    click B1 "https://github.com/leduonng/pos_cafe/tree/master/lib/controllers"
    click C1 "https://github.com/leduonng/pos_cafe/tree/master/lib/models"
    click D1 "https://github.com/leduonng/pos_cafe/blob/master/lib/connect_mysql.py"
    click D4a "https://github.com/leduonng/pos_cafe/blob/master/assets/data/craw_data.py"
    click D4b "https://github.com/leduonng/pos_cafe/blob/master/lib/notification.py"
    click E1 "https://github.com/leduonng/pos_cafe/tree/master/assets"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef controllers fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef models fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef assets fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
