# al3x2023/crisys architecture

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

- Interactive diagram: https://gitdiagram.com/al3x2023/crisys
- Repository: https://github.com/al3x2023/crisys

## Overview

1. This repository is split into three main application areas plus one utility: a FastAPI backend, a React/Vite frontend, a QR-code generator script, and a SQLite database file used by the backend at runtime.

2. The backend is the system of record. `backend/main.py` wires the FastAPI app together, mounts the API routes, enables CORS for the local frontend, and exposes the WebSocket channel for live order updates.

3. Persistence is local and lightweight: SQLAlchemy models in `backend/models.py` map to `backend/restaurant.db`, with `backend/database.py` handling engine/session setup. The README indicates startup seeding for demo tables and products.

4. The backend is organized by domain routes:
   - `routes/productos.py` serves the menu catalog.
   - `routes/ordenes.py` creates orders, lists orders, and updates order status.
   - `routes/admin.py` appears to support admin-facing operations.
   - `routes/finanzas.py` suggests a separate finance area.
   `backend/security.py` indicates auth/role protection, most likely around admin/finance access.

5. The primary customer flow starts from a QR code. The QR generator in `qr_generator/generate_qr.py` produces per-table images that encode a frontend URL with a `mesa` query parameter, so the table number becomes part of the ordering context.

6. The customer UI is a React single-page app in `frontend/src`. The key entry points are `main.tsx` and `App.tsx`, with page-level components for the menu, admin dashboard, and finance screens. The menu page is the order-taking interface; the admin page is the operational dashboard; `FinanceLogin.tsx` and `FinancePage.tsx` point to a separate authenticated finance workflow.

7. Cart state is held on the client in `frontend/src/context/CartContext.tsx`. That context is the boundary between product browsing and order submission: product cards add items to the cart, and the menu page converts the cart into an order payload sent to the backend.

8. Real-time updates are a major architectural element. The backend broadcasts order events over `ws://.../ws/ordenes`, and the frontend admin view listens for new orders and status changes so the dashboard stays current without polling.

9. The data lifecycle is straightforward: product catalog is fetched from the backend, the customer selects items, the frontend POSTs a new order, the backend persists it in SQLite, then pushes a WebSocket event so the admin side sees it immediately.

10. Order state management is central to the operational workflow. Orders move through statuses such as `pendiente`, `en_proceso`, and `entregado`, and those transitions are exposed through REST plus reflected live in the dashboard.

11. The finance area looks like a separate functional boundary from ordering. Based on the filenames, it likely uses backend auth/security and dedicated finance routes rather than sharing the open menu flow, so it should be drawn as a protected subsystem distinct from customer ordering and kitchen/admin operations.

12. Infrastructure is intentionally local-first: FastAPI on Python 3.11+, React/Vite/Tailwind on Node 20+/22+, SQLite for storage, and WebSockets for live signaling. There is no evidence of external cloud services in the core architecture beyond demo image URLs for seeded products.

13. For an architecture diagram, the clearest boundaries are:
   - QR generator → frontend menu URL
   - Frontend customer SPA ↔ backend REST API
   - Backend ↔ SQLite
   - Backend → WebSocket broadcast → admin dashboard
   - Protected finance/admin flows gated by `security.py` and separate routes/pages

Main entry points: [`backend/main.py`](https://github.com/al3x2023/crisys/blob/main/backend/main.py) (App wiring), [`frontend/src/pages/MenuPage.tsx`](https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/MenuPage.tsx) (Menu page), [`backend/routes/ordenes.py`](https://github.com/al3x2023/crisys/blob/main/backend/routes/ordenes.py) (Orders API), [`frontend/src/App.tsx`](https://github.com/al3x2023/crisys/blob/main/frontend/src/App.tsx) (SPA shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_main["App wiring<br/>FastAPI entrypoint<br/>[main.py]"]
  node_backend_routes_productos["Products API<br/>catalog route<br/>[productos.py]"]
  node_backend_routes_ordenes["Orders API<br/>order workflow<br/>[ordenes.py]"]
  node_backend_routes_admin["Admin API<br/>ops route<br/>[admin.py]"]
  node_backend_routes_finanzas["Finance API<br/>protected route<br/>[finanzas.py]"]
  node_backend_security["Access control<br/>auth/roles<br/>[security.py]"]
  node_backend_database["DB setup<br/>SQLAlchemy config<br/>[database.py]"]
  node_backend_models["Data models<br/>ORM schema<br/>[models.py]"]
  node_backend_db_file[("restaurant.db<br/>SQLite storage<br/>[restaurant.db]")]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["SPA shell<br/>React app<br/>[App.tsx]"]
  node_frontend_main["UI bootstrap<br/>Vite entrypoint<br/>[main.tsx]"]
  node_frontend_menu["Menu page<br/>customer UI<br/>[MenuPage.tsx]"]
  node_frontend_admin["Admin page<br/>ops dashboard<br/>[AdminPage.tsx]"]
  node_frontend_finance_login["Finance login<br/>auth screen<br/>[FinanceLogin.tsx]"]
  node_frontend_finance_page["Finance page<br/>finance UI<br/>[FinancePage.tsx]"]
  node_frontend_cart["Cart context<br/>client state<br/>[CartContext.tsx]"]
  node_frontend_product_card["Product card<br/>product UI<br/>[ProductCard.tsx]"]
end

subgraph group_qr["QR Tools"]
  node_qr_generator["QR generator<br/>script<br/>[generate_qr.py]"]
end

node_qr_generator -->|"encodes menu URL"| node_frontend_menu
node_frontend_main -->|"mounts"| node_frontend_app
node_frontend_app -->|"routes to"| node_frontend_menu
node_frontend_app -->|"routes to"| node_frontend_admin
node_frontend_app -->|"routes to"| node_frontend_finance_login
node_frontend_finance_login -->|"opens"| node_frontend_finance_page
node_frontend_menu -->|"uses"| node_frontend_cart
node_frontend_product_card -->|"adds items"| node_frontend_cart
node_frontend_menu -->|"fetches catalog"| node_backend_routes_productos
node_frontend_menu -->|"creates order"| node_backend_routes_ordenes
node_frontend_admin -->|"manages orders"| node_backend_routes_ordenes
node_frontend_admin -->|"listens websocket"| node_backend_main
node_frontend_finance_page -->|"uses"| node_backend_routes_finanzas
node_backend_main -->|"mounts"| node_backend_routes_productos
node_backend_main -->|"mounts"| node_backend_routes_ordenes
node_backend_main -->|"mounts"| node_backend_routes_admin
node_backend_main -->|"mounts"| node_backend_routes_finanzas
node_backend_main -->|"protects"| node_backend_security
node_backend_routes_productos -->|"reads"| node_backend_database
node_backend_routes_ordenes -->|"persists"| node_backend_models
node_backend_models -->|"maps to"| node_backend_db_file
node_backend_database -->|"connects to"| node_backend_db_file
node_backend_routes_admin -->|"gated by"| node_backend_security
node_backend_routes_finanzas -->|"gated by"| node_backend_security
node_backend_routes_ordenes -->|"broadcasts events"| node_backend_main

click node_backend_main "https://github.com/al3x2023/crisys/blob/main/backend/main.py"
click node_backend_routes_productos "https://github.com/al3x2023/crisys/blob/main/backend/routes/productos.py"
click node_backend_routes_ordenes "https://github.com/al3x2023/crisys/blob/main/backend/routes/ordenes.py"
click node_backend_routes_admin "https://github.com/al3x2023/crisys/blob/main/backend/routes/admin.py"
click node_backend_routes_finanzas "https://github.com/al3x2023/crisys/blob/main/backend/routes/finanzas.py"
click node_backend_security "https://github.com/al3x2023/crisys/blob/main/backend/security.py"
click node_backend_database "https://github.com/al3x2023/crisys/blob/main/backend/database.py"
click node_backend_models "https://github.com/al3x2023/crisys/blob/main/backend/models.py"
click node_backend_db_file "https://github.com/al3x2023/crisys/blob/main/backend/restaurant.db"
click node_frontend_app "https://github.com/al3x2023/crisys/blob/main/frontend/src/App.tsx"
click node_frontend_main "https://github.com/al3x2023/crisys/blob/main/frontend/src/main.tsx"
click node_frontend_menu "https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/MenuPage.tsx"
click node_frontend_admin "https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/AdminPage.tsx"
click node_frontend_finance_login "https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/FinanceLogin.tsx"
click node_frontend_finance_page "https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/FinancePage.tsx"
click node_frontend_cart "https://github.com/al3x2023/crisys/blob/main/frontend/src/context/CartContext.tsx"
click node_frontend_product_card "https://github.com/al3x2023/crisys/blob/main/frontend/src/components/ProductCard.tsx"
click node_qr_generator "https://github.com/al3x2023/crisys/blob/main/qr_generator/generate_qr.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_main,node_backend_routes_productos,node_backend_routes_ordenes,node_backend_routes_admin,node_backend_routes_finanzas,node_backend_security,node_backend_database,node_backend_models,node_backend_db_file toneBlue
class node_frontend_app,node_frontend_main,node_frontend_menu,node_frontend_admin,node_frontend_finance_login,node_frontend_finance_page,node_frontend_cart,node_frontend_product_card toneAmber
class node_qr_generator toneMint
```

## Components

### Backend

FastAPI application, domain routes, security, and SQLite persistence.

- [App wiring](https://github.com/al3x2023/crisys/blob/main/backend/main.py): FastAPI entrypoint · Creates the FastAPI app, mounts routes, configures CORS, and exposes live order updates. · `backend/main.py`
- [Products API](https://github.com/al3x2023/crisys/blob/main/backend/routes/productos.py): catalog route · Serves the menu catalog and product data. · `backend/routes/productos.py`
- [Orders API](https://github.com/al3x2023/crisys/blob/main/backend/routes/ordenes.py): order workflow · Creates orders, lists them, and updates order status. · `backend/routes/ordenes.py`
- [Admin API](https://github.com/al3x2023/crisys/blob/main/backend/routes/admin.py): ops route · Supports admin-facing operations and dashboard actions. · `backend/routes/admin.py`
- [Finance API](https://github.com/al3x2023/crisys/blob/main/backend/routes/finanzas.py): protected route · Finance-focused backend surface, likely behind role checks. · `backend/routes/finanzas.py`
- [Access control](https://github.com/al3x2023/crisys/blob/main/backend/security.py): auth/roles · Authorization and role protection for sensitive backend areas. · `backend/security.py`
- [DB setup](https://github.com/al3x2023/crisys/blob/main/backend/database.py): SQLAlchemy config · Creates the SQLite engine and session management for the app. · `backend/database.py`
- [Data models](https://github.com/al3x2023/crisys/blob/main/backend/models.py): ORM schema · Defines SQLAlchemy models mapped to the local restaurant database. · `backend/models.py`
- [restaurant.db](https://github.com/al3x2023/crisys/blob/main/backend/restaurant.db): SQLite storage · Local runtime database used as the system of record. · `backend/restaurant.db`

### Frontend

React/Vite customer and operator interfaces.

- [SPA shell](https://github.com/al3x2023/crisys/blob/main/frontend/src/App.tsx): React app · Top-level React application that routes between customer and operator screens. · `frontend/src/App.tsx`
- [UI bootstrap](https://github.com/al3x2023/crisys/blob/main/frontend/src/main.tsx): Vite entrypoint · Bootstraps the frontend application into the browser. · `frontend/src/main.tsx`
- [Menu page](https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/MenuPage.tsx): customer UI · Main ordering interface where users browse products and submit carts. · `frontend/src/pages/MenuPage.tsx`
- [Admin page](https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/AdminPage.tsx): ops dashboard · Live operational view for new orders and order status changes. · `frontend/src/pages/AdminPage.tsx`
- [Finance login](https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/FinanceLogin.tsx): auth screen · Entry screen for the finance workflow. · `frontend/src/pages/FinanceLogin.tsx`
- [Finance page](https://github.com/al3x2023/crisys/blob/main/frontend/src/pages/FinancePage.tsx): finance UI · Authenticated finance-facing screen distinct from the customer ordering flow. · `frontend/src/pages/FinancePage.tsx`
- [Cart context](https://github.com/al3x2023/crisys/blob/main/frontend/src/context/CartContext.tsx): client state · Holds cart state between product browsing and order submission. · `frontend/src/context/CartContext.tsx`
- [Product card](https://github.com/al3x2023/crisys/blob/main/frontend/src/components/ProductCard.tsx): product UI · Adds individual products into the cart from the menu. · `frontend/src/components/ProductCard.tsx`

### QR Tools

Script that generates table-specific QR codes for the ordering flow.

- [QR generator](https://github.com/al3x2023/crisys/blob/main/qr_generator/generate_qr.py): script · Generates per-table QR images that encode the menu URL with a mesa parameter. · `qr_generator/generate_qr.py`

## Connections

- QR generator → Menu page: encodes menu URL · Produces table-specific QR codes that point customers to the ordering page.
- UI bootstrap → SPA shell: mounts · Bootstraps the SPA shell into the browser.
- SPA shell → Menu page: routes to · Provides the customer ordering experience.
- SPA shell → Admin page: routes to · Provides the admin dashboard.
- SPA shell → Finance login: routes to · Starts the finance access flow.
- Finance login → Finance page: opens · Leads into the authenticated finance screen.
- Menu page → Cart context: uses · Reads and updates cart state while customers build an order.
- Product card → Cart context: adds items · Product cards push selected items into the shared cart context.
- Menu page → Products API: fetches catalog · Loads menu data from the backend.
- Menu page → Orders API: creates order · Submits the cart as a new order.
- Admin page → Orders API: manages orders · Reads and updates order state through the backend.
- Admin page → App wiring: listens websocket · Consumes live order events from the backend broadcast channel.
- Finance page → Finance API: uses · Calls finance-specific backend operations.
- App wiring → Products API: mounts · Registers catalog routes on the FastAPI app.
- App wiring → Orders API: mounts · Registers order routes on the FastAPI app.
- App wiring → Admin API: mounts · Registers admin routes on the FastAPI app.
- App wiring → Finance API: mounts · Registers finance routes on the FastAPI app.
- App wiring → Access control: protects · Applies authorization controls around sensitive endpoints.
- Products API → DB setup: reads · Loads catalog data through the database layer.
- Orders API → Data models: persists · Uses ORM models to create and update orders.
- Data models → restaurant.db: maps to · ORM entities are stored in the local SQLite database file.
- DB setup → restaurant.db: connects to · Engine and sessions target the restaurant database.
- Admin API → Access control: gated by · Admin operations are protected by access control.
- Finance API → Access control: gated by · Finance operations are protected by access control.
- Orders API → App wiring: broadcasts events · Order status changes are pushed to the live websocket channel.
