Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Track proposals and tasks as `Proposed`, `Approved`, `Implemented`, or `Verified

Every implementation task must specify its objective, scope, technical constraints, dependencies, acceptance criteria, validation requirements, and explicit out-of-scope items.

Claude provides an implementation report and validation evidence. Codex inspects the Git diff against each acceptance criterion, identifies bugs and architectural violations, reviews test execution evidence, cites files and lines, and recommends approval or rework. Report passing tests only with execution evidence. Follow the [architecture workflow](docs/architecture-workflow.md).
Claude provides an implementation report and validation evidence. Codex inspects the Git diff against each acceptance criterion, identifies bugs and architectural violations, reviews test execution evidence, cites files and lines, and recommends approval or rework. Report passing tests only with execution evidence. Follow the [architecture workflow](docs/project/architecture-workflow.md).

## Project Structure and Style

NestJS domains under `src/` group controllers, services, DTOs, and unit tests. Update Swagger decorators and the corresponding guide in `docs/` whenever API behavior changes. Read `docs/database.md` before changing the shared schema in `prisma/control/` or the per-organization schema in `prisma/tenant/`. Add migrations and preserve applied ones.
NestJS domains under `src/` group controllers, services, DTOs, and unit tests. Update Swagger decorators and the corresponding guide in `docs/modules/` whenever API behavior changes. Read `docs/architecture/database.md` before changing the shared schema in `prisma/control/` or the per-organization schema in `prisma/tenant/`. Add migrations and preserve applied ones.

Write code and documentation in English. Reserve comments for complex, non-obvious logic. Use two spaces, single quotes, trailing commas, and `.js` extensions for relative imports. Use PascalCase classes and kebab-case filenames such as `stock-requests.service.ts`.

Expand Down
12 changes: 6 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Pango core: the NestJS backend of a multi-tenant inventory SaaS for Colombian SMEs (pymes), with demand forecasting (a separate Python AI service lives outside this repo). The product catalog API is in `docs/catalog.md`; warehouses in `docs/warehouses.md`; inventory movements in `docs/movements.md`; stock queries and lots in `docs/stock.md`; replenishment parameters and stock alerts in `docs/replenishment.md`; departments and internal stock requests in `docs/stock-requests.md`; the demand history in `docs/demand.md`; demand forecasting (runs through the Python service) in `docs/forecasting.md`; the header's cross-module search in `docs/search.md`; the dashboard figures in `docs/dashboard.md`. The database design — conventions, tables, constraints, business rules, planned views, provisioning and the schema-change workflow — is in `docs/database.md`; read it before touching the data model.
Pango core: the NestJS backend of a multi-tenant inventory SaaS for Colombian SMEs (pymes), with demand forecasting (a separate Python AI service lives outside this repo). The product catalog API is in `docs/modules/catalog.md`; warehouses in `docs/modules/warehouses.md`; inventory movements in `docs/modules/movements.md`; stock queries and lots in `docs/modules/stock.md`; replenishment parameters and stock alerts in `docs/modules/replenishment.md`; departments and internal stock requests in `docs/modules/stock-requests.md`; the demand history in `docs/modules/demand.md`; demand forecasting (runs through the Python service) in `docs/modules/forecasting.md`; the header's cross-module search in `docs/modules/search.md`; the dashboard figures in `docs/modules/dashboard.md`. The database design — conventions, tables, constraints, business rules, planned views, provisioning and the schema-change workflow — is in `docs/architecture/database.md`; read it before touching the data model.

## Roles

Claude is the senior developer; Codex is the principal software architect (its rules are in `AGENTS.md`); the human user has final approval. The full workflow is in `docs/architecture-workflow.md`.
Claude is the senior developer; Codex is the principal software architect (its rules are in `AGENTS.md`); the human user has final approval. The full workflow is in `docs/project/architecture-workflow.md`.

- Claude implements the agreed scope: source, tests, migrations, dependencies, Swagger and the domain guide in `docs/` for any API change. Claude does not write or change ADRs, task definitions or their status; architecture concerns go to the user as a proposal.
- Claude implements the agreed scope: source, tests, migrations, dependencies, Swagger and the domain guide in `docs/modules/` for any API change. Claude does not write or change ADRs, task definitions or their status; architecture concerns go to the user as a proposal.
- Work from a task that states objective, scope, constraints, dependencies, acceptance criteria, validation requirements and out-of-scope items. If the task is missing, incomplete or conflicts with the code, ask before building; don't widen the scope on your own.
- Finish with an implementation report: what changed (files), how each acceptance criterion is met, and the validation commands run with their results. Only report checks as passing when they were actually run; mark the rest as not run.
- Treat Codex's review findings as input to verify against the code, not as orders: fix the confirmed ones, and explain to the user any you disagree with.
Expand Down Expand Up @@ -57,7 +57,7 @@ Prisma CLI calls always need `--config prisma/control.config.ts` or `--config pr

### Auth

Details in `docs/auth.md`. Own auth (no Cognito): Argon2id passwords in `public.accounts`, HS256 access JWT (`sub` = account, `org` = organization) and rotating opaque refresh tokens (`public.refresh_tokens`, SHA-256 only). Both travel only as HttpOnly cookies `pango_access_<subdomain>` / `pango_refresh_<subdomain>` (`SameSite=Lax`, `Domain=COOKIE_DOMAIN`; `src/auth/session-cookies.ts`), never in a body; Bearer is accepted as a fallback for non-browser clients. `CsrfGuard` (global, before `AuthGuard`) rejects unsafe requests with a session cookie from an origin outside `APP_BASE_DOMAIN`, so GET routes must never change state. Only owners sign up (`POST /auth/signup` creates account + organization and emails a confirmation link; login is blocked until `accounts.email_verified_at` is set); login takes two steps: the password opens a challenge (`public.login_challenges`, token in the HttpOnly cookie `pango_login_<subdomain>`) and a six-digit code emailed to the account completes it (`POST /auth/login/verify`, `src/auth/login-code.service.ts`; `LOGIN_EMAIL_CODE_ENABLED=false` skips it for local development); after the code the browser is trusted for a while (`src/auth/trusted-device.service.ts`, signed cookie `pango_device_<subdomain>`, no table), so the next logins ask for the password only; employees join through invitations (`public.organization_invitations`, emailed with Resend), which also verify their email. The organization comes from the `X-Tenant` header or the host's subdomain of `APP_BASE_DOMAIN`. `AuthGuard` is global (`@Public()` opts out): it checks the token's organization equals the request's, reloads membership + tenant user on every request, and puts the session on `request.auth` (`@CurrentAuth()`); `@RequirePermissions(...)` passes when any role assignment grants the permission; `ORGANIZATION`-scope permissions then apply everywhere, while handlers narrow `WAREHOUSE`-scope ones (e.g. `user.manage`) with `warehousesWithPermission` / `permissionsInWarehouse` (`src/auth/auth-context.ts`). Only the Owner (system role) has assignments with no warehouse; granting roles goes through `assertCanAssign` (`src/roles/role-policy.ts`). Errors carry a stable `code` (`src/auth/auth-errors.ts`).
Details in `docs/modules/auth.md`. Own auth (no Cognito): Argon2id passwords in `public.accounts`, HS256 access JWT (`sub` = account, `org` = organization) and rotating opaque refresh tokens (`public.refresh_tokens`, SHA-256 only). Both travel only as HttpOnly cookies `pango_access_<subdomain>` / `pango_refresh_<subdomain>` (`SameSite=Lax`, `Domain=COOKIE_DOMAIN`; `src/auth/session-cookies.ts`), never in a body; Bearer is accepted as a fallback for non-browser clients. `CsrfGuard` (global, before `AuthGuard`) rejects unsafe requests with a session cookie from an origin outside `APP_BASE_DOMAIN`, so GET routes must never change state. Only owners sign up (`POST /auth/signup` creates account + organization and emails a confirmation link; login is blocked until `accounts.email_verified_at` is set); login takes two steps: the password opens a challenge (`public.login_challenges`, token in the HttpOnly cookie `pango_login_<subdomain>`) and a six-digit code emailed to the account completes it (`POST /auth/login/verify`, `src/auth/login-code.service.ts`; `LOGIN_EMAIL_CODE_ENABLED=false` skips it for local development); after the code the browser is trusted for a while (`src/auth/trusted-device.service.ts`, signed cookie `pango_device_<subdomain>`, no table), so the next logins ask for the password only; employees join through invitations (`public.organization_invitations`, emailed with Resend), which also verify their email. The organization comes from the `X-Tenant` header or the host's subdomain of `APP_BASE_DOMAIN`. `AuthGuard` is global (`@Public()` opts out): it checks the token's organization equals the request's, reloads membership + tenant user on every request, and puts the session on `request.auth` (`@CurrentAuth()`); `@RequirePermissions(...)` passes when any role assignment grants the permission; `ORGANIZATION`-scope permissions then apply everywhere, while handlers narrow `WAREHOUSE`-scope ones (e.g. `user.manage`) with `warehousesWithPermission` / `permissionsInWarehouse` (`src/auth/auth-context.ts`). Only the Owner (system role) has assignments with no warehouse; granting roles goes through `assertCanAssign` (`src/roles/role-policy.ts`). Errors carry a stable `code` (`src/auth/auth-errors.ts`).

### API documentation (Swagger)

Expand All @@ -69,11 +69,11 @@ Details in `docs/auth.md`. Own auth (no Cognito): Argon2id passwords in `public.

### Migrations

- Migrations are generated without a shadow DB with `prisma migrate diff --from-config-datasource --to-schema <schema.prisma> --script` (tenant: set `TENANT_SCHEMA=tenant_demo`), then saved as `<yyyymmddhhmmss>_<name>/migration.sql`. Full steps in `docs/database.md`.
- Migrations are generated without a shadow DB with `prisma migrate diff --from-config-datasource --to-schema <schema.prisma> --script` (tenant: set `TENANT_SCHEMA=tenant_demo`), then saved as `<yyyymmddhhmmss>_<name>/migration.sql`. Full steps in `docs/architecture/database.md`.
- The tenant `init` migration ends with hand-written SQL (CHECK constraints, partial unique indexes, `NULLS NOT DISTINCT` indexes) that Prisma can't express. The tenant diff always emits `DROP INDEX` for the two `NULLS NOT DISTINCT` indexes — delete those lines from new migrations.
- Tenant base data (permissions, base movement types, `EA` unit, `Owner` role, settings row) lives in the `base_data` migration, not a seed, so new tenants are born with it. Any migration that adds a permission must also grant it to `Owner`.
- Don't edit migrations that are already applied; add a new one.
- Derived values are computed in views (planned, see `docs/database.md`), not stored — except `products.average_cost`. `stock_balances` is a materialized balance that only changes when movements are confirmed; nothing is deleted, mistakes are voided with a reversing movement (`movements.reversal_of_id`).
- Derived values are computed in views (planned, see `docs/architecture/database.md`), not stored — except `products.average_cost`. `stock_balances` is a materialized balance that only changes when movements are confirmed; nothing is deleted, mistakes are voided with a reversing movement (`movements.reversal_of_id`).
- Naming: plural `snake_case` tables, `snake_case` columns, singular `snake_case` enum types with `UPPER_CASE` values; Prisma models are singular PascalCase with `@@map`, fields camelCase with `@map`. Keys are `serial`/`integer` (no `bigint`, to avoid `BigInt` in JSON). `created_at`/`updated_at` use `@default(now())` (plus `@updatedAt`) so non-Prisma writers work. Index every foreign key unless it leads a PK/unique index.

## Git workflow (from README)
Expand Down
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ the application.
```text
.
├── docs/
│ ├── auth.md # Authentication and invitation flows
│ ├── catalog.md # Product catalog API
│ ├── database.md # Database design and migration workflow
│ └── warehouses.md # Warehouse API
│ ├── README.md # Documentation index
│ ├── architecture/
│ ├── modules/
│ ├── plans/
│ ├── project/
│ └── templates/
├── prisma/
│ ├── control/ # Public/control-plane schema and migrations
│ ├── tenant/ # Tenant schema and migrations
Expand Down Expand Up @@ -158,7 +160,7 @@ At minimum, configure:

Important authentication defaults include 15-minute access tokens,
30-day refresh tokens, 72-hour invitations and 24-hour email-verification
links. See [`docs/auth.md`](docs/auth.md) for the complete configuration
links. See [`docs/modules/auth.md`](docs/modules/auth.md) for the complete configuration
reference.

## Local development
Expand Down Expand Up @@ -278,7 +280,7 @@ data model.
Tenant provisioning creates the schema, applies all tenant migrations, creates
the organization and adds the owner in a single workflow. New schema changes
must be added as migrations; already-applied migrations must not be edited.
Read [`docs/database.md`](docs/database.md) before changing either schema.
Read [`docs/architecture/database.md`](docs/architecture/database.md) before changing either schema.

## Testing and quality checks

Expand All @@ -295,14 +297,8 @@ Generated Prisma clients under `src/generated/` are not committed. Run

## Documentation

- [`docs/auth.md`](docs/auth.md): sessions, cookies, CSRF, email verification,
invitations and user administration.
- [`docs/catalog.md`](docs/catalog.md): product and category behavior,
validation rules and catalog endpoints.
- [`docs/warehouses.md`](docs/warehouses.md): warehouse types, permissions
and default locations.
- [`docs/database.md`](docs/database.md): schemas, naming conventions,
migrations, provisioning and data-model rules.
The [documentation index](docs/README.md) links to module guides, database
design, project decisions, implementation plans and templates.

## Development workflow

Expand Down
29 changes: 29 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Pango Core documentation

## Implemented modules

| Guide | What it covers |
| --- | --- |
| [Authentication and access](modules/auth.md) | Sign-up, login, invitations, users and roles |
| [Product catalog](modules/catalog.md) | Products, categories and stock units |
| [Warehouses](modules/warehouses.md) | Warehouses, stores and default locations |
| [Inventory movements](modules/movements.md) | Receipts, issues, adjustments and transfers |
| [Stock](modules/stock.md) | Quantities by warehouse, location and lot |
| [Internal stock requests](modules/stock-requests.md) | Department requests, reservations and fulfillment |
| [Demand history](modules/demand.md) | Which movements count as demand and how demand is grouped |
| [Forecasting](modules/forecasting.md) | Forecast runs and integration with the Python service |
| [Replenishment](modules/replenishment.md) | Manual and calculated reorder points, stock alerts and their resolution |
| [Search](modules/search.md) | Cross-module search and access rules |
| [Dashboard](modules/dashboard.md) | Inventory indicators and alerts |

## Architecture and project

- [Database architecture](architecture/database.md) covers tenant isolation, schema conventions, migrations and provisioning.
- [Architecture workflow](project/architecture-workflow.md) defines roles, approvals and implementation review.
- [Project context](project/project-context.md) records decisions, previous work and open questions.

## Plans and templates

- [CU-11 · Calculated reorder point](plans/cu-11-reorder-point.md) records the design and validation of the implemented feature.
- [CU-17 · Kardex import](plans/cu-17-kardex-import.md) proposes the movement import workflow. The [standard Pango kardex template](templates/pango-standard-kardex-movement-history-import-v1.csv) defines the CSV format for importing inventory movement history.
- [Documentation layout](plans/documentation-layout.md) records the organization of these guides.
Loading