Happy House - Ecommerce Docs
Developer ResourcesShipping

Shipping Features and Flows

Complete feature list, actor journeys, state flows, business rules, edge cases, and diagrams for the Shipping module.

Shipping Features and Flows

Use this page for the shipping domain: what it does for admins and customers, and how each flow behaves from start to finish.

1. Documentation Evidence

Source TypeFiles or DocsWhat Was Extracted
APIapps/api/src/modules/shipping/admin/shipping-admin.controller.ts, shipping/customer/shipping-quote-customer.controller.tsRoutes, permissions, rate limits
Backendshipping-admin.service.ts, shipping-admin-bulk.service.ts, shipping-quote-customer.service.ts, shipping-serviceability.service.tsUpsert semantics, bulk transaction, availability flags
Schemapackages/db/src/schema/shipping/shipping-rate.tsdistrict_id unique, fee bigint minor units
Cachecache-invalidation.tags.tsshipping domain
Error registryapps/api/src/common/types/error-codes.ts (// SHIPPING)SHIPPING_* codes

2. Feature Summary

FieldValue
Moduleshipping
SubmoduleN/A
Primary user valueA delivery fee and serviceability answer for every district, configurable in bulk
ActorsAdmin, customer (signed in), worker/system
Main entry points/api/admin/shipping/* (5 routes), GET /api/mobile/shipping/quote
Main outputsCoverage list, rate responses, bulk report, quotes
Related docsAPI, Backend

3. Actor Matrix

ActorCan DoCannot DoAuth RequirementNotes
AdminView coverage, get/set/delete a district rate, bulk priceOperate without the role grants the seed providesAdmin JWT + Shipping_READ/Shipping_UPDATE/Shipping_DELETE — granted by the seed from the shared permission catalogWrites record activity
Customer (signed in)Quote a districtSee admin coverage, quote without loginJWTCUSTOMER_READ 60/min keyed on the account
Worker/systemNo worker surface

4. Capability Matrix

CapabilitySurfaceActorRoute/TriggerState ReadState WrittenLinked API Section
Coverage listAdminAdminGET /api/admin/shipping/districtsAll 77 districts + ratesAPI §4
Get one rateAdminAdminGET /districts/:districtId/rateOne district + rateAPI
Upsert rateAdminAdminPUT /districts/:districtId/rateDistrictshipping_rateAPI
Discard rateAdminAdminDELETE /districts/:districtId/rateDistrict + raterate row removedAPI
Bulk priceAdminAdminPOST /rates/bulkDistricts by scopeMany rate rowsAPI
QuoteCustomerCustomerGET /api/mobile/shipping/quote?districtId=District + rateAPI

5. User-Facing Flows

5.1 Quote delivery (customer)

Summary

At checkout, the client reads location.district.id off the selected address and quotes it. The answer is a fee (or "not serviceable") — never a 404 for an unserved place.

Sequence Diagram

Branches and Edge Cases

BranchConditionBehaviorError/Result
Active rateconfigured && active200 with feeserviceable: true
Paused or unconfiguredno active rate200 with fee: nullserviceable: false — branch on this, not status
Unknown districtuuid names nothing404SHIPPING_DISTRICT_NOT_FOUND
Free deliveryfee = 0200 with fee 0serviceable: true

5.2 Admin flow — set a district fee

Summary

The admin coverage screen lists all 77 districts; each unconfigured one has "set fee". Saving is an upsert — no create-vs-edit branch.

Sequence Diagram

Branches and Edge Cases

BranchConditionBehaviorError/Result
PauseisActive: falseFee keptconfigured: true, active: false
Negative feefee < 0400SHIPPING_FEE_NEGATIVE
Missing permissionRole lacks Shipping_UPDATE403Add to the permission catalog + re-seed
Repeat callSame district twiceSecond replaces firstUpsert, never 409

5.3 Admin flow — bulk price

Scopes union and de-duplicate: explicit districts, whole provinces, or all of Nepal. One transaction — an unknown id rejects the entire request. Omitting fee makes it status-only, which cannot create a configuration; those districts are skipped and named.

6. Admin Flows

Covered in §5.2/§5.3. All admin writes record activity and invalidate the shipping cache domain. There is deliberately no bulk delete — use bulk isActive: false to stop delivering while keeping every configured fee.

7. Lifecycle and State Transitions

7.1 The district's shipping state

FromEvent/ActionToGuard ConditionSide Effects
unconfiguredPUT with feeconfigured (active per isActive)fee >= 0Cache invalidation
configuredPUT { isActive: false }pausedFee kept
pausedPUT { isActive: true }activeOne-toggle re-enable
configuredDELETEunconfiguredFee discarded; coverage list reflects it
anybulk status-onlyanydistricts without a fee are skipped, namedReport

9. Data and Side Effects by Flow

FlowDB WritesCache EffectsJobsRealtimeAnalyticsNotifications
Upsert rateshipping_rateshipping domain
Delete raterate row removedshipping domain
Bulkmany rate rows (one tx)shipping domain
Quoteread (serviceability cache)

10. Error and Recovery Flows

ScenarioTriggerUser/System ExperienceRecoverySource
Bulk partial failure impossibleUnknown idEntire request rejected, nothing writtenFix the scopeone transaction
Permission missingRole lacks Shipping_*403Add to the shared permission catalog + re-seedRoleGuard
Rate limitBulk 5/min429Build UI to submit onceADMIN_BULK_WRITE
Cache staleAdmin editNext read freshInvalidation after commitshipping domain

11. Diagrams Required Per Module

  • Actor capability diagram — §3/§4.
  • Sequence diagram per major flow — §5.1/§5.2.
  • Activity diagram — §5.3.
  • State machine diagram — §7.1.
  • Data side-effect diagram — §9.
  • Error branch diagram — §5.3/§10.

12. Mandatory Feature and Flow Deep-Dive Pack

12.1 Feature Inventory With Minor Behaviors

FeatureMinor BehaviorActorTriggerUser/System ResultBackend Side EffectSource
Coverage listLeft-joined districtsAdminGET /districtsUnconfigured visibleDistrict rows without rate rows listedservice
Coverage listStatus filterAdmin?status=unconfiguredSubset
Coverage listPricing filterAdmin?pricing=freefee=0 subset
Coverage listSearchAdmin?search=Name match
UpsertPauseAdminisActive:falseFee kept
UpsertRepeatAdminSecond callReplace
DeleteUnconfigured targetAdminDELETE on no rate404SHIPPING_RATE_NOT_FOUND
BulkScope unionAdmindistricts + provinces + allDe-duplicated
BulkStatus-onlyAdminfee omittedSkip unconfigured + nameReport
QuoteFree deliveryCustomerfee 0fee 0
QuoteNot serviceableCustomerno active rate200 + false

12.2 Business Process Diagram Pack

12.3 Business Rules and Policy Traceability

RuleBusiness ReasonActor ImpactEnforced InAPI ImpactBackend ImpactTests
Fee in minor unitsMoney invariantAdmin enters 12000 for NPR 120DTO + schemaFee fieldbigint columnspec
Unserviceable = 200Coverage is informationCustomer branches on flagServiceQuote responsespec
Pause keeps feeOne-toggle re-enableAdmin sees configured+inactiveServicePUT semantics
District-keyed upsertNo create-vs-editAdmin UI simpleUnique district_idPUT replaces
Bulk all-or-nothingNo half-applied price changeAdmin retries fixed scopeOne transaction4xx on unknownspec
Status-only cannot createNo fee to insertAdmin sees skipped listServiceReport field
Shipping never reads addressesModule boundaryQuote takes districtIdService designQuote contractreviewed

12.4 Tradeoffs and Product Rationale

Product DecisionUser BenefitEngineering BenefitAlternativeTradeoffRisk
Flat fee per districtSimple pricingOne row per districtZone/weight modelsNo distance nuanceDocumented
Bulk 5/minReprice-all is atomicMatches blast radiusPer-district submitsSlower bulk editsUI submits once
Upsert PUTNo create/edit branchStricter permission onlyPOST+PUT pair
Permissions one-sourceShipping_* come from the shared catalogAdmin gets 403 only if seed not runpermission-catalog.ts + specpermissions-catalog spec

12.5 Flow Edge-Case Matrix

FlowEdge CaseTriggerExpected BehaviorUser/System FeedbackSource
QuoteUnconfiguredNo rate200, fee nullserviceable false
QuotePausedisActive false200, fee nullserviceable false
QuoteUnknown districtBad uuid404SHIPPING_DISTRICT_NOT_FOUND
QuoteFreefee 0fee 0serviceable true
BulkEmpty scopeNo keys400SHIPPING_BULK_SCOPE_EMPTY
BulkNo changeNeither field400SHIPPING_BULK_NO_CHANGE_REQUESTED
Bulk> 77 distinctImpossible from correct client409SHIPPING_BULK_LIMIT_EXCEEDED
BulkStatus-only on unconfiguredNo fee to insertSkipped + namedskippedDistricts
DeleteUnconfiguredNo row404SHIPPING_RATE_NOT_FOUND

12.6 Flow-to-Data Trace

FlowReadsWritesCacheJobs/EventsResponse Fields
Coveragedistrict + shipping_rateshippingrate response array
Upsertdistrict, rateshipping_rateinvalidaterate response
Bulkdistricts by scopeshipping_rate rowsinvalidatereport
Quotedistrict, rateserviceabilityquote response

12.7 Experience Quality Checklist

  • The doc explains what the actor is trying to accomplish.
  • The doc explains what the backend does that the actor does not see (left join, one transaction, cache).
  • The doc covers every minor flow and branch.
  • The doc includes user, admin, and system flows.
  • The doc explains business logic, tradeoffs, and rationale.
  • The doc maps every flow to API routes and backend side effects.
  • The doc includes diagrams appropriate to each flow type.
  • The doc covers edge cases and failure recovery.

13. Completion Checklist

  • Every feature, minor action, and submodule capability is listed.
  • Every actor has allowed and forbidden behavior.
  • Every major and minor flow includes steps, branches, and diagrams.
  • Every lifecycle has a transition table and state diagram.
  • Every flow links to the API and backend docs.
  • TDD dependencies are called out where they shape behavior (no TDD pages published yet).

See Also