Documentation
Documentation
Back to AppGetting Started
Platform OverviewFeaturesArchitecture
Platform

Platform Overview

Architecture, technology stack, and design principles behind the customs compliance platform.

Design Principles

The platform is designed around three principles:

  1. Accuracy first -- duty calculations must match what a customs broker would file. Every rate type, every exemption, every CARICOM preference must be handled correctly.
  2. Broker-grade workflow -- the interface follows the actual customs declaration lifecycle: classify goods, estimate duties, prepare declaration, export for filing.
  3. Data integrity -- tariff data is versioned, timestamped, and traceable. The platform tracks when data was last refreshed and warns users if rates may be outdated.

Technology Stack

LayerTechnologyPurpose
FrontendNext.js 16 (React) with TurbopackServer-rendered application with App Router
StylingTailwind CSS 4Utility-first CSS framework
DatabasePostgreSQL 16 + pgvectorRelational data + vector similarity search
AI -- ClassificationAzure OpenAI (GPT-4.1-mini)Natural language to HS code classification
AI -- SearchAzure OpenAI (text-embedding-3-small)Semantic embedding for tariff code search
AI -- DocumentsAzure Document IntelligenceOCR and structured data extraction from invoices
AuthNextAuth v5 (Auth.js)Authentication with role-based access control
HostingAzure Container AppsServerless container hosting with auto-scale
CDN/SecurityCloudflare ProEdge caching, WAF, DDoS protection, SSL
InfrastructureTerraformInfrastructure as code for all Azure resources

Application Architecture

The platform follows a standard Next.js App Router architecture:

src/
  app/
    login/          -- Sign-in page (credentials + OAuth)
    signup/         -- Registration page (currently disabled)
    signout/        -- Sign-out handler
    portal/         -- User dashboard and activity overview
    classify/       -- AI-assisted HS code classification
    tariffs/        -- Tariff schedule browsing and search
    declarations/   -- C82 declaration management
    extract/        -- Document upload and data extraction
    reports/        -- Analytics and reporting
    billing/        -- Usage and billing management
    clients/        -- Customs broker client management
    settings/       -- User preferences and account settings
    audit/          -- Audit log viewer
    jobs/           -- Background job monitoring
    pipeline/       -- Data pipeline management
    proposal/       -- Classification proposal workflow
    docs/           -- In-app documentation (Fumadocs)
    api/            -- API route handlers
  db/               -- Database schema, migrations, queries
  lib/              -- Shared utilities, AI service clients

Database Schema

The database contains 25 tables organized around the core domain:

Table GroupKey TablesPurpose
Tariff datatariff_commodities, tariff_embeddings~7,300 HS codes with 11 duty rate types + vector embeddings
Usersusers, accounts, sessions, audit_logAuthentication, authorization, activity tracking
Declarationsdeclarations, declaration_itemsC82 declaration preparation and line items
Documentsuser_documentsUploaded commercial documents (invoices, bills of lading)
Exchange ratesexchange_ratesDaily FX rates for duty calculation in TTD
ClientsclientsCustoms broker client management
ReportsGenerated at query timeClassification and duty estimation analytics

Authentication and Roles

The platform implements 6 hierarchical roles:

RoleLevelCapabilities
Guest0Public tariff lookup only
Client1Search, classify, view own declarations
Broker2Full declaration management, client management
Viewer3Read-only access to all data
Reviewer4Audit classifications, approve declarations
Admin5Full system access, user management

Authentication uses scrypt password hashing, JWT tokens (8-hour expiry), and optional Cloudflare Turnstile CAPTCHA for bot protection.

AI Services

The platform integrates three Azure AI services across four deployed models:

Classification (GPT-4.1-mini)

Primary classification model. Takes a natural language goods description and returns the most likely HS code(s) with confidence scores. The model is prompted with T&T tariff context and returns structured JSON. GPT-4o-mini and GPT-4.1 are also deployed as fallback/evaluation models.

Semantic Search (text-embedding-3-small)

Pre-computed 1536-dimension embeddings for all ~7,300 tariff commodity descriptions. User queries are embedded at search time and matched via cosine similarity using pgvector. This powers the "search by description" feature.

Document Intelligence (prebuilt-layout)

Extracts structured data from uploaded commercial invoices and bills of lading using Azure's prebuilt document models. Extracted fields are mapped to declaration line items.

Deployed Models

ModelVersionCapacity (TPM)Purpose
gpt-4.1-mini2025-04-14200Primary classification
gpt-4o-mini2024-07-18100Fallback classification
gpt-4.12025-04-1450Complex classification
text-embedding-3-smallv1120Semantic search embeddings

All AI service usage is governed by a spend guard: $5/day and $25/month hard limits, enforced at the application level.

Getting Started

An introduction to the customs compliance and trade facilitation platform.

Features

Detailed feature inventory of the customs compliance platform.

On this page

Design PrinciplesTechnology StackApplication ArchitectureDatabase SchemaAuthentication and RolesAI ServicesClassification (GPT-4.1-mini)Semantic Search (text-embedding-3-small)Document Intelligence (prebuilt-layout)Deployed Models