Interface Documentation
Overview
This document outlines the interfaces, value objects, repositories, and domain contracts for the Expense Management module in the Bee O'clock panel service. The module follows Domain-Driven Design principles with clear separation between domain logic and infrastructure concerns.
Domain Interfaces
IExpense
File: applications/panel.beeoclock/src/modules/expense/domain/interfaces/i.expense.ts
The core expense aggregate root interface that defines the structure and behavior of expense entities within the domain.
import {IBaseEntityBeeoClockTenantId} from '@beeoclock/common/core/entities/i.base.entity.beeoclock.tenant.id';
import {ExpenseValueRootValueObject} from '../value-objects/expense-value.value-object';
import {ExpenseItemValueObject} from '../value-objects/expense-item.value-object';
export interface IExpense extends IBaseEntityBeeoClockTenantId {
totalValue: ExpenseValueRootValueObject; // Total monetary value of the expense
expensedAt: Date; // Date when the expense occurred
description?: string; // Optional description of the expense
items?: ExpenseItemValueObject[]; // Array of individual expense line items
}Key Characteristics:
Extends base entity with tenant ID for multi-tenancy support
Uses value objects for monetary amounts and complex structures
Supports itemized expenses with detailed breakdown
Immutable expense timestamp for audit purposes
IExpenseCategory
File: applications/panel.beeoclock/src/modules/expense/domain/interfaces/i.expense-category.ts
Interface defining expense categorization structure for organizing and filtering expenses.
Key Characteristics:
Extends base entity with tenant ID for multi-tenancy support
Simple name-based categorization system
Optional description for detailed category information
Designed for reusability across multiple expenses
IExpenseRepository
File: applications/panel.beeoclock/src/modules/expense/domain/interfaces/i.expense.repository.ts
Repository interface defining data access patterns for expense entities with advanced querying capabilities.
Key Features:
Extends base repository with common CRUD operations
Advanced pagination with expense-specific filtering
Supports date range queries and category filtering
Built-in tenant isolation for multi-tenant architecture
Soft delete pattern for data integrity
IExpenseCategoryRepository
File: applications/panel.beeoclock/src/modules/expense/domain/interfaces/i.expense-category.repository.ts
Repository interface for managing expense categories with pagination and bulk operations.
Key Features:
Bulk operations for efficient category management
Name-based lookup with tenant scoping
Standard pagination for category listing
Designed for high-frequency read operations
Value Objects
ExpenseValueRootValueObject
File: applications/panel.beeoclock/src/modules/expense/domain/value-objects/expense-value.value-object.ts
Value object representing monetary amounts with currency support.
Key Features:
Immutable value object with validation
Currency consistency enforcement
Arithmetic operations with currency validation
Serialization support for persistence
ExpenseItemValueObject
File: applications/panel.beeoclock/src/modules/expense/domain/value-objects/expense-item.value-object.ts
Value object representing individual line items within an expense.
Key Features:
Encapsulates line item business logic
Category validation and querying
Integration with expense value and source objects
Immutable design with validation
ExpenseSourceValueObject
File: applications/panel.beeoclock/src/modules/expense/domain/value-objects/expense-source.value-object.ts
Value object representing the source or origin of an expense item.
Key Features:
Encapsulates source entity information
Type validation and checking
Flexible naming with fallbacks
Immutable design with validation
Enumerations
ExpenseSourceTypeEnum
File: applications/panel.beeoclock/src/modules/expense/domain/enums/expense-source-type.enum.ts
Enumeration defining the types of entities that can be associated with expense items.
Usage Context:
member: Employee salaries, commissions, benefits
resource: Equipment maintenance, facility costs, resource allocation
product: Inventory costs, product-related expenses, cost of goods sold
supplier: Vendor payments, external services, outsourced operations
Data Transfer Objects (DTOs)
ExpenseDto
File: applications/panel.beeoclock/src/modules/expense/application/dtos/expense.dto.ts
Data transfer object for expense entities with validation decorators.
ExpenseValueDto
File: applications/panel.beeoclock/src/modules/expense/application/dtos/expense-value.dto.ts
Data transfer object for monetary values with currency validation.
ExpenseItemDto
File: applications/panel.beeoclock/src/modules/expense/application/dtos/expense-item.dto.ts
Data transfer object for expense line items with category and source validation.
ExpenseSourceDto
File: applications/panel.beeoclock/src/modules/expense/application/dtos/expense-source.dto.ts
Data transfer object for expense source information with type validation.
ExpenseCategoryDto
File: applications/panel.beeoclock/src/modules/expense/application/dtos/expense-category.dto.ts
Data transfer object for expense categories with validation.
ExpensePaginationDto
File: applications/panel.beeoclock/src/modules/expense/application/dtos/expense.pagination.dto.ts
Data transfer object for expense pagination with advanced filtering.
Mappers
ExpenseMapperToDto
File: applications/panel.beeoclock/src/modules/expense/application/mappers/expense.mapper-to-dto.ts
Mapper for converting domain entities to DTOs with proper type transformation.
ExpenseMapperToDomain
File: applications/panel.beeoclock/src/modules/expense/application/mappers/expense.mapper-to-domain.ts
Mapper for converting DTOs to domain entities with validation.
Use Case Interfaces
ICreateExpenseUseCase
Interface defining the contract for expense creation use cases.
IGetPagedExpensesUseCase
Interface defining the contract for paginated expense retrieval.
Architecture Integration
Dependency Injection
The expense management module integrates with the NestJS dependency injection system:
Module Configuration
Integration with the panel module's dependency injection container:
Design Patterns
Repository Pattern
Abstract data access through repository interfaces
Consistent querying and persistence operations
Support for complex queries with filtering and pagination
Value Object Pattern
Immutable objects for monetary values and complex data
Encapsulation of business rules and validation
Type safety for financial calculations
Domain-Driven Design
Clear separation between domain logic and infrastructure
Rich domain models with business behavior
Aggregate roots for consistency boundaries
Command Query Responsibility Segregation (CQRS)
Separate interfaces for command and query operations
Optimized data access patterns for different use cases
Clear separation of concerns for read and write operations
Validation Rules
Domain Validation
Expense amounts must be positive
Currency consistency across expense items
Required fields validation (amount, date, source)
Category existence validation
DTO Validation
JSON schema validation using class-validator decorators
Type conversion and transformation using class-transformer
Custom validation rules for business-specific requirements
Repository Validation
Data integrity checks during persistence
Constraint validation at the database level
Foreign key integrity for related entities
Error Handling
Domain Exceptions
Repository Exceptions
Testing Interfaces
Mock Repositories
Test Builders
This interface documentation provides a comprehensive view of the expense management module's contracts, value objects, and domain structure, enabling developers to understand and work with the expense system effectively while maintaining consistency with domain-driven design principles.
Last updated
Was this helpful?