Services

This document details the services used in the Digibit ERP system, which handle business logic, data operations, and communication with external systems.

Core Services

AuthService (auth.service.ts)

Manages user authentication and session management.

Key Features: - User login and registration with email/password - Session management with Supabase - Profile management - File storage for avatars via Supabase Storage - Sign out functionality

Methods: - signInWithEmailAndPassword(): Authenticates user with email and password - signUp(): Registers a new user account - signOut(): Logs out the current user - initSession(): Initializes the user session - profile(): Retrieves user profile information - updateProfile(): Updates user profile data - uploadAvatar(): Uploads user avatar images - downLoadImage(): Downloads images from storage

Properties: - sessionSnapshots: BehaviorSubject containing the current session - session$: Observable for subscribing to session changes

SupabaseService (supabase.service.ts)

Handles database connections and operations with Supabase.

Key Features: - Database client initialization - Connection management - Query execution

LanguageService (language.service.ts)

Manages internationalization and translation functionality.

Key Features: - Multi-language support (English, Romanian, Hungarian) - Translation loading and caching - Current language management - Instant translation retrieval

Methods: - setLanguage(): Sets the current language - instant(): Gets an instant translation for a key

Properties: - currentLang: Signal containing the current language

MessagingService (messaging.service.ts)

Handles application notifications and messages.

Key Features: - Toast notifications - Error message display - Success confirmations - Warning alerts

Data Services

Each entity in the system has a corresponding data service that implements the DataService<T> interface.

CompanyService (company.service.ts)

Manages company-related data operations.

Key Features: - CRUD operations for companies - Data synchronization with backend - Observable data stream for real-time updates

ArticleService (article.service.ts)

Manages article/product-related data operations.

Key Features: - Full CRUD operations for articles - Filtering and search capabilities - Price and inventory management - Image handling for thumbnails

DocumentService (document.service.ts)

Handles document workflow and management.

Key Features: - Document lifecycle management - Status tracking - Related entity linking - Workflow operations

ProductionService (production.service.ts)

Manages production-related operations.

Key Features: - Production order management - Machine utilization tracking - Operation scheduling - Resource allocation

OperationService (operation.service.ts)

Handles manufacturing operations.

Key Features: - Operation definition and management - Time estimation - Resource requirements - Predecessor/successor relationships

BillOfMaterialService (bill-of-material.service.ts)

Manages bills of materials.

Key Features: - BOM creation and editing - Component hierarchy management - Version control - Quantity and unit specifications

Specialized Services

CSV Import Service (csv-import.service.ts)

Handles importing data from CSV files.

Key Features: - CSV parsing - Data validation - Type mapping - Error handling during import

Dynamic Field Service (dynamic-field.service.ts)

Manages dynamic/custom fields for entities.

Key Features: - Custom field definition - Validation rules - Type management - Form rendering configuration

Tab Service (tab.service.ts)

Manages the tab-like interface in the dock.

Key Features: - Tab creation and management - Route state preservation - Tab closing and switching - Visual indicators

Service Architecture Patterns

Data Service Interface

All data services implement the DataService<T> interface:

interface DataService<T> {
  data$: Observable<T[] | null>;  // Reactive data stream
  load(): Promise<void>;          // Load data from API
  insert(data: any, options?: DataServiceOptions): any;  // Create new record
  edit(data: any, options?: DataServiceOptions): Promise<VoidOperationResponse>;  // Update record
  delete(data: number): Promise<VoidOperationResponse>;  // Delete record
  tableName: DatabaseTable;       // Associated table name
}

Response Handling

Services use standardized response types:

  • VoidOperationResponse: For operations that don't return data
  • AsyncOperationResponse<T>: For operations that return data

Error Handling

Services implement consistent error handling: - Network error detection - Validation error propagation - User-friendly error messages - Fallback mechanisms

Service Dependencies

External Dependencies

  • Supabase: For database operations and authentication
  • External Backend API: For business logic and complex operations
  • PrimeNG: For UI components and utilities

Internal Dependencies

  • Environment Configuration: For API endpoints and settings
  • Models: For data structure definitions
  • Utilities: For helper functions and constants

Service Communication

With Components

Services communicate with components through: - Observable data streams - Promise-based methods - Event emission - Direct method calls

With Other Services

Services may depend on other services: - AuthService for authentication state - MessagingService for notifications - LanguageService for translations

Best Practices

Service Design Principles

  1. Single Responsibility: Each service has a clear, focused purpose
  2. Reusability: Services are designed for reuse across components
  3. Maintainability: Clean, well-commented code with clear separation of concerns
  4. Performance: Efficient data handling and minimal redundant operations
  5. Security: Proper authentication and authorization checks

Error Handling

  • Comprehensive error handling for network requests
  • Graceful degradation when services are unavailable
  • User-friendly error messages
  • Proper logging for debugging

Memory Management

  • Proper subscription cleanup to prevent memory leaks
  • Efficient data caching strategies
  • Resource management for long-running operations

Service Lifecycle

Services in Angular are typically singleton instances when provided at the root level. They are initialized when first injected and remain active throughout the application lifecycle.

This service architecture provides a robust foundation for managing business logic and data operations in the Digibit ERP system.