| name | flexport-reference-architecture |
| description | Implement Flexport reference architecture for supply chain integrations
with best-practice project layout, service boundaries, and data flow.
Trigger: "flexport architecture", "flexport project structure", "flexport system design".
|
| allowed-tools | Read, Write, Edit |
| version | 1.6.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","logistics","flexport"] |
| compatibility | Designed for Claude Code |
Flexport Reference Architecture
Overview
Production reference architecture for Flexport logistics integrations. Three core services: Ingest (webhooks + polling), Core (business logic), and Expose (API + dashboard).
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Application โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโค
โ Ingest โ Core โ Expose โ
โ โ โ โ
โ Webhook โ Shipment โ REST API โ
โ Receiver โ Service โ (your clients) โ
โ โ โ โ
โ Scheduled โ Product โ Dashboard โ
โ Sync โ Service โ (Next.js/Astro) โ
โ โ โ โ
โ Event โ Invoice โ Notifications โ
โ Queue โ Service โ (email/slack) โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโค
โ Infrastructure: Cache (Redis) โ DB (Postgres) โ Queue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Flexport API v2 (https://api.flexport.com) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Project Layout
flexport-integration/
โโโ src/
โ โโโ flexport/
โ โ โโโ client.ts # Singleton API client
โ โ โโโ types.ts # Zod schemas for API responses
โ โ โโโ webhooks.ts # Webhook signature + routing
โ โโโ services/
โ โ โโโ shipment.service.ts # Shipment CRUD + tracking
โ โ โโโ product.service.ts # Product catalog sync
โ โ โโโ invoice.service.ts # Commercial + freight invoices
โ โ โโโ booking.service.ts # Booking creation + amendments
โ โโโ jobs/
โ โ โโโ sync-shipments.ts # Scheduled full sync (hourly)
โ โ โโโ cache-warmup.ts # Pre-populate caches on deploy
โ โโโ api/
โ โ โโโ routes.ts # Express/Fastify routes
โ โ โโโ middleware.ts # Auth, logging, error handling
โ โโโ config/
โ โโโ flexport.ts # API config per environment
โ โโโ cache.ts # TTL settings per data type
โโโ tests/
โ โโโ unit/ # Mocked API tests
โ โโโ integration/ # Live API tests (CI only)
โโโ .env.example
โโโ docker-compose.yml # Redis + Postgres for local dev
Data Flow
Flexport API โโwebhookโโ> Ingest โโqueueโโ> Core โโcacheโโ> Expose
โ โ
โโโ DB (Postgres) โ
- Ingest: Webhook receiver validates signatures, enqueues events
- Core: Services process events, sync with Flexport API, update DB
- Expose: API/dashboard reads from DB + cache, never directly from Flexport
- Scheduled jobs: Hourly full sync catches any missed webhooks
Key Design Decisions
| Decision | Choice | Rationale |
|---|
| Database | PostgreSQL | Structured logistics data, JSONB for flexible fields |
| Cache | Redis with 5min TTL | Shipment data changes infrequently |
| Queue | BullMQ | Retry, dead letter, rate limiting built in |
| API client | Custom fetch wrapper | No official SDK, typed with Zod |
| Webhook processing | Async via queue | Fast 200 response, process later |
Resources
Next Steps
For multi-environment setup, see flexport-multi-env-setup.