Architecture¶
pt-fiscal is a set of pure functions grouped by domain, with no shared state and no runtime dependencies. Each validator normalizes input, then applies a structural check and a checksum/check-digit.
flowchart LR
IN["raw input<br/>(NIF / IBAN / CP7)"] --> N["normalize<br/>(strip spaces, PT prefix)"]
N --> S{"structure ok?"}
S -- no --> F["false"]
S -- yes --> C["checksum / check digit<br/>(mod-11 · ISO 7064 mod-97)"]
C --> R["valid : boolean"]
Module map¶
| Module | Responsibility |
|---|---|
nif.ts |
NIF normalize, entity-type classification, mod-11 check digit |
iban.ts |
IBAN normalize, ISO 7064 mod-97 checksum, PT length rule |
postal.ts |
CP7 format validation & normalization |
atcud.ts |
Build/validate the document unique code |
qrcode.ts |
Compose the AT invoice QR field string |
index.ts |
Public API surface |
Design principles¶
- Pure & deterministic — every function is input → output, safe on client or server.
- Zero runtime dependencies — nothing to audit or update; ships as ESM with types.
- Structure, not existence — validation proves shape and check digits, never that an identifier is assigned/active.
- Composition over bundling — the QR builder returns a string; rendering is your choice (keeps the package dependency-free).