The product catalog is the foundation of Inventory System. Every product belongs to a category, carries an auto-generated SKU code derived from that category’s prefix, and tracks its own minimum stock threshold. Changes to a product’s price are stored in a separate history table so you always have a full audit trail of who changed what and when.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/juadariasmar/inventory_project/llms.txt
Use this file to discover all available pages before exploring further.
Product data model
EachProducto record stores the following fields:
| Field | Type | Description |
|---|---|---|
id | Int | Auto-incremented primary key |
nombre | String | Display name of the product |
descripcion | String? | Optional free-text description |
codigo | String | Unique SKU within the company (auto-generated or custom) |
precio | Float | Current unit selling price |
cantidad | Int | Current stock quantity (updated automatically by movements) |
stockMinimo | Int | Minimum quantity threshold; triggers a low-stock notification when cantidad falls at or below this value plus the alert margin |
categoriaId | Int | Foreign key to the owning Categoria |
empresaId | String | Tenant isolation key — every query is scoped to this value |
creadoEn | DateTime | UTC timestamp of record creation |
Every product must belong to a category. If you migrate existing products without a category, the system reassigns them to a “Sin clasificar” fallback category automatically.
Category system
Categories group products and provide the prefix used to generate product codes. TheCategoria model fields are:
| Field | Type | Description |
|---|---|---|
id | Int | Auto-incremented primary key |
nombre | String | Unique category name within the company |
prefijo | String | Uppercase alphanumeric characters derived from the category name (e.g. BEB, ALI). Must be unique within the company. |
empresaId | String | Tenant key |
nombre and prefijo have a compound unique constraint per empresaId, so two categories in the same tenant cannot share either value.
Prefix suggestion
When you create a category without supplying a prefix, the system callsgenerarPrefijoSugerido from src/lib/codigos.ts. The algorithm:
- Strips accents and non-alphanumeric characters from the category name and converts it to uppercase.
- Takes the first 3 characters as the candidate (e.g.
"Bebidas"→"BEB"). - If that prefix is already in use, it extends by one more character (
"BEBI") until a free slot is found. - If the name runs out of letters, it appends a numeric suffix (
"BEB1","BEB2", …). - Falls back to
"CAT"if the name has no usable letters.
Auto-generated product codes
Product codes follow the format{PREFIJO}-NNNNN (five zero-padded digits). The function siguienteCodigoConsecutivoPorCategoria in src/lib/codigos.ts queries the highest existing sequence number for the given category and returns the next one:
codigo when creating a product it is used as-is, provided it is unique within the tenant.
Stock management
ThestockMinimo field defines the reorder point for a product. The system uses a constant alert margin (MARGEN_ALERTA_STOCK = 2, defined in src/lib/inventario.ts) on top of the minimum:
- Stock bajo —
cantidad <= stockMinimo + 2 - Sin stock —
cantidad <= 0 - Normal — above the alert margin
NotificacionesService.generarAlertasStock) creates a STOCK_BAJO or STOCK_CRITICO notification for the company. See Notifications for details.
Price history
Every time a product’s price is updated, the previous and new values are recorded inHistorialPrecio:
| Field | Type | Description |
|---|---|---|
id | Int | Auto-incremented primary key |
productoId | Int | FK to the product |
precioAnterior | Float | Price before the change |
precioNuevo | Float | Price after the change |
cambiadoPorId | String? | FK to the Usuario who made the change (nullable if changed by the system) |
creadoEn | DateTime | Timestamp of the price change |
empresaId | String | Tenant key |
GET /api/productos/[id]/historial-precios.
Bulk import
To load products in bulk, use the CSV/Excel import endpoint. First download the official template so your file has the correct column headers:.xlsx). Fill it in and then upload it:
codigo value, and returns a summary of created and failed records.
Bulk delete
To delete multiple products in a single request, send their IDs as an array:Code example — product object
The following is a representative JSON object returned byGET /api/productos or POST /api/productos: