Skip to content
Back to projects

dgii-helper

In Development

API that validates Dominican tax identifiers and issues invoice numbers without duplicates

Role: Solo developer

Solo · Since Nov 2026 · Public repo

.NET 10ASP.NET CoreEF CoreSQL ServerAngular 21xUnitTestcontainersDocker
113, against a real SQL Server
API tests
52
Front-end tests

An ASP.NET Core API for the two things any Dominican invoicing system needs: checking that an RNC, cédula, NCF or e-CF is well formed, and handing out NCF numbers so that none is ever repeated, even when many invoices arrive at once. It includes an Angular front end to validate identifiers and to register ranges and issue their numbers.

Problem

Issuing the next invoice number by reading a counter and writing it back gives the same number to two requests that arrive together. A repeated NCF is a problem with the tax authority (DGII), not only a bug.

Solution

Each authorized range hands out its next number with a single UPDATE ... OUTPUT: SQL Server locks the row, adds one and returns the previous value in the same statement. Registering a range runs in a serializable transaction that rejects overlaps and retries when SQL Server aborts one as a deadlock victim.

Not done yet

Not deployed anywhere. It does not query the DGII registry, validate e-CF XML or sign and send documents; it only checks that identifiers have a valid form.

Architecture highlights

  • 40 simultaneous requests on a 40-number range receive 40 distinct, consecutive numbers. On a smaller range the extra requests get a 409 and nobody receives a repeated number
  • RNC check digit is a weighted sum modulo 11, tested with hand-computed vectors. The cédula uses Luhn and is compared against an independent Luhn implementation over 20,000 numbers
  • Tests run against a real SQL Server with Testcontainers. I broke the implementation on purpose (read-then-write issuing, a lower isolation level, wrong weights) and the suite caught each one
  • Write endpoints need an API key compared in constant time, and the app refuses to start in production without one. There is a per-IP rate limit
  • The Angular front end uses signals and standalone components, with 52 tests. I ran it in a browser against the real API: registered a 3-number range, issued all 3, saw the button switch to exhausted, and saw a wrong key produce the 401 message
  • A bug I found on the way: EF wraps the deadlock error two levels deep, so my first retry never ran. It now walks the whole exception chain