How ajperezcossio/diagramas works
1. System shape
MiniMarketWeb is a single-page React application for a minimarket business, not a separate frontend/backend monolith. The runtime architecture is: browser UI → client state → service layer → Supabase/PostgreSQL. Most business logic lives in the frontend services and hooks, with Supabase acting as the external data/auth backend.
2. Top-level partitioning
The codebase is organized by feature and role. src/pages/ contains role-specific screens for:
• cliente for shopping and loyalty
• empleado for operations and admin workflows
• cajero for sales processing
• repartidor for delivery handling
• root pages for login/register/404
This role-based partitioning is the main structural boundary an architecture diagram should show.
3. Presentation layer
src/components/ holds cross-cutting UI pieces like Layout, ProtectedRoute, LoadingScreen, and DataDiagnostics. src/pages/** contains the actual screens and some local subcomponents/modals. Routing is centralized in src/App.jsx and bootstrapped from src/main.jsx.
4. State management
Application state is handled with Zustand stores in src/store/:
• useAuthStore for session, profile, and role
• useCartStore for shopping cart state and persistence
• useThemeStore for UI theme
These stores are the main client-side coordination layer between pages and services. Session/cart state is persisted locally, so the app can survive reloads without re-fetching everything.
5. Business logic / service layer
src/lib/ is the core business layer. It contains focused services for:
• products/data access: dataService.js
• loyalty: lealtadService.js
• promotions: promocionesService.js
• returns: devolucionesService.js
• payroll: nominaService.js
• shifts: turnosService.js
These services encapsulate the business rules used by multiple screens and keep pages thinner. currencyFormatter.js is a shared utility, not a domain service.
6. Backend boundary
The only backend integration visible in the repo is Supabase via src/lib/supabase.js. That file is important because it abstracts between a real Supabase client and a mock/local fallback for development/testing. So the architectural boundary is not “frontend talks to custom API,” but “frontend services talk directly to Supabase.”
7. Authentication and authorization flow
Authentication is handled through useAuthStore and enforced at the routing layer with ProtectedRoute. The app uses RBAC with roles like client, employee, admin, cashier, and delivery person. After login, the store loads the user profile, persists session state, and routes the user to the correct dashboard.
8. Core business workflows
The most important data flows are:
• Catalog → Cart → Promotions → Sales → Loyalty
• Sales → Delivery/Reparto for home delivery orders
• Sales → Returns for post-sale returns
• Attendance/Shifts → Payroll for HR calculations
These are the main cross-module dependencies and should be central in any system diagram.
9. Domain modules reflected in the UI
The UI exposes several business capabilities that map to separate bounded areas:
• product/inventory management
• checkout and payment processing
• loyalty points and redemptions
• promotional pricing and coupons
• delivery assignment and tracking
• returns approval and reimbursement
• attendance, shifts, and payroll
• task assignment and operational dashboards
Even though everything is in one frontend app, these modules are logically distinct and interact through services and shared data tables.
10. Database and schema assets
The database/ folder contains SQL scripts such as schema_extensiones.sql and actualizar_precios_bs.sql. This indicates the project expects a structured relational schema in Supabase/PostgreSQL, with extension tables for loyalty, promotions, payroll, and other operational areas. Those scripts are part of the data-definition boundary, not application runtime code.
11. Testing structure
The repo has a mature test layout under test/:
• unit tests for stores, services, and utilities
• integration tests for auth, cart, loyalty, returns, and protected routes
• e2e flows for login, registration, and cart
This suggests the architecture is designed around testable service/store boundaries rather than only UI snapshot testing.
12. Deployment and infrastructure
vercel.json shows the production delivery target is Vercel. The infra/ folder contains Vagrant/Ansible scripts, but the README suggests this is supplemental infrastructure rather than the main runtime path. So the production architecture is: static React bundle on Vercel, Supabase as backend/data, with optional local mock and infra tooling for setup.
13. What to emphasize in a diagram
A faithful architecture diagram should show:
• Browser SPA as the main entry point
• Role-based route guards
• Zustand as the shared client state hub
• Service layer as the business logic boundary
• Supabase/PostgreSQL as external persistence/auth
• Separate domain areas for sales, loyalty, promotions, returns, delivery, HR, and inventory
• SQL migration/assets as offline schema support
• Vercel as deployment host
14. Important architectural nuance
This repository is best understood as a frontend-centric business application with backend-as-a-service, not as a traditional multi-tier server app. The “backend” responsibilities are largely pushed into Supabase and frontend service modules, while the React app orchestrates workflows and enforces role-based access.
Main entry points: App.jsx App · supabase.js Supabase · Dashboard.jsx Cliente · dataService.js Data Service
Components 24
Presentation
React entry, routing, layouts, and role screens
- main.jsx · Vite entrypoint that mounts the app
MiniMarketWeb-final/src/main.jsx - App · Central route and role navigation setup
MiniMarketWeb-final/src/App.jsx - Layout · Shared application shell and navigation chrome
MiniMarketWeb-final/src/components/Layout.jsx - Protected Route · Route guard enforcing session and role access
MiniMarketWeb-final/src/components/ProtectedRoute.jsx - Auth Pages · Login and registration entry screens
MiniMarketWeb-final/src/pages/LoginPage.jsx - Cliente · Shopping, cart, loyalty, orders, and profile flows
MiniMarketWeb-final/src/pages/cliente/Dashboard.jsx - Empleado · Inventory, tasks, attendance, returns, and admin workflows
MiniMarketWeb-final/src/pages/empleado/Dashboard.jsx - Cajero · Sales processing and payment handling
MiniMarketWeb-final/src/pages/cajero/Cajero.jsx - Repartidor · Delivery assignment, routes, and shift views
MiniMarketWeb-final/src/pages/repartidor/Repartidor.jsx
State
Client-side coordination with persisted stores
- Auth Store · Session, profile, and role state with persistence
MiniMarketWeb-final/src/store/useAuthStore.js - Cart Store · Cart contents, checkout state, and persistence
MiniMarketWeb-final/src/store/useCartStore.js - Theme Store · UI theme state
MiniMarketWeb-final/src/store/useThemeStore.js
Services
Business logic and domain workflows
- Data Service · Shared data access for products and core entities
MiniMarketWeb-final/src/lib/dataService.js - Promotions · Promotional pricing and coupon rules
MiniMarketWeb-final/src/lib/promocionesService.js - Loyalty · Points, redemptions, and loyalty rules
MiniMarketWeb-final/src/lib/lealtadService.js - Returns · Return approval and reimbursement logic
MiniMarketWeb-final/src/lib/devolucionesService.js - Payroll · Payroll calculations and employee compensation workflows
MiniMarketWeb-final/src/lib/nominaService.js - Shifts · Shift scheduling and attendance coordination
MiniMarketWeb-final/src/lib/turnosService.js - Data Hooks · Initialization and data-loading coordination layer
MiniMarketWeb-final/src/hooks/useInitializeData.js
Data Boundary
Supabase backend and database assets
- Supabase · Supabase client with mock/local fallback
MiniMarketWeb-final/src/lib/supabase.js - SQL Assets · Database schema extensions and price update scripts
MiniMarketWeb-final/database/schema_extensiones.sql
Delivery
Build, deployment, and test assets
Connections 42
- main.jsx → App: boots · Application entry mounts the router
- App → Layout: wraps · Routes are rendered within the shared shell
- App → Protected Route: guards · Private routes are protected by role and session checks
- App → Auth Pages: exposes · Public entry screens for login and registration
- App → Cliente: routes · Client role dashboards and workflows
- App → Empleado: routes · Employee and admin workflows
- App → Cajero: routes · Cashier checkout screens
- App → Repartidor: routes · Delivery role screens
- Protected Route → Auth Store: reads · Access control depends on session and role state
- Layout → Theme Store: uses · Shell reacts to theme state
- Layout → Auth Store: uses · Shell adapts to authenticated user context
- Cliente → Cart Store: reads/writes · Shopping and checkout use shared cart state
- Cliente → Data Service: loads · Catalog and product data are fetched through services
- Cliente → Loyalty: uses · Client loyalty views and redemptions
- Cliente → Promotions: uses · Promotion-aware shopping flows
- Cliente → Returns: uses · Customer return requests and status
- Empleado → Data Service: manages · Inventory, products, users, and operational data
- Empleado → Returns: uses · Return processing workflows
- Empleado → Payroll: uses · Payroll administration screens
- Empleado → Shifts: uses · Attendance and shift management
- Cajero → Cart Store: uses · Checkout state and sale composition
- Cajero → Data Service: sells · Sales processing depends on shared product data
- Cajero → Promotions: applies · Promotions affect pricing at checkout
- Cajero → Loyalty: awards · Sales feed loyalty points and redemptions
- Repartidor → Shifts: uses · Shift and attendance views for delivery staff
- Repartidor → Data Service: tracks · Delivery orders and assignments use shared data
- Data Hooks → Data Service: orchestrates · Data loading and initialization flow
- Data Hooks → Auth Store: initializes · Bootstraps session and profile state
- Data Service → Supabase: reads/writes · Core data access goes through Supabase
- Promotions → Supabase: reads/writes · Promotion rules and tables live in Supabase
- Loyalty → Supabase: reads/writes · Loyalty data is stored remotely
- Returns → Supabase: reads/writes · Return records and reimbursements persist remotely
- Payroll → Supabase: reads/writes · Payroll calculations use backend data
- Shifts → Supabase: reads/writes · Shift and attendance records persist remotely
- Supabase → SQL Assets: schema · Database behavior is supported by SQL assets
- Tests → Auth Store: verifies · Store behavior and auth flow coverage
- Tests → Cart Store: verifies · Cart persistence and business logic coverage
- Tests → Promotions: verifies · Promotion rules are covered by tests
- Tests → Loyalty: verifies · Loyalty workflows are covered by tests
- Tests → Protected Route: verifies · Route access control is tested
- Vercel → main.jsx: hosts · Production deployment serves the SPA bundle
- Infra → Supabase: supports · Local setup and environment tooling support the backend boundary