Requirements

Documentation for Modules

Fiscal Library - Requirements Specification

Library: @libs-core/fiscal Location: libs/core/fiscal/ Type: Core infrastructure library (not a business module) Permission Namespace: fiscal:*

1. Overview

Minimal tax configuration system that provides tax class definitions and tax rate resolution to any module in the platform. Products, services, invoicing, POS, and any entity or process that needs tax calculation can consume this library.

This is a minimal MVP — it provides the tax class registry and basic rate resolution. Advanced features (tax rules by region, tax exemptions, compound taxes) are deferred to future iterations.

1.1 Design Principles

2. Functional Requirements

2.1 Tax Class Entity

A tax class represents a category of taxation (e.g., "Standard", "Reduced", "Exempt"):

Field Type Required Description
id string Yes Unique identifier (UUID)
tenantId string Yes Multi-tenant isolation
name string Yes Display name (e.g., "Standard Rate", "Reduced Rate")
code string Yes Machine-readable code (e.g., 'standard', 'reduced', 'exempt', 'zero_rated')
description string No Explanation of when this class applies
rate number Yes Tax rate as percentage (e.g., 16 for 16%, 0 for exempt)
isDefault boolean Yes Whether this is the default tax class for new entities
isActive boolean Yes Whether this tax class is available (default: true)
sortOrder number No Display order
createdAt Date Yes Creation timestamp
updatedAt Date Yes Last update timestamp

Tax Class Rules:

2.2 Tax Calculation

The library provides a simple calculation utility:

3. Services

3.1 FiscalService

Injectable service for programmatic access:

3.2 TaxCalculationResult

interface TaxCalculationResult {
  subtotal: number;        // Original amount
  taxRate: number;         // Applied rate (e.g., 16)
  taxAmount: number;       // Calculated tax (subtotal * rate / 100)
  total: number;           // subtotal + taxAmount
  taxClassName: string;    // Name of applied tax class
  taxClassCode: string;    // Code of applied tax class
}

4. Integration Points

4.1 Domain Events

Event Payload Trigger
fiscal.tax-class.created { taxClass, tenantId } Tax class created
fiscal.tax-class.updated { taxClass, changes, tenantId } Tax class updated (including rate change)
fiscal.tax-class.deleted { taxClassId, tenantId } Tax class deleted
fiscal.tax-rate.changed { taxClassId, oldRate, newRate, tenantId } Tax rate changed (important for consumers)

4.2 Embeddable Components

Component ID Description Inputs
fiscal:tax-class-selector Dropdown tax class picker placeholder, showRate, includeInactive

4.3 Public Actions

Action ID Description Parameters Permission
fiscal:get-tax-classes List tax classes { tenantId } fiscal:read
fiscal:calculate-tax Calculate tax for amount { amount, taxClassId } fiscal:read

5. Permissions

Permission Description
fiscal:read View tax classes and calculate taxes
fiscal:manage Create/edit/delete tax classes and rates

6. User Stories

7. Non-Functional Requirements

8. Dependencies

@libs-core/fiscal
├── @libs-core/event-system        (domain events)
├── @libs-core/security            (permissions, tenant context)
├── @libs-core/log-system          (logging)
├── @libs-core/utilities           (number/currency utilities)
├── @libs-core/shared-models       (BaseEntity, API types)
├── @libs-core/ui-framework        (UI components for embeddables)
├── @libs-core/action-registry     (public actions)
└── @libs-core/mock-api            (development mock data)

9. Future Iterations (Out of Scope)

These features are explicitly deferred: