/admin/*), lazy loading, and its own layout components. No storefront Header or Footer renders inside admin routes.
Architecture
Code Split Chunk
All admin pages are bundled into a single lazy-loaded chunk named
admin-panel, configured in vite.config.ts via manualChunks. The chunk only loads when a user first navigates to /admin.AdminGuard
Every admin route is wrapped with
AdminGuard, which verifies the authenticated user exists in the admin_users table. Non-admins are redirected; unauthenticated users go to /login.AdminLayout
Admin pages render inside
AdminLayout — a distinct shell with a collapsible sidebar, breadcrumb header, omnisearch, and system-pulse indicator. No storefront chrome is present.Supabase RLS
Row Level Security policies on every table ensure admin operations are gated at the database level, not only in the UI.
How Access Works
User logs in
The user authenticates via Supabase Auth.
AuthContext loads their session and customer_profiles record.Navigate to /admin
React Router renders
AdminGuard wrapping AdminLayout. The guard calls checkIsAdmin(user.id) from admin-auth.service.ts.The guard has an 8-second timeout safety net. If Supabase does not respond within that window, the user sees a retry dialog rather than an infinite spinner.
Granting Admin Access
Insert a row intoadmin_users where id matches the user’s Supabase Auth UUID:
Admin Routes
All routes are prefixed with/admin and rendered inside AdminGuard + AdminLayout.
| Route | Component | Description |
|---|---|---|
/admin | AdminDashboard | Main dashboard — metrics, charts, AI insights |
/admin/products | AdminProducts | Product list with filtering and bulk actions |
/admin/products/new | AdminProductForm | Create a new product |
/admin/products/:id | AdminProductForm | Edit an existing product |
/admin/orders | AdminOrders | Order management with Kanban and list views |
/admin/categories | AdminCategories | Category tree management |
/admin/customers | AdminCustomers | Customer directory |
/admin/customers/:id | AdminCustomerDetails | Full customer profile and history |
/admin/coupons | AdminCoupons | Coupon CRUD |
/admin/settings | AdminSettings | Store configuration |
/admin/monitoring | AdminMonitoring | System health and live users |
AdminLayout Structure
The sidebar is organized into five sections:| Section | Items |
|---|---|
| Operaciones | Dashboard, Pedidos, Clientes |
| Inventario | Productos, Categorías, Marcas, Etiquetas, Atributos, Batch Manager |
| Vitrina | Editor Home, MegaHero Sliders, Ofertas Flash, Testimonios |
| Retención | V-Coins (Lealtad), Cupones, Ruleta de Premios |
| Sistema | Cesarin OS, Configuración, Monitoreo |
- Green dot →
optimal - Amber dot →
busy(>10 active orders) - Red dot →
alert(any products with stock < 5)
Code Splitting Configuration
admin-panel chunk is loaded lazily via React.lazy() in App.tsx, so the admin JavaScript is never downloaded by regular storefront visitors.