Inventory & Supply Chain
Relevant source files
The following files were used as context for generating this wiki page:
The Inventory & Supply Chain module within the Tuturuuu platform is a comprehensive system designed to manage stock levels, track product movements across multiple warehouses, and automate supply chain operations. It provides real-time visibility into inventory performance, enabling organizations to optimize their logistics and fulfillment processes through data-driven insights.
The system is integrated into the core platform's workspace management, allowing for granular permission control and cross-module collaboration. It supports enterprise-grade security for stock data and offers tools for barcode/QR scanning, automated reordering, and detailed audit trails for every inventory change.
Sources: apps/web/src/app/[locale]/(marketing)/products/inventory/page.tsx:1-125, README.md:21-26
Core Features & Capabilities
The inventory system provides a suite of tools designed to streamline modern logistics and retail operations.
| Feature | Description |
|---|---|
| Stock Management | Real-time tracking of inventory levels with proactive alerts and updates. |
| Warehouse Organization | Support for multiple physical locations and tracking stock movement between them. |
| Barcode & QR Integration | Scanning capabilities for quick and accurate item identification and tracking. |
| Order Processing | Management of purchase orders and supplier relationships within the supply chain. |
| Automated Reordering | Automatic generation of orders based on user-defined minimum stock thresholds. |
| Audit Trails | Detailed historical records of every movement and change for compliance. |
Sources: apps/web/src/app/[locale]/(marketing)/products/inventory/page.tsx:21-57, apps/web/src/app/[locale]/(marketing)/products/inventory/page.tsx:135-155
Technical Architecture & Data Flow
The inventory module follows a RESTful API pattern for managing product quantities and stock adjustments. It utilizes Supabase for data persistence and enforces workspace-level security via Row Level Security (RLS) and custom permission checks.
Inventory Update Process
When an inventory level is modified, the system performs a multi-step process to ensure data integrity and traceability.
The flow above illustrates how a PATCH request updates stock levels while simultaneously logging the delta in the product_stock_changes table.
Sources: apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:133-289
API Endpoints
The backend implementation provides endpoints for granular management of inventory items associated with specific products and warehouses.
| Method | Endpoint | Description | Permission Required |
|---|---|---|---|
GET | /api/v1/workspaces/[wsId]/products/[productId]/inventory | Fetches all inventory entries for a specific product. | view_stock_quantity |
POST | /api/v1/workspaces/[wsId]/products/[productId]/inventory | Creates new inventory records for a product. | update_stock_quantity |
PATCH | /api/v1/workspaces/[wsId]/products/[productId]/inventory | Updates existing stock levels, prices, or minimum amounts. | update_stock_quantity |
DELETE | /api/v1/workspaces/[wsId]/products/[productId]/inventory | Removes all inventory records for a specific product. | update_stock_quantity |
Sources: apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:55-373
Data Models
The system relies on several core tables to maintain the relationship between products, warehouses, and stock changes.
Inventory Item Structure
The InventoryItemSchema defines the requirements for an inventory entry.
const InventoryItemSchema = z.object({
warehouse_id: z.uuid(),
unit_id: z.uuid(),
amount: z.number().nonnegative().nullable(),
min_amount: z.number().nonnegative().optional(),
price: z.number().nonnegative(),
});
Sources: apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:12-18
Relationship Diagram
The following diagram represents the logical relationships between inventory entities.
The system ensures that every stock change is linked to a creator_id (a virtual user ID within the workspace) for auditing purposes.
Sources: apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:25-53, apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:262-273
Stock Change Logic
A critical component of the supply chain module is the calculation and logging of stock changes. When an inventory record is updated, the system calculates the difference between the old amount and the new amount.
- New Insertion: If a product is added to a warehouse for the first time, the entire amount is logged as a positive change.
- Update: If the amount changes from 10 to 15, a
+5change is logged. - Deletion/Clearing: If an inventory record is deleted, the current amount is logged as a negative change (e.g.,
-10) to reflect the removal from the total supply.
Sources: apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:102-126, apps/web/src/app/api/v1/workspaces/[wsId]/products/[productId]/inventory/route.ts:167-188
SDK Integration
Developers can interact with the storage and document aspects of the inventory system using the official tuturuuu SDK. This is particularly useful for managing technical specifications or supplier contracts associated with inventory items.
// Example of accessing documentation related to inventory
import { TuturuuuClient } from 'tuturuuu';
const client = new TuturuuuClient('ttr_api_key');
// Search for inventory-related documents
const results = await client.documents.search('inventory-report-2024');
Permission Requirements for SDK operations:
- Storage Operations: Requires
manage_drivepermission. - Document Operations: Requires
manage_documentspermission.
Sources: apps/web/src/app/[locale]/(dashboard)/[wsId]/(workspace-settings)/api-keys/sdk-guide.tsx:10-25, apps/web/src/app/[locale]/(dashboard)/[wsId]/(workspace-settings)/api-keys/sdk-guide.tsx:280-295
Conclusion
The Inventory & Supply Chain system is a robust, secure, and highly traceable module within the Tuturuuu platform. By combining real-time stock management with automated audit logging and multi-warehouse support, it provides a scalable solution for organizations ranging from retail to manufacturing. Its deep integration with the platform's permission system and SDK ensures that logistics data remains protected while remaining accessible for automated workflows.