How ema1322/lafileto-monorepo works
1. Repository shape
- This is a pnpm monorepo with three deployable apps: apps/client (public storefront SPA), apps/admin (back-office SPA), and apps/backend (Node/Express API).
- There are also small shared packages under packages/, plus repo-level docs, CI, and utility scripts.
2. Public client SPA
- apps/client is the customer-facing app for catalog browsing, cart, confirmation, and WhatsApp-driven ordering.
- It has a React-based shell (src/react) for the newer flow, plus some legacy/static UI assets and CSS under src/components and src/styles.
- The client consumes a public API through src/api/public.js and src/react/services/publicApi.js.
3. Admin SPA
- apps/admin is the management console for products, categories, users, roles/permissions, settings, and dashboard views.
- It is organized by feature folders in src/components, with a lot of UI-state/render split files for tables, modals, bindings, and state.
- It uses JWT-based authentication and RBAC gates to decide which module routes are visible or accessible.
4. Backend API boundary
- apps/backend is the system of record: an Express API under /api/v1 that exposes auth, users, roles, modules, settings, dashboard, products, categories, offers, and public catalog endpoints.
- The code is layered: routes → controllers → services → repositories, with validation and middleware at the edges.
- This boundary is where auth, authorization, persistence, and domain rules are enforced.
5. Persistence and data model
- The backend uses Prisma with MySQL as the database layer.
- Migrations show the main persisted entities: users, roles, modules, role-permissions, settings, categories, products, and offers.
- Seeds and migration history indicate the schema has evolved significantly, especially around admin RBAC, product modeling, and settings.
6. Authentication and authorization flow
- Login is handled by authController/authService and JWT helpers; the client/admin stores the token and rehydrates session state via GET /auth/me.
- Authorization is module-based RBAC: permissions are fetched from the backend and enforced both server-side (rbacGuard, requireAdminRole) and client-side via route guards.
- The admin flow depends on “hydrated” session state before navigation is allowed, which is a major architectural boundary.
7. Public vs admin data paths
- The client can operate against either JSON fixtures or the API, controlled by VITE_DATA_SOURCE=json|api; this supports gradual migration from static data to backend-backed data.
- The admin app also ships with JSON data files in public/data, which suggests local/mock-driven screens and test fixtures alongside live API usage.
- This dual-source approach is an important diagram element because it means not all UI reads go directly to MySQL-backed endpoints.
8. Domain services and repositories
- The backend business logic is concentrated in services such as productService, userService, categoryService, rbacService, settingsService, and dashboardService.
- Repositories isolate Prisma access for each aggregate, keeping controllers thin and making the database the only persistence boundary.
- Domain-specific helpers exist for offers, formatting, pagination, and site-config validation/sanitization.
9. Cross-cutting middleware and API safeguards
- The backend uses dedicated middleware for request IDs, timeouts, validation, login rate limiting, CORS, error handling, and RBAC enforcement.
- This means request processing is not just route handling; the API has a clear guardrail layer before business logic runs.
- For diagrams, these are the main horizontal concerns spanning all routes.
10. Shared UI and utility layer
- The admin and client each have their own UI stacks, but there are reusable packages for design and utilities under packages/.
- packages/shared-utils contains common formatting/text helpers; packages/shared-design supports UI consistency.
- These are smaller than the app boundaries, but they matter as shared dependencies that reduce duplication.
11. External integrations
- The public client’s ordering flow includes WhatsApp as an external handoff channel.
- The admin/backend architecture also relies on environment-configured CORS allowlists and JWT secrets, so runtime configuration is part of the deployment boundary.
- There is no evidence of a heavy third-party SaaS core; the main external dependency is MySQL, plus the browser/WhatsApp interaction on the public side.
12. Testing and quality boundaries
- Each app has its own tests: backend integration/smoke tests, client component/integration tests, and admin feature tests.
- CI runs lint/test workflows from the repo root, and Vite-based builds produce the SPA bundles.
- From an architecture perspective, tests mirror the same boundaries as runtime: public client, admin console, and backend API.
Main entry points: index.js Routes · pages Client pages · dashboard.js Dashboard · main.js Admin shell
Components 23
Shared
Reusable packages consumed by the apps.
- Shared utils · Common formatting and text helpers used across apps.
packages/shared-utils/src/index.js - Shared design · Reusable UI design package for visual consistency.
packages/shared-design/package.json
Backend
Express API boundary and its internal layers.
- API app · Express server composition, route mounting, and top-level middleware.
apps/backend/src/app.js - Routes · Versioned API surface for auth, users, roles, modules, settings, dashboard, products, categories, offers, and public endpoints.
apps/backend/src/routes/index.js - Edge guards · Request IDs, timeouts, validation, login rate limiting, CORS, auth, RBAC, and error handling.
apps/backend/src/middlewares - Auth flow · JWT login, session hydration, role checks, and admin access enforcement.
apps/backend/src/controllers/authController.js - Domain services · Product, category, user, RBAC, settings, dashboard, public catalog, and offers logic.
apps/backend/src/services - Repositories · Prisma-backed data access for users, roles, modules, settings, products, categories, offers, and permissions.
apps/backend/src/repositories - Prisma/MySQL · Schema, migrations, seeds, and MySQL persistence boundary.
apps/backend/prisma/schema.prisma
Client
Public storefront SPA and its React migration path.
- Client shell · Public storefront entry, legacy UI, and React shell composition.
apps/client/src/main.js - Client router · Routes between storefront home, products, cart, and confirmation flows.
apps/client/src/react/router/AppRouter.jsx - Client pages · Home, products, cart, confirm, and fallback views for the storefront.
apps/client/src/react/pages - Public API · Client-side adapter for public catalog and ordering data.
apps/client/src/api/public.js - Client state · Shell state, async resource handling, and cart/commercial helpers.
apps/client/src/react/state/shellState.js - WhatsApp handoff · Ordering handoff path used by the public storefront.
apps/client/src/utils/commercialContext.js
Admin
Back-office SPA and module-based management screens.
- Admin shell · Admin entry point, route bootstrap, and shared screen chrome.
apps/admin/src/main.js - Admin auth · JWT session hydration, route gating, and access-control helpers.
apps/admin/src/utils/auth.js - Users module · User management screens, modals, tabs, roles, and status rendering.
apps/admin/src/components/users/users.js - Products module · Product management tables, modals, bindings, and state.
apps/admin/src/components/products/products.js - Categories module · Category management screens and table/modal flow.
apps/admin/src/components/categories/categories.js - Settings module · Administrative settings screen and configuration editing.
apps/admin/src/components/settings/settings.js - Dashboard · Admin overview and summary views.
apps/admin/src/components/dashboard/dashboard.js - Mock data · Local JSON-backed admin data for offline or mock-driven screens.
apps/admin/public/data/products.json
Connections 28
- Client shell → Client router: bootstraps · Client shell initializes the React routing flow.
- Client router → Client pages: renders · Router selects the storefront page views.
- Client pages → Public API: loads data · Pages request public catalog and order data.
- Client pages → Client state: uses · Pages share shell, async, and cart state.
- Client pages → WhatsApp handoff: handoff · Confirmation flow can transfer ordering to WhatsApp.
- Public API → Routes: calls public API · Storefront data access targets the backend public endpoints.
- Admin shell → Admin auth: guards routes · Admin navigation depends on hydrated JWT/RBAC state.
- Admin shell → Dashboard: starts · Admin shell enters at the dashboard and module chrome.
- Dashboard → Users module: links to · Dashboard and navigation expose management modules.
- Dashboard → Products module: links to · Dashboard and navigation expose management modules.
- Dashboard → Categories module: links to · Dashboard and navigation expose management modules.
- Dashboard → Settings module: links to · Dashboard and navigation expose management modules.
- Users module → Mock data: can use · Admin screens can be backed by local JSON fixtures.
- Products module → Mock data: can use · Admin screens can be backed by local JSON fixtures.
- Users module → Routes: calls API · Management screens consume backend endpoints when live.
- Products module → Routes: calls API · Management screens consume backend endpoints when live.
- Categories module → Routes: calls API · Management screens consume backend endpoints when live.
- Settings module → Routes: calls API · Management screens consume backend endpoints when live.
- API app → Edge guards: applies · All requests pass through shared API safeguards.
- API app → Routes: mounts · Express app mounts the versioned route tree.
- Routes → Auth flow: exposes · Auth routes feed login and session hydration.
- Routes → Domain services: delegates · Route handlers defer business logic to services.
- Domain services → Repositories: persists via · Services isolate Prisma access behind repositories.
- Repositories → Prisma/MySQL: uses · Repositories read and write through Prisma/MySQL.
- Auth flow → Edge guards: protected by · Auth flows are constrained by rate limiting and validation.
- Domain services → Shared utils: formats with · Domain services share formatting and text helpers.
- Client pages → Shared design: styled by · Client UI can reuse shared design assets.
- Admin shell → Shared design: styled by · Admin UI can reuse shared design assets.