How al3x2023/crisys works
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: main.py App wiring · MenuPage.tsx Menu page · ordenes.py Orders API · App.tsx SPA shell
Components 18
Backend
FastAPI application, domain routes, security, and SQLite persistence.
- App wiring · Creates the FastAPI app, mounts routes, configures CORS, and exposes live order updates.
backend/main.py - Products API · Serves the menu catalog and product data.
backend/routes/productos.py - Orders API · Creates orders, lists them, and updates order status.
backend/routes/ordenes.py - Admin API · Supports admin-facing operations and dashboard actions.
backend/routes/admin.py - Finance API · Finance-focused backend surface, likely behind role checks.
backend/routes/finanzas.py - Access control · Authorization and role protection for sensitive backend areas.
backend/security.py - DB setup · Creates the SQLite engine and session management for the app.
backend/database.py - Data models · Defines SQLAlchemy models mapped to the local restaurant database.
backend/models.py - restaurant.db · Local runtime database used as the system of record.
backend/restaurant.db
Frontend
React/Vite customer and operator interfaces.
- SPA shell · Top-level React application that routes between customer and operator screens.
frontend/src/App.tsx - UI bootstrap · Bootstraps the frontend application into the browser.
frontend/src/main.tsx - Menu page · Main ordering interface where users browse products and submit carts.
frontend/src/pages/MenuPage.tsx - Admin page · Live operational view for new orders and order status changes.
frontend/src/pages/AdminPage.tsx - Finance login · Entry screen for the finance workflow.
frontend/src/pages/FinanceLogin.tsx - Finance page · Authenticated finance-facing screen distinct from the customer ordering flow.
frontend/src/pages/FinancePage.tsx - Cart context · Holds cart state between product browsing and order submission.
frontend/src/context/CartContext.tsx - Product card · 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 · Generates per-table QR images that encode the menu URL with a mesa parameter.
qr_generator/generate_qr.py
Connections 25
- 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.