How iamluissosa/lmcu works
1. Repository shape
- This is a Turborepo monorepo with three product apps: apps/web (Next.js dashboard), apps/mobile (Expo/React Native app), and apps/api (NestJS backend).
- Shared code lives in packages/*, especially database, DTOs, UI, TS config, and lint config.
2. Primary system boundary
- The backend API is the central business system. Both the web dashboard and mobile app are thin clients that fetch and mutate data through it.
- The API owns authentication, authorization, business rules, and persistence access.
3. Web client
- apps/web is a Next.js app that implements the desktop/admin experience for sales, accounting, inventory, settings, reports, and printing.
- It includes route-based pages under app/dashboard/** and app/print/**, plus reusable UI components like dashboard cards, quote modals, and document format editors.
- It uses a local lib/api-client.ts to talk to the API and lib/supabase.ts for auth integration.
4. Mobile client
- apps/mobile is an Expo app focused on operational views: commissions, quotes, dashboard, and settings.
- It uses custom hooks (useAuth, useDashboard, useQuotes, useCommissions) and a shared API client in src/lib/api-client.ts.
- The mobile app stores auth state locally in src/store/auth.store.ts and is set up for OTA updates via GitHub Actions and EAS.
5. API service
- apps/api is a NestJS service organized into feature modules: auth, users, companies, suppliers, products, sales, purchases, accounting/fiscal books, commissions, reports, events, settings, exchange rates, and more.
- Each feature typically has a controller and service; some have DTOs and entities.
- The API also contains global HTTP concerns: JWT auth guard, permissions guard/decorator, exception filter, and response transform interceptor.
6. Authentication and authorization
- Auth is based on Supabase: the backend has a SupabaseStrategy, and the web app has a Supabase client helper.
- Access control is enforced in the API with JWT-based auth plus permission checks, so business routes are protected server-side rather than relying on the clients.
7. Persistence layer
- Database access is handled through Prisma in apps/api/src/prisma and shared database package packages/database.
- packages/database/prisma/schema.prisma and its migrations define the canonical data model for the domain.
- The backend services call Prisma through a dedicated PrismaService, with some feature-specific repositories where needed.
8. Domain areas modeled in the backend
- The codebase is heavily ERP/accounting-oriented: sales quotes, sales orders, invoices, purchase orders, purchase bills, direct expenses, goods receipts, commissions, fiscal books, ISLR/IVA retention, departments, service categories, and document formats.
- There are also supporting master-data modules such as clients, suppliers, products, companies, users, expense categories, exchange rates, and dashboard settings.
- This suggests a single operational database feeding both transactional workflows and reporting/printing.
9. Cross-cutting business flows
- Several modules are not simple CRUD: commissions include a calculator and listener service; fiscal books and ISLR modules handle tax/accounting calculations; reports aggregate data; document formats influence generated printable output.
- The presence of controllers for “print” in the web app indicates the API supplies document-ready records, while the browser renders final output.
10. Shared packages
- packages/ui provides reusable React components shared by apps.
- packages/dtos and packages/types centralize type contracts used across the repo, reducing duplication between client and server.
- packages/eslint-config and packages/typescript-config standardize build and code-quality behavior across all workspaces.
11. Operational tooling and maintenance
- The repo includes Prisma migrations, seed scripts, and utility scripts for backfills and data fixes, indicating database evolution is handled as part of the codebase.
- There are also ad hoc scripts for role fixes and user checks, which are operational tools rather than product features.
- apps/api/check-db.ts and backfill scripts suggest direct support for database validation and data repair.
12. Deployment/runtime boundaries
- The project is containerized with a root Dockerfile and docker-compose.yml.
- Hosting config files point to common PaaS targets such as Railway and Render.
- Mobile distribution has a dedicated GitHub Actions workflow for OTA updates, while the web app is built as a Next.js deployment target.
13. Documentation and auxiliary assets
- docs/user-manual is a static documentation site separate from the transactional apps.
- It likely serves end-user guidance rather than participating in runtime data flow.
- The API also includes trained OCR language files, hinting at document-processing or extraction features in the broader system.
14. High-level data flow
- User interacts with web or mobile UI → client calls API over HTTP → NestJS authenticates and authorizes → service layer applies domain logic → Prisma reads/writes the database → response is transformed and returned to the client.
- For some workflows, the API also performs internal event/listener processing before persisting or aggregating results for reports and print views.
Main entry points: app.module.ts API app · page.tsx Web app · App.tsx Mobile app · auth.module.ts Auth
Components 18
Applications
Runtime apps and user-facing clients
- Web app · Desktop/admin client for sales, accounting, inventory, settings, reports, and printing
apps/web/app/dashboard/page.tsx - Mobile app · Operational mobile client for dashboard, quotes, commissions, and settings
apps/mobile/App.tsx - API app · Central business service for auth, domain logic, and persistence
apps/api/src/app.module.ts - Auth · Supabase-based authentication and server-side access control
apps/api/src/modules/auth/auth.module.ts - Sales · Quotes, orders, and invoices workflows
apps/api/src/modules/sales/sales.module.ts - Accounting · Purchases, bills, payments, fiscal books, and tax handling
apps/api/src/modules/fiscal-books/fiscal-books.module.ts - Master data · Companies, users, clients, suppliers, products, settings, and related reference data
apps/api/src/modules/companies/companies.module.ts - Commissions · Commission calculation and event/listener processing
apps/api/src/modules/commissions/commissions.module.ts - Reports · Aggregated reporting and event data for the clients
apps/api/src/modules/reports/reports.module.ts - Prisma service · Backend database access through the Prisma service
apps/api/src/prisma/prisma.service.ts
Shared Packages
Reusable contracts, UI, and config
- UI kit · Reusable components shared across apps
packages/ui/src/button.tsx - DTOs · Cross-app data transfer types and auth contracts
packages/dtos/src/index.ts - Types · Common type definitions used across the workspace
packages/types/src/index.ts - Tooling config · Shared linting and TypeScript presets
packages/typescript-config/base.json
Operations
Database evolution, deployment, and support assets
- DB schema · Canonical domain model and migrations for the operational database
packages/database/prisma/schema.prisma - Migrations & seed · Schema migrations, seed scripts, and backfills
packages/database/prisma/seed.ts - User manual · Standalone documentation site for end users
docs/user-manual/index.html - Deploy runtime · Container and hosting configuration for app deployment
Dockerfile
Connections 23
- Web app → API app: HTTP API · Web dashboard fetches and mutates server data
- Mobile app → API app: HTTP API · Mobile client uses the backend for operational workflows
- Web app → UI kit: renders · Web app reuses shared UI primitives
- Mobile app → UI kit: renders · Mobile app shares React UI building blocks where applicable
- Web app → DTOs: contracts · Web client consumes shared request/response shapes
- Mobile app → DTOs: contracts · Mobile client consumes shared request/response shapes
- API app → Auth: includes · Backend wires in authentication and authorization
- API app → Sales: includes · Backend exposes sales workflows
- API app → Accounting: includes · Backend exposes accounting and fiscal workflows
- API app → Master data: includes · Backend manages master data and settings
- API app → Commissions: includes · Backend handles commission calculations and listeners
- API app → Reports: includes · Backend serves aggregated reports
- API app → Prisma service: persists via · Services access the database through Prisma
- Prisma service → DB schema: maps to · Prisma service is backed by the canonical schema
- DB schema → Migrations & seed: evolves with · Schema changes are applied through migrations and seed scripts
- API app → DTOs: uses · Backend shares DTO contracts with clients and packages
- API app → Types: uses · Backend shares common types with the workspace
- API app → Tooling config: follows · API builds against shared tooling presets
- Web app → Auth: auth integration · Web app uses Supabase-based authentication flow
- Mobile app → Auth: auth integration · Mobile app authenticates against the backend auth boundary
- User manual → Deploy runtime: deployed with · Static docs and apps sit alongside deployment/runtime setup
- Web app → Deploy runtime: deployed with · Next.js app is built for hosted deployment
- API app → Deploy runtime: deployed with · Backend service runs in containerized infrastructure