Cargomatiq is a shipment-centric freight operations workspace with a retained Finance reconciliation module. It makes operational emails and documents usable alongside finance workflows; it does not replace reconciliation.
The current release is a demo-ready MVP: multi-mode in its data model, with a complete replayable Ocean Export FCL workflow.
- Operations Inbox for
.emlreplay and IMAP-ingested messages - Raw MIME and attachment preservation in local object storage
- Idempotent email ingestion using mailbox UIDVALIDITY/UID, Message-ID, and raw-content hashes
- Document classification for Commercial Invoice, Packing List, Ocean Booking Confirmation, Bill of Lading, and Draft Bill of Lading
- Provider-neutral extraction contract with deterministic fixture extraction for the MVP
- Shipment resolution from booking, BL, container, PO, invoice, and related references
- Shipment Workspace with canonical facts, evidence, documents, communication, timeline, exceptions, and tasks
- Operational exceptions for consignee mismatch, gross-weight mismatch, schedule change, and missing required documents
- Logisys and BT snapshot uploads
- Vendor and master-data management
- Reconciliation job creation, extraction review, matching, reruns, and SOA handling
- Finance exception workbench, reconciliation history, reports, and exports
- Synchronization of finance reconciliation exceptions into the generic operational exception model
| Layer | Technology |
|---|---|
| Backend | FastAPI, SQLAlchemy, Alembic |
| Database | PostgreSQL (Supabase supported) |
| PostgreSQL driver | Psycopg 3 |
| Frontend | Next.js 14, React 18, Tailwind CSS |
| File storage | Local object storage interface (backend/storage) |
IMAP plus replayable .eml files |
- Python with
venv - Node.js and npm
- PostgreSQL, either local or hosted through Supabase
Use a Supabase Session Pooler connection if the direct database endpoint is unreachable from your network.
All commands below use Windows Command Prompt (cmd).
cd D:\Projects\cargomatiq\cargomatiq\backend
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install --upgrade pip
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
copy .env.example .envIf the virtual environment already exists, skip py -m venv .venv.
Edit backend\.env. For local PostgreSQL:
DATABASE_URL=postgresql+psycopg://postgres:YOUR_PASSWORD@localhost:5432/cargomatiq
STORAGE_DIR=./storageFor Supabase, use its Session Pooler host and append sslmode=require:
DATABASE_URL=postgresql+psycopg://postgres.YOUR_PROJECT_REF:YOUR_PASSWORD@aws-0-YOUR_REGION.pooler.supabase.com:5432/postgres?sslmode=require
STORAGE_DIR=./storageReplace all placeholders, remove square brackets, and never commit .env to Git.
cd D:\Projects\cargomatiq\cargomatiq\backend
.\.venv\Scripts\python.exe -m alembic upgrade headIn a second terminal:
cd D:\Projects\cargomatiq\cargomatiq\frontend
npm ci
npm run devIn the backend terminal:
cd D:\Projects\cargomatiq\cargomatiq\backend
.\.venv\Scripts\python.exe -m uvicorn app.main:app --host 127.0.0.1 --port 8000Open http://localhost:3000. The API is at http://127.0.0.1:8000; interactive API documentation is at http://127.0.0.1:8000/docs.
The sidebar is split by domain.
| Area | Pages | Purpose |
|---|---|---|
| Operations | Operations dashboard, Inbox, Shipments, Exceptions, Tasks | Process shipment communications and operational work |
| Finance | Reconciliation, New Reconciliation, Reconciliation History, Finance Exceptions, Finance Reports | Keep the accounting reconciliation workflow intact |
| Settings | Finance Data Uploads, Master Data | Upload source exports and manage vendors/master data |
Original Finance routes remain available for compatibility:
| Route | Feature |
|---|---|
/jobs |
Reconciliation jobs |
/jobs/new |
New reconciliation workflow |
/history |
Completed reconciliation history |
/exceptions |
Finance exception workbench |
/snapshots |
Logisys and BT source-data uploads |
/master |
Master-data uploads and management |
/reports |
Finance reports and exports |
This is the fastest way to populate a new database without an email account.
- Start the backend and frontend.
- Open Operations → Inbox.
- Select Replay demo.
Five checked-in .eml files pass through the same ingestion pipeline used for manual replay and IMAP. The result is one Ocean Export FCL shipment; invoice and packing-list evidence; booking confirmation and draft BL documents; a consignee mismatch exception; a schedule-change exception; and one unresolved email requiring review.
Replay is idempotent: running it again does not create duplicate emails or shipments. You can also upload an individual .eml from the Inbox page.
Add this to backend\.env, then restart the backend. Startup creates the configured mailbox record for the demo organization; the password is never stored in the database.
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_USERNAME=ops@example.com
IMAP_PASSWORD=replace-with-a-new-app-password
IMAP_FOLDER=INBOX
IMAP_POLL_SECONDS=60For Gmail, enable two-step verification and create a Gmail App Password. Do not use a normal account password. If an app password was pasted in chat, a terminal recording, screenshot, or Git history, revoke it and generate a new one.
One polling cycle:
cd D:\Projects\cargomatiq\cargomatiq\backend
.\.venv\Scripts\python.exe -m app.operations.worker --imapContinuous polling while the terminal remains open:
.\.venv\Scripts\python.exe -m app.operations.worker --imap --watchUse a custom interval if needed:
.\.venv\Scripts\python.exe -m app.operations.worker --imap --watch --interval 120The first live poll records the current highest UID and deliberately imports no old mail. This prevents an unexpected historical import. Send or forward a new email after that first poll; the next cycle ingests it. The worker advances the mailbox cursor only after raw email persistence succeeds. If IMAP UIDVALIDITY changes, polling stops for review rather than risking an incorrect cursor.
IMAP / .eml replay
|
v
Raw MIME + attachments stored and hashed
|
v
Document classification + fixture extraction
|
v
Immutable field observations with evidence and confidence
|
v
Reference-based shipment resolution
|
+--> auto matched -> link to existing shipment
+--> new job -> create shipment workspace
+--> needs review -> leave in Operations Inbox
|
v
Canonical facts, timeline, exceptions, and tasks
The extraction implementation is intentionally deterministic for this MVP. DocumentExtractionProvider is the extension point for a future structured document-model provider; no external AI extraction provider is configured yet.
The previous Finance application used backend\recon.db. The migration utility copies finance records to PostgreSQL while preserving primary keys and existing relationships. It has been validated against the included legacy database and handles vendors, snapshots, line items, reconciliation jobs, SOAs, results, and vendor mapping cache.
Before running it:
- Confirm
backend\.envpoints to the intended Supabase Session Pooler or local PostgreSQL database. - Run
alembic upgrade headfirst. - Ensure the target does not already contain finance data. The script stops safely if it does, preventing duplicate records.
- Keep a backup of
recon.db.
Then run:
cd D:\Projects\cargomatiq\cargomatiq\backend
.\.venv\Scripts\python.exe scripts\migrate_sqlite_to_postgres.py recon.dbThe utility reports copied row counts. Restart the backend and refresh the browser when it completes.
Historical upload paths are retained as legacy references. Files no longer present at their original paths cannot be reconstructed automatically; re-upload them if they are needed in new local object storage.
The frontend uses these endpoints; all are documented at /docs.
| Endpoint | Description |
|---|---|
GET /api/operations/inbox |
List received and processed operational emails |
POST /api/operations/inbox/replay |
Upload and replay one .eml file |
POST /api/operations/demo/replay |
Run the five-message Ocean Export demo |
GET /api/operations/shipments |
List shipment workspaces |
GET /api/operations/shipments/{id} |
Shipment facts, evidence, events, and work items |
POST /api/operations/shipments/{id}/emails |
Manually link an inbox email to a shipment |
GET/PATCH /api/operations/exceptions |
List or update operational exceptions |
GET/PATCH /api/operations/tasks |
List or update operational tasks |
GET/POST /api/jobs |
List or create Finance reconciliation jobs |
POST /api/snapshots/logisys |
Upload Logisys source data |
POST /api/snapshots/bt |
Upload BT source data |
Build the frontend:
cd D:\Projects\cargomatiq\cargomatiq\frontend
npm run buildCheck Python syntax:
cd D:\Projects\cargomatiq\cargomatiq\backend
.\.venv\Scripts\python.exe -m compileall -q app scriptsThe operational replay test is tests\test_operations.py. Install pytest in the backend virtual environment if needed, then run it from the repository root:
cd D:\Projects\cargomatiq\cargomatiq
.\backend\.venv\Scripts\python.exe -m pip install pytest
set PYTHONPATH=%CD%\backend
.\backend\.venv\Scripts\python.exe -m pytest tests -qbackend/
alembic/ Database migrations
app/api/ Finance and Operations API routes
app/db/ SQLAlchemy models and database session
app/operations/ Ingestion, IMAP, extraction, rules, and worker
app/operations/demo_emails/
Replay fixtures for the Ocean Export demo
scripts/ SQLite-to-PostgreSQL migration utility
storage/ Local raw email and attachment object storage
frontend/
src/app/ Next.js pages
src/components/ Application shell and navigation
tests/ Automated Operations replay coverage
This is a demo-ready MVP, not a production-hardened multi-tenant deployment.
- The schema is organization-ready, but authentication and user provisioning are not implemented.
- The app starts with one
demoorganization. - Ocean Export FCL is the deep demo workflow. Ocean, air, and road are supported by the core model, but air and road do not yet have full workflows.
- IMAP is the only live connector. Gmail OAuth and Microsoft 365 are future work.
- Processing is PostgreSQL-backed and retryable without Redis, Kafka, or microservices.
- A live extraction-model provider is deliberately deferred.
- There is no autonomous outbound email, tracking-platform integration, customs workflow, or chatbot in this MVP.
A new Supabase database contains schema only. Use Replay demo to create Operations data, upload Finance source files for new reconciliation work, or run the SQLite migration to restore existing finance records.
Use the Supabase Session Pooler URL rather than the direct db.<project>.supabase.co endpoint, use the postgresql+psycopg:// scheme, and include ?sslmode=require.
Install the current backend requirements and use the documented postgresql+psycopg:// URL:
.\.venv\Scripts\python.exe -m pip install -r requirements.txtThat is expected on the first poll. It establishes a safe cursor at the newest existing message. Send a new email and wait for the next worker cycle.
Confirm the host, port, folder, username, and fresh app password in .env, then restart the backend before rerunning the worker.
- Keep
backend\.envprivate and excluded from Git. - Rotate any database or email credential that has been exposed.
- Use separate Supabase credentials for development and production.
- Back up
recon.dbbefore migration and verify the reported migration counts.