Data Models
This document details the data models used in the Digibit ERP system, which represent the entities and structures used throughout the application.
Base Model
BaseModel (base-model.ts)
The base model provides common properties for all entities in the system.
Properties:
- id: Unique identifier for the entity
- created_at: Timestamp of when the entity was created
Purpose: - Ensures all entities have a consistent ID and creation timestamp - Provides a foundation for inheritance - Standardizes common properties across all models
Entity Models
Company (company.ts)
Represents a business entity in the system.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the company
- dynamic_fields: Record of custom fields and their values
DTO Class:
- CompanyDTO: Data transfer object for API operations
Article (article.ts)
Represents a product or inventory item.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the article
- description: Detailed description
- sku: Stock keeping unit identifier
- barcode: Barcode for identification
- net_price: Net price of the article
- gross_price: Gross price including taxes
- currency_id: Reference to the currency used
- stock_quantity: Current stock quantity
- min_stock: Minimum stock threshold
- max_stock: Maximum stock capacity
- supplier: Supplier information
- manufacturer: Manufacturer information
- category_id: Reference to the article category
- vat_rate: VAT rate applied
- discount: Discount percentage
- article_type_id: Reference to the article type
- thumbnailUrl: URL for the article thumbnail
- dynamic_fields: Record of custom fields and their values
- companyName: Optional company name for display
- expansionItems: Optional expansion items for tables
DTO Class:
- ArticleDTO: Data transfer object for API operations
- TableExpansionItem: Type definition for expansion items
Document (document.ts)
Represents a business document (order, invoice, etc.).
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- title: Title of the document
- description: Description of the document
- document_type_id: Reference to the document type
- company_id: Reference to the associated company
- status: Current status of the document
- date_created: Date the document was created
- date_due: Due date for the document
- total_amount: Total amount of the document
- currency_id: Reference to the currency used
- dynamic_fields: Record of custom fields and their values
- document_items: Array of document items
- document_attached_production: Attached production information
DTO Class:
- DocumentDTO: Data transfer object for API operations
Document Item (document-item.ts)
Represents an item within a document.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- document_id: Reference to the parent document
- article_id: Reference to the associated article
- quantity: Quantity of the article
- unit_price: Unit price of the article
- total_price: Total price for this item
- dynamic_fields: Record of custom fields and their values
DTO Class:
- DocumentItemDTO: Data transfer object for API operations
User Profile (profile.ts)
Represents user profile information.
Properties:
- id: Unique identifier
- username: Username
- website: Website URL
- avatar_url: URL for the user's avatar
Category and Group Models
Article Category (article-category.ts)
Represents categories for organizing articles.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the category
- description: Description of the category
- parent_id: Reference to parent category (for hierarchy)
- dynamic_fields: Record of custom fields and their values
DTO Class:
- ArticleCategoryDTO: Data transfer object for API operations
Article Group (article-group.ts)
Represents groups for organizing articles.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the group
- description: Description of the group
- parent_id: Reference to parent group (for hierarchy)
- dynamic_fields: Record of custom fields and their values
DTO Class:
- ArticleGroupDTO: Data transfer object for API operations
Article Type (article-type.ts)
Represents different types of articles.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the type
- description: Description of the type
- dynamic_fields: Record of custom fields and their values
DTO Class:
- ArticleTypeDTO: Data transfer object for API operations
Currency (currency.ts)
Represents different currencies used in the system.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the currency
- symbol: Currency symbol
- code: Currency code (ISO 4217)
- rate: Exchange rate relative to base currency
- dynamic_fields: Record of custom fields and their values
DTO Class:
- CurrencyDTO: Data transfer object for API operations
Measurement (measurement.ts)
Represents units of measurement.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the measurement unit
- abbreviation: Abbreviation for the measurement unit
- category: Category of the measurement
- conversion_factor: Conversion factor to base unit
- dynamic_fields: Record of custom fields and their values
DTO Class:
- MeasurementDTO: Data transfer object for API operations
Measurement Group (measurement-group.ts)
Represents groups of related measurements.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the measurement group
- description: Description of the group
- dynamic_fields: Record of custom fields and their values
DTO Class:
- MeasurementGroupDTO: Data transfer object for API operations
Production Models
Operation (operation.ts)
Represents a manufacturing operation.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the operation
- description: Description of the operation
- duration: Expected duration of the operation
- machine_id: Reference to the required machine
- operator_count: Number of operators required
- setup_time: Setup time required
- dynamic_fields: Record of custom fields and their values
DTO Class:
- OperationDTO: Data transfer object for API operations
Operation Group (operation-group.ts)
Represents groups of related operations.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the operation group
- description: Description of the group
- parent_id: Reference to parent group (for hierarchy)
- dynamic_fields: Record of custom fields and their values
DTO Class:
- OperationGroupDTO: Data transfer object for API operations
Production Order (production-order.ts)
Represents a production order.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the production order
- description: Description of the order
- status: Current status of the order
- due_date: Due date for the order
- quantity: Quantity to be produced
- product_id: Reference to the product to be manufactured
- dynamic_fields: Record of custom fields and their values
DTO Class:
- ProductionOrderDTO: Data transfer object for API operations
Bill of Materials (bill-of-material.ts)
Represents a bill of materials for a product.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the BOM
- description: Description of the BOM
- product_id: Reference to the product
- version: Version of the BOM
- effective_date: Date when the BOM becomes effective
- dynamic_fields: Record of custom fields and their values
- bom_lines: Array of BOM lines (components)
DTO Class:
- BillOfMaterialDTO: Data transfer object for API operations
BOM Line (bom-line.ts)
Represents a line item in a bill of materials.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- bom_id: Reference to the parent BOM
- component_id: Reference to the component article
- quantity_required: Quantity of component required
- unit_id: Reference to the unit of measure
- sequence: Sequence number in the BOM
- dynamic_fields: Record of custom fields and their values
DTO Class:
- BomLineDTO: Data transfer object for API operations
Document Models
Document Type (document-type.ts)
Represents different types of documents.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the document type
- description: Description of the document type
- abbreviation: Abbreviation for the document type
- workflow_enabled: Whether workflow is enabled for this type
- dynamic_fields: Record of custom fields and their values
DTO Class:
- DocumentTypeDTO: Data transfer object for API operations
Machine Models
Machine (machine.ts)
Represents a manufacturing machine.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- name: Name of the machine
- description: Description of the machine
- machine_type: Type of the machine
- capacity: Production capacity
- status: Current operational status
- location: Physical location of the machine
- dynamic_fields: Record of custom fields and their values
DTO Class:
- MachineDTO: Data transfer object for API operations
Dynamic Field Models
Dynamic Field (dynamic-field.ts)
Represents a custom field that can be added to entities.
Properties:
- id: Unique identifier
- created_at: Creation timestamp
- entity_type: Type of entity this field applies to
- field_name: Name of the field
- field_type: Data type of the field
- is_required: Whether the field is required
- validation_rules: Validation rules for the field
- display_order: Order in which to display the field
DTO Class:
- DynamicFieldDTO: Data transfer object for API operations
Static Field (static-field.ts)
Represents a predefined field for entities.
Properties:
- id: Unique identifier
- entity_type: Type of entity this field applies to
- field_name: Name of the field
- display_name: Display name for the field
- field_type: Data type of the field
- is_required: Whether the field is required
- validation_pattern: Validation pattern for the field
Supporting Models
File (file.ts)
Represents a file in the system.
Properties:
- id: Unique identifier
- name: Name of the file
- size: Size of the file in bytes
- type: MIME type of the file
- url: URL where the file is stored
- uploaded_at: Timestamp when the file was uploaded
Order Type (order-type.ts)
Represents different types of orders.
Properties:
- id: Unique identifier
- name: Name of the order type
- description: Description of the order type
- color: Color code for visual identification
Model Relationships
Hierarchical Relationships
Some models support hierarchical structures: - Article Categories (parent-child relationships) - Article Groups (parent-child relationships) - Operation Groups (parent-child relationships)
Reference Relationships
Models reference other models through foreign keys: - Documents reference Companies, Document Types, and Currencies - Document Items reference Documents and Articles - Production Orders reference Products (Articles) - BOM Lines reference BOMs and Components (Articles)
Model Usage Patterns
DTO Pattern
Each model has a corresponding DTO (Data Transfer Object) class used for: - API communication - Serialization/deserialization - Type safety during data transfer
Constructor Pattern
Models use constructors to initialize properties, providing: - Type safety - Immutability (using readonly) - Clear property definitions
Extensibility
Models support extensibility through: - Dynamic fields property - Inheritance from BaseModel - Flexible data structures
Best Practices
Model Design Principles
- Immutability: Properties marked as readonly where appropriate
- Type Safety: Strong typing with TypeScript interfaces and types
- Consistency: Standardized property names and patterns
- Extensibility: Support for custom fields and extensions
- Maintainability: Clear, well-documented property definitions
Property Naming
- Use camelCase for property names
- Use descriptive names that clearly indicate purpose
- Maintain consistency across similar entities
Data Integrity
- Include validation at the model level where appropriate
- Use appropriate data types to ensure integrity
- Include timestamps for audit trails
These data models provide a robust foundation for representing business entities in the Digibit ERP system while maintaining flexibility for customization and extension.