# iamluissosa/lmcu architecture

> Architecture diagram of the GitHub repository iamluissosa/lmcu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iamluissosa/lmcu
- Repository: https://github.com/iamluissosa/lmcu

## Overview

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: [`apps/api/src/app.module.ts`](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/app.module.ts) (API app), [`apps/web/app/dashboard/page.tsx`](https://github.com/iamluissosa/lmcu/blob/main/apps/web/app/dashboard/page.tsx) (Web app), [`apps/mobile/App.tsx`](https://github.com/iamluissosa/lmcu/blob/main/apps/mobile/App.tsx) (Mobile app), [`apps/api/src/modules/auth/auth.module.ts`](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/auth/auth.module.ts) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Applications"]
  node_web["Web app<br/>Next.js dashboard<br/>[page.tsx]"]
  node_mobile["Mobile app<br/>Expo client<br/>[App.tsx]"]
  node_api["API app<br/>NestJS backend<br/>[app.module.ts]"]
  node_api_auth["Auth<br/>API module<br/>[auth.module.ts]"]
  node_api_sales["Sales<br/>API module<br/>[sales.module.ts]"]
  node_api_accounting["Accounting<br/>API modules"]
  node_api_master["Master data<br/>API modules"]
  node_api_commissions["Commissions<br/>API module"]
  node_api_reports["Reports<br/>API module<br/>[reports.module.ts]"]
  node_api_prisma[("Prisma service<br/>Persistence layer<br/>[prisma.service.ts]")]
end

subgraph group_shared["Shared Packages"]
  node_shared_ui["UI kit<br/>Shared React UI<br/>[button.tsx]"]
  node_shared_dtos["DTOs<br/>Shared contracts<br/>[index.ts]"]
  node_shared_types["Types<br/>[index.ts]"]
  node_shared_config["Tooling config<br/>Workspace config<br/>[base.json]"]
end

subgraph group_ops["Operations"]
  node_db_schema["DB schema<br/>Prisma schema<br/>[schema.prisma]"]
  node_db_seed["Migrations & seed<br/>Database ops<br/>[seed.ts]"]
  node_docs["User manual<br/>Static docs<br/>[index.html]"]
  node_runtime["Deploy runtime<br/>Infra"]
end

node_web -->|"HTTP API"| node_api
node_mobile -->|"HTTP API"| node_api
node_web -->|"renders"| node_shared_ui
node_mobile -->|"renders"| node_shared_ui
node_web -->|"contracts"| node_shared_dtos
node_mobile -->|"contracts"| node_shared_dtos
node_api -->|"includes"| node_api_auth
node_api -->|"includes"| node_api_sales
node_api -->|"includes"| node_api_accounting
node_api -->|"includes"| node_api_master
node_api -->|"includes"| node_api_commissions
node_api -->|"includes"| node_api_reports
node_api -->|"persists via"| node_api_prisma
node_api_prisma -->|"maps to"| node_db_schema
node_db_schema -.->|"evolves with"| node_db_seed
node_api -->|"uses"| node_shared_dtos
node_api -->|"uses"| node_shared_types
node_api -.->|"follows"| node_shared_config
node_web -->|"auth integration"| node_api_auth
node_mobile -->|"auth integration"| node_api_auth
node_docs -.->|"deployed with"| node_runtime
node_web -.->|"deployed with"| node_runtime
node_api -.->|"deployed with"| node_runtime

click node_web "https://github.com/iamluissosa/lmcu/blob/main/apps/web/app/dashboard/page.tsx"
click node_mobile "https://github.com/iamluissosa/lmcu/blob/main/apps/mobile/App.tsx"
click node_api "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/app.module.ts"
click node_api_auth "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/auth/auth.module.ts"
click node_api_sales "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/sales/sales.module.ts"
click node_api_accounting "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/fiscal-books/fiscal-books.module.ts"
click node_api_master "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/companies/companies.module.ts"
click node_api_commissions "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/commissions/commissions.module.ts"
click node_api_reports "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/reports/reports.module.ts"
click node_api_prisma "https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/prisma/prisma.service.ts"
click node_db_schema "https://github.com/iamluissosa/lmcu/blob/main/packages/database/prisma/schema.prisma"
click node_db_seed "https://github.com/iamluissosa/lmcu/blob/main/packages/database/prisma/seed.ts"
click node_shared_ui "https://github.com/iamluissosa/lmcu/blob/main/packages/ui/src/button.tsx"
click node_shared_dtos "https://github.com/iamluissosa/lmcu/blob/main/packages/dtos/src/index.ts"
click node_shared_types "https://github.com/iamluissosa/lmcu/blob/main/packages/types/src/index.ts"
click node_shared_config "https://github.com/iamluissosa/lmcu/blob/main/packages/typescript-config/base.json"
click node_docs "https://github.com/iamluissosa/lmcu/blob/main/docs/user-manual/index.html"
click node_runtime "https://github.com/iamluissosa/lmcu/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_mobile,node_api,node_api_auth,node_api_sales,node_api_accounting,node_api_master,node_api_commissions,node_api_reports,node_api_prisma toneBlue
class node_shared_ui,node_shared_dtos,node_shared_types,node_shared_config toneAmber
class node_db_schema,node_db_seed,node_docs,node_runtime toneMint
```

## Components

### Applications

Runtime apps and user-facing clients

- [Web app](https://github.com/iamluissosa/lmcu/blob/main/apps/web/app/dashboard/page.tsx): Next.js dashboard · Desktop/admin client for sales, accounting, inventory, settings, reports, and printing · `apps/web/app/dashboard/page.tsx`
- [Mobile app](https://github.com/iamluissosa/lmcu/blob/main/apps/mobile/App.tsx): Expo client · Operational mobile client for dashboard, quotes, commissions, and settings · `apps/mobile/App.tsx`
- [API app](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/app.module.ts): NestJS backend · Central business service for auth, domain logic, and persistence · `apps/api/src/app.module.ts`
- [Auth](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/auth/auth.module.ts): API module · Supabase-based authentication and server-side access control · `apps/api/src/modules/auth/auth.module.ts`
- [Sales](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/sales/sales.module.ts): API module · Quotes, orders, and invoices workflows · `apps/api/src/modules/sales/sales.module.ts`
- [Accounting](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/fiscal-books/fiscal-books.module.ts): API modules · Purchases, bills, payments, fiscal books, and tax handling · `apps/api/src/modules/fiscal-books/fiscal-books.module.ts`
- [Master data](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/companies/companies.module.ts): API modules · Companies, users, clients, suppliers, products, settings, and related reference data · `apps/api/src/modules/companies/companies.module.ts`
- [Commissions](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/commissions/commissions.module.ts): API module · Commission calculation and event/listener processing · `apps/api/src/modules/commissions/commissions.module.ts`
- [Reports](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/modules/reports/reports.module.ts): API module · Aggregated reporting and event data for the clients · `apps/api/src/modules/reports/reports.module.ts`
- [Prisma service](https://github.com/iamluissosa/lmcu/blob/main/apps/api/src/prisma/prisma.service.ts): Persistence layer · Backend database access through the Prisma service · `apps/api/src/prisma/prisma.service.ts`

### Shared Packages

Reusable contracts, UI, and config

- [UI kit](https://github.com/iamluissosa/lmcu/blob/main/packages/ui/src/button.tsx): Shared React UI · Reusable components shared across apps · `packages/ui/src/button.tsx`
- [DTOs](https://github.com/iamluissosa/lmcu/blob/main/packages/dtos/src/index.ts): Shared contracts · Cross-app data transfer types and auth contracts · `packages/dtos/src/index.ts`
- [Types](https://github.com/iamluissosa/lmcu/blob/main/packages/types/src/index.ts): Shared types · Common type definitions used across the workspace · `packages/types/src/index.ts`
- [Tooling config](https://github.com/iamluissosa/lmcu/blob/main/packages/typescript-config/base.json): Workspace config · Shared linting and TypeScript presets · `packages/typescript-config/base.json`

### Operations

Database evolution, deployment, and support assets

- [DB schema](https://github.com/iamluissosa/lmcu/blob/main/packages/database/prisma/schema.prisma): Prisma schema · Canonical domain model and migrations for the operational database · `packages/database/prisma/schema.prisma`
- [Migrations & seed](https://github.com/iamluissosa/lmcu/blob/main/packages/database/prisma/seed.ts): Database ops · Schema migrations, seed scripts, and backfills · `packages/database/prisma/seed.ts`
- [User manual](https://github.com/iamluissosa/lmcu/blob/main/docs/user-manual/index.html): Static docs · Standalone documentation site for end users · `docs/user-manual/index.html`
- [Deploy runtime](https://github.com/iamluissosa/lmcu/tree/main/Dockerfile): Infra · Container and hosting configuration for app deployment · `Dockerfile`

## Connections

- 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
