Case study / 02

JurisLogic - Headless Tax & Commission Microservice

An independent personal project exploring multi-jurisdiction tax and commission logic with hexagonal architecture, decimal-safe calculations, and public statutory rates.

Status
Selected work
System context
TypeScript, NestJS, Prisma, PostgreSQL
Source
Public repository

01 / System behavior

Interactive proof

A project-specific technical mechanism based on the recorded architecture and implementation context.

Interactive proofJurisLogic - Headless Tax & Commission Microservice
Transaction
Jurisdiction
Tax strategy
Rule pipeline
Decimal-safe result
Audit / cache / queue

Context and intent

JurisLogic is an independent personal project, built on my own time from publicly available tax legislation and open-source libraries. It is not derived from any employer's system.

JurisLogic is a plug-and-play headless microservice designed to be consumed by any frontend, mobile app, or backend service with no coupling or lock-in. Every monetary operation flows through immutable Money value objects backed by decimal.js with banker's rounding (ROUND_HALF_UP), guaranteeing penny-perfect accuracy across all jurisdictions.

03 / Architecture record

Architecture

A structured reading of the architecture recorded with this project.

Architecture recordJurisLogic - Headless Tax & Commission Microservice
Application Layer
Interface Layer
Domain Layer
Infrastructure Layer
Read the full architecture record

The codebase follows a strict Hexagonal (Ports & Adapters) Architecture with three layers:

• Domain Layer (src/domain/) - Pure TypeScript classes with zero framework imports. Contains Value Objects (Money, TaxRate, JurisdictionCode), Entities (Transaction aggregate root, TaxRule, Commission), and Strategies (ITaxStrategy interface with US, EU, UK, CA implementations plus the TaxRulePipeline chain).

• Application Layer (src/application/) - Use case orchestrators (CalculateTax, CalculateCommission, ProcessBatchTransaction) that build domain objects from DTOs, check cache, resolve strategies, run pipelines, and write audit logs. Depends entirely on abstract port interfaces - ICachePort, IQueuePort, IAuditLogPort, ITaxRuleRepository.

• Infrastructure Layer (src/infrastructure/) - Concrete adapters: PrismaService for PostgreSQL, RedisCacheAdapter, BullMQ queue adapter, and Prisma audit log adapter. The NestJS InfrastructureModule is the single composition root that wires adapters to ports.

• Interface Layer (src/interfaces/rest/) - NestJS controllers with Swagger decorators and DTOs. Thin layer that delegates to use cases.

Design Patterns: Strategy, Factory, Chain of Responsibility, Decorator, Builder, Value Object, Repository, Ports & Adapters.

How the system is shaped

The service covers four jurisdiction families: US (state + county + city stacking), EU (per-country standard and reduced rates), UK (standard 20%, reduced 5%, zero-rated), and Canada (HST provinces vs GST+PST). Each jurisdiction is implemented as a concrete Strategy, resolved by a TaxStrategyFactory - adding a new jurisdiction means writing one class and registering it, with zero changes to existing code.

Cross-cutting concerns - exemptions, surcharges, minimum tax floors - are handled by a Chain of Responsibility pipeline with a fluent builder API. The application layer orchestrates use cases (single tax, commission, batch) through abstract port interfaces, keeping business logic framework-free. Infrastructure adapters wire Redis caching, BullMQ async batch processing, and PostgreSQL audit logging.

The commission system supports three models: flat-fee, percentage, and tiered (progressive brackets similar to income tax), all computed with the same decimal precision guarantees.

05 / Selected highlights

Selected implementation notes

The decisions and workflows that carry the most explanatory weight.

  1. True Hexagonal Architecture - domain layer has zero framework dependencies; swap the database or cache without touching a single business rule
  2. Strategy pattern with 4 concrete jurisdiction implementations (US, EU, UK, CA), resolved via a Factory - adding new jurisdictions requires zero changes to existing code (Open/Closed Principle)
  3. Chain of Responsibility pipeline for cross-cutting concerns (exemptions, surcharges, minimum tax floors) with a fluent builder API
  4. Immutable Value Objects (Money, TaxRate, JurisdictionCode) backed by decimal.js - never a floating-point rounding error in financial output
  5. Tiered commission calculation with progressive brackets, per-tier rounding, and edge-case handling for multi-bracket transactions
  6. Async batch processing via BullMQ - POST N transactions, receive 202 Accepted immediately, workers calculate in parallel

06 / Supported metrics

Verified project record

Jurisdiction Families
4
Design Patterns
8
Unit Tests
30+
Commission Models
3
Rounding Errors
0
Framework Dependencies in Domain
0

Technology in context

TypeScript, NestJS, Prisma, PostgreSQL, Redis, BullMQ, decimal.js, Docker, Swagger/OpenAPI, Jest

View source repository