Ship Quote MongoDB Collections: Full Schema Reference
Ship Quote MongoDB schema reference: six collections, every field, index, and relationship for Agency, Location, PalletType, Zone, ZoneRules, and Rate.
Use this file to discover all available pages before exploring further.
Ship Quote stores its configuration in six MongoDB collections managed through Mongoose. Understanding how these models relate to each other is essential for seeding data correctly and for extending the system with new carriers. This page documents every field in every schema, the indexes that back the rate engine’s queries, and the relationships that tie the models together.
An Agency owns one or more Zones, PalletTypes, and Rates.
A Zone has zero or more ZoneRules that refine province-level zone assignment by postal code range.
A Rate references its zone by the zoneName string (not an ObjectId) to allow fast composite-key cache lookups without joins.
A Rate optionally references a PalletType via palletTypeId — present for per-pallet-type pricing, absent (null) for weight-volume or parcel pricing where the zone-level key is sufficient.
The Agency model (api/src/lib/models/agency.model.js) is the root entity for every carrier registered in the system. It controls whether the carrier is active, which shipment types it supports, what scope it covers, and — for API carriers — how to connect to the external endpoint.
Derived from name (lowercased, accents stripped, spaces → _). Unique index.
type
String enum
"static"
"static" | "api" | "hybrid"
active
Boolean
true
Set to false to disable without deleting.
rules.hasAndaluciaRule
Boolean
false
Whether the agency applies special Andalucía routing rules.
rules.supportsPallets
Boolean
true
Pallet items are processed for this agency.
rules.supportsParcels
Boolean
false
Parcel items are processed for this agency.
rules.coverage
[String]
["national"]
Accepted values: "national", "international".
supplements.fuelSurcharge.enabled
Boolean
false
Toggle fuel surcharge on/off.
supplements.fuelSurcharge.type
String enum
"percentage"
"percentage" or "fixed".
supplements.fuelSurcharge.value
Number
0
Percentage (e.g. 5.5) or fixed euro amount (e.g. 2.50).
apiConfig.baseUrlApi
String
—
Required when type is "api".
apiConfig.timeout
Number
3000
HTTP timeout in milliseconds for external carrier calls.
apiConfig.apiKey
String
—
Required when type is "api". Passed via X-API-Key header.
apiConfig.endpoints.quotations
String
—
Path appended to baseUrlApi for rate queries.
apiConfig.endpoints.transportOrders
String
—
Path for order creation (future use).
apiConfig.baseUrlApi and apiConfig.apiKey have conditional required validators — they are only enforced when type === "api". Static agencies can omit the apiConfig block entirely.
The Location model (api/src/lib/models/location.model.js) stores the geographical reference data: every province (and optionally country) that the system can route shipments to.
locationSchema.index({ countryCode: 1, normalizedName: 1 });locationSchema.index({ adminFullCode: 1 }, { unique: true });// normalizedName also carries a single-field index declared inline on the path
The adminFullCode unique index prevents duplicate province records. The composite { countryCode, normalizedName } index accelerates province look-ups by name when filtering by country.
The PalletType model (api/src/lib/models/palletType.model.js) defines the pallet dimensions and weight limits recognised by a specific agency. The rate engine matches each inbound pallet item against the agency’s sorted pallet types to determine which rate bracket applies.
Pallet type label, e.g. "CUARTO", "QUARTER PALLET", "Euro Pallet" (max 60 chars).
constraints.maxWeight
Number
Maximum gross weight in kg. Required, ≥ 0.
constraints.maxHeight
Number
Maximum stacked height in cm. Defaults to 0 (unconstrained).
constraints.maxLength
Number
Maximum length in cm. Defaults to 0 (unconstrained).
constraints.maxWidth
Number
Maximum width in cm. Defaults to 0 (unconstrained).
Constraint values of 0 mean the dimension is not checked during pallet matching. Empty strings and null are coerced to 0 by the sanitizeInput setter.
At startup, loadAgencyTariffs() sorts each agency’s pallet types by maxWeight ascending, then maxHeight ascending, so the matching algorithm picks the smallest valid type — ensuring customers are priced accurately rather than being over-charged.
The Zone model (api/src/lib/models/zone.model.js) maps a set of provinces to a named pricing zone for a given agency. The rate engine resolves which zone applies to a destination by searching the province list (or, via ZoneRules, by postal code range).
The ZoneRules model (api/src/lib/models/zone.rules.model.js) provides postal-code-level overrides for province-level zone assignment. Some agencies route a specific postal code range within a province to a different zone from the rest of that province — ZoneRules captures those exceptions.
The Rate model (api/src/lib/models/rate.model.js) stores the pricing tariff for a specific combination of agency, shipment type, zone, and (optionally) pallet type. Each rate document contains an array of services (e.g. economy, premium) each with its own priceBreaks, surcharges, and limits.
This compound index directly mirrors the ratesByKey cache structure. It also accelerates the bulk load query (Rate.find({ agencyId: { $in: agencyIds } })) used at startup.
The same key is constructed at query time in the calculators, so a rate lookup is a single Map.get(key) call with no database round-trip.
When adding a new rate document via the REST API or seed script, ensure zoneName exactly matches the corresponding Zone.name field — the lookup is case-sensitive. A mismatch will cause the rate engine to return a ZONE_NOT_FOUND incident for that agency.