{"schemaVersion":"mappls.journey-workshop.v1","slug":"connected-fleet-trip","journeySlug":"connected-fleet-trip","title":"Build Connected fleet trip","summary":"An eight-lab, source-bounded workshop for the complete trip lifecycle: exact commands and events, durable records, replay, concurrency, unknown outcomes, hostile fixtures, a maintained capstone, and production exit evidence.","duration":"2 hr 10 min","level":"Advanced","productSlug":"intouch-telematics","stateModel":"stateful","aggregate":"trip","actorCount":4,"stateCount":6,"transitionCount":7,"eventCount":7,"sourceGuideSlugs":["mappls-intouch-rest-apis","mappls-intouch-android-sdk","mappls-intouch-ios-sdk","mappls-intouch-ios-distribution","mappls-intouch-ios-distribution-base","mapmyindia-intouch-ios-sdk","mappls-react-native-intouch-sdk"],"contractSlugs":["intouch-post-trips-this-api-will-create-a-trip","intouch-get-trips-this-api-will-get-all-the-trips-for-a-user","intouch-get-trips-id-gets-the-details-of-a-single-trip","intouch-post-trips-id-close-post-api-to-close-a-trip","intouch-get-devices-gets-the-live-data-of-devices","intouch-get-devices-deviceid-events-gets-the-historical-location-events-of-a-device"],"relatedTutorialSlugs":[],"sample":{"slug":"delivery-control-tower","name":"Delivery Control Tower","downloadPath":"/downloads/delivery-control-tower.zip","checksumPath":"/downloads/delivery-control-tower.zip.sha256","verifiedTestCount":7,"runCommand":"npm test --workspace @mappls-example/delivery-control-tower"},"labs":[{"slug":"model-lifecycle","title":"Model the lifecycle before the UI","duration":"15 min","objective":"Turn the trip blueprint into an explicit aggregate boundary owned by the application.","build":["planned: Stops, service window, asset, driver, and business identifiers are fixed enough to create the trip.","ready: The trip and assigned device are provisioned, entitled, and emitting sufficiently fresh location.","active: Positions, events, progress, ETA, and exception state are continuously observed.","exception: A deviation, delay, device gap, geofence, or safety event requires operator attention.","closing: Arrival is plausible but late events, final proof, and device state are still being reconciled.","closed: The provider trip and internal aggregate are closed with a final trace, metrics, and exception record."],"prove":["Every persisted state exists in the reviewed blueprint.","Terminal states reject ordinary forward commands.","Recovery text is operational guidance, not another hidden state."]},{"slug":"command-event-contract","title":"Implement every command and event pair","duration":"20 min","objective":"Make intent, actor authority, allowed source state, committed state, and emitted fact reviewable together.","build":["create_trip by Fleet planner: new aggregate → planned; emit trip.created.","confirm_device_ready by Telematics service: planned → ready; emit trip.ready.","start_trip by Driver: ready → active; emit trip.started.","raise_exception by Telematics service: active | exception → exception; emit trip.exception_raised.","resolve_exception by Operations controller: exception → active; emit trip.exception_resolved.","request_close by Driver: active | exception → closing; emit trip.close_requested.","close_trip by Telematics service: closing → closed; emit trip.closed."],"prove":["create_trip resolves to connected-fleet-trip-trip-created without claiming a provider webhook payload.","confirm_device_ready resolves to connected-fleet-trip-trip-ready without claiming a provider webhook payload.","start_trip resolves to connected-fleet-trip-trip-started without claiming a provider webhook payload.","raise_exception resolves to connected-fleet-trip-trip-exception-raised without claiming a provider webhook payload.","resolve_exception resolves to connected-fleet-trip-trip-exception-resolved without claiming a provider webhook payload.","request_close resolves to connected-fleet-trip-trip-close-requested without claiming a provider webhook payload.","close_trip resolves to connected-fleet-trip-trip-closed without claiming a provider webhook payload."]},{"slug":"durable-records","title":"Persist restart-safe records","duration":"15 min","objective":"Separate business identity, provider evidence, command receipts, immutable facts, audit, and downstream delivery.","build":["Trip aggregate: Current operational state and identity mapping. Keys: tripId, externalId, providerTripId, deviceId, state, version.","Telemetry envelope: Immutable position and vehicle observation. Keys: sourceEventId, deviceId, eventTime, receivedTime, position, quality.","Exception case: Operator-owned acknowledgement and resolution workflow. Keys: caseId, rule, severity, owner, status, sourceEventIds.","Trip revision: Recomputed summary when bounded late data arrives. Keys: tripId, revision, inputWatermark, metrics, generatedAt."],"prove":["Process restart restores the same aggregate version and command result.","Opaque SDK or native UI objects are not durable records.","Provider evidence and application decisions remain distinguishable."]},{"slug":"concurrency-replay","title":"Make concurrency and replay deterministic","duration":"15 min","objective":"Apply optimistic expected versions and aggregate-scoped idempotency before executing effects.","build":["A device is assigned to at most one active trip in the same operational context.","Raw telemetry is immutable and distinguished by event time and receipt time.","Derived live state can be rebuilt from ordered observations and commands.","Trip closure never discards unresolved exceptions or data gaps.","Every provider identifier is mapped to the internal trip and tenant."],"prove":["An exact replay returns the first result without another event or version.","A reused key with different intent conflicts.","A stale expected version changes no durable truth."]},{"slug":"effects-reconciliation","title":"Control effects and unknown outcomes","duration":"15 min","objective":"Commit outbox intent atomically, execute effects outside the transaction, and reconcile ambiguous results.","build":["Telemetry arrives late or out of order: detect with Event time is behind the trip watermark or its sequence creates a gap. Recover with Store raw input, recompute the bounded affected window, and publish a new derived revision.","Device stops reporting: detect with Freshness exceeds the vehicle-specific health threshold. Recover with Raise a connection exception, show last-known time explicitly, and avoid extrapolating authoritative position.","Close succeeds remotely but the response is lost: detect with Internal trip remains closing while provider detail reports closed. Recover with Reconciliation closes the internal aggregate with the original command identity.","Driver or vehicle assignment changes mid-trip: detect with A control-plane version differs from the assignment captured at trip start. Recover with Use an explicit transfer transition and retain both assignment intervals."],"prove":["A timeout remains an unknown outcome until identity-based reconciliation completes.","Retries are bounded and preserve the original business and command identities.","Dead-letter or manual review retains the entire attempt history."]},{"slug":"hostile-scenarios","title":"Run all hostile fixture scenarios","duration":"15 min","objective":"Exercise the success path plus replay, concurrency, state, and response-loss failures without an account.","build":["Complete journey: Commit the shortest reviewed success path to the journey-specific operating target.","Idempotent replay: Repeat one command identity and prove that version, event identity, and side effects do not duplicate.","Stale version: Reject a command based on an outdated aggregate version without changing durable truth.","Invalid transition: Reject a known command when the current state does not permit it.","Unknown outcome recovery: Reconcile after a lost response, then replay the original command identity safely."],"prove":["All fixture checks pass for all five scenarios.","Rejected commands emit no event and do not increment version.","The fixture makes zero provider calls and exposes no write tool."]},{"slug":"maintained-capstone","title":"Trace the Delivery Control Tower capstone","duration":"20 min","objective":"Follow the maintained source through domain rules, adapter seam, repository transaction, HTTP boundary, UI evidence, and restart test.","build":["Run the app's declared test suite (7 tests).","Run fixture mode without a credential.","Inspect audit and outbox evidence after each transition.","Restart the process and continue the same aggregate."],"prove":["The downloadable archive checksum verifies before execution.","The capstone covers the journey target without inventing provider completion.","Browser and HTTP surfaces report the same durable version."]},{"slug":"production-exit","title":"Qualify the real integration boundary","duration":"15 min","objective":"Replace only reviewed adapter seams and collect independent production evidence without weakening application invariants.","build":["Telemetry freshness, ordering lag, rejection, and quality","Active trips without a healthy assigned device","ETA error and route-deviation duration","Open exception age by severity and owner","Trips stuck in closing and reconciliation outcomes","Raw-to-derived lineage and revision count"],"prove":["Exact product entitlement and regional behavior are validated separately.","Provider contract tests cover success, rejection, throttling, timeout, and unknown outcome.","Security, privacy, operations, rollback, and product owners approve exact evidence.","Fixture completion is never presented as provider or production completion."]}],"codeSamples":[{"language":"typescript","label":"TypeScript aggregate boundary","code":"type State = \"planned\" | \"ready\" | \"active\" | \"exception\" | \"closing\" | \"closed\";\ntype CommandName = \"create_trip\" | \"confirm_device_ready\" | \"start_trip\" | \"raise_exception\" | \"resolve_exception\" | \"request_close\" | \"close_trip\";\n\ntype Command = {\n  name: CommandName;\n  aggregateId: string;\n  expectedVersion: number;\n  idempotencyKey: string;\n};\n\nconst transitions = {\n  \"create_trip\": { from: [null], to: \"planned\", event: \"trip.created\" },\n  \"confirm_device_ready\": { from: [\"planned\"], to: \"ready\", event: \"trip.ready\" },\n  \"start_trip\": { from: [\"ready\"], to: \"active\", event: \"trip.started\" },\n  \"raise_exception\": { from: [\"active\", \"exception\"], to: \"exception\", event: \"trip.exception_raised\" },\n  \"resolve_exception\": { from: [\"exception\"], to: \"active\", event: \"trip.exception_resolved\" },\n  \"request_close\": { from: [\"active\", \"exception\"], to: \"closing\", event: \"trip.close_requested\" },\n  \"close_trip\": { from: [\"closing\"], to: \"closed\", event: \"trip.closed\" },\n} as const;\n\nexport function decide(current: { state: State | null; version: number }, command: Command) {\n  const rule = transitions[command.name];\n  if (command.expectedVersion !== current.version) throw new Error(\"version_conflict\");\n  if (!rule.from.includes(current.state as never)) throw new Error(\"invalid_transition\");\n  return {\n    state: rule.to as State,\n    version: current.version + 1,\n    event: rule.event,\n    idempotencyKey: command.idempotencyKey,\n  };\n}\n\n// Persist the result, immutable event, audit row, and outbox intent atomically.\n// Store the first result by idempotencyKey before executing another effect."},{"language":"sql","label":"SQL durability skeleton","code":"CREATE TABLE journey_connected_fleet_trip (\n  aggregate_id text PRIMARY KEY,\n  state text NOT NULL,\n  version bigint NOT NULL CHECK (version > 0),\n  updated_at timestamptz NOT NULL DEFAULT now()\n);\n\nCREATE TABLE journey_connected_fleet_trip_commands (\n  aggregate_id text NOT NULL REFERENCES journey_connected_fleet_trip(aggregate_id),\n  idempotency_key text NOT NULL,\n  request_hash text NOT NULL CHECK (length(request_hash) = 64),\n  committed_version bigint NOT NULL,\n  result_json jsonb NOT NULL,\n  PRIMARY KEY (aggregate_id, idempotency_key)\n);\n\nCREATE TABLE journey_connected_fleet_trip_outbox (\n  event_id text PRIMARY KEY,\n  aggregate_id text NOT NULL,\n  aggregate_version bigint NOT NULL,\n  event_type text NOT NULL,\n  payload jsonb NOT NULL,\n  published_at timestamptz\n);\n\n-- In one transaction: lock aggregate, compare version, decide, append audit/event,\n-- insert the outbox row, and remember the exact command result."},{"language":"curl","label":"Complete fixture journey","code":"curl --request POST 'https://developer.mappls.com/api/journey-simulator' \\\n+  --header 'content-type: application/json' \\\n+  --data '{\"journey\":\"connected-fleet-trip\",\"scenario\":\"complete-journey\"}'"},{"language":"curl","label":"Unknown-outcome drill","code":"curl --request POST 'https://developer.mappls.com/api/journey-simulator' \\\n+  --header 'content-type: application/json' \\\n+  --data '{\"journey\":\"connected-fleet-trip\",\"scenario\":\"unknown-outcome\"}'\n\n# Reconcile trip identity and the original idempotency key.\n# Never mint a replacement key merely because the response was lost."},{"language":"json","label":"First command envelope","code":"{\n  \"command\": \"create_trip\",\n  \"aggregateId\": \"fixture-connected-fleet-trip-001\",\n  \"expectedVersion\": 0,\n  \"idempotencyKey\": \"cmd_connected-fleet-trip_001\",\n  \"evidenceBoundary\": \"application-owned-workshop\"\n}"}],"simulationScenarios":[{"slug":"complete-journey","title":"Complete journey","outcome":"Commit the shortest reviewed success path to the journey-specific operating target.","href":"/tools/journey-lab?journey=connected-fleet-trip&scenario=complete-journey#lab"},{"slug":"idempotent-replay","title":"Idempotent replay","outcome":"Repeat one command identity and prove that version, event identity, and side effects do not duplicate.","href":"/tools/journey-lab?journey=connected-fleet-trip&scenario=idempotent-replay#lab"},{"slug":"stale-version","title":"Stale version","outcome":"Reject a command based on an outdated aggregate version without changing durable truth.","href":"/tools/journey-lab?journey=connected-fleet-trip&scenario=stale-version#lab"},{"slug":"invalid-transition","title":"Invalid transition","outcome":"Reject a known command when the current state does not permit it.","href":"/tools/journey-lab?journey=connected-fleet-trip&scenario=invalid-transition#lab"},{"slug":"unknown-outcome","title":"Unknown outcome recovery","outcome":"Reconcile after a lost response, then replay the original command identity safely.","href":"/tools/journey-lab?journey=connected-fleet-trip&scenario=unknown-outcome#lab"}],"acceptance":["All 7 reviewed transitions are implemented with actor and source-state checks.","All 7 application event identities are immutable and versioned.","Exact replay, idempotency conflict, stale version, invalid transition, and unknown outcome are tested.","Aggregate, event, audit, command result, and outbox intent commit atomically.","The Delivery Control Tower capstone passes 7 declared tests after archive checksum verification.","Provider entitlement, payload, callback, completion, and production behavior remain independently evidenced."],"sourceBoundary":["The journey blueprint and application event contracts are implementation guidance, not Mappls provider payload specifications.","Only linked normalized contracts and source guides may define provider request syntax; empty evidence is never backfilled.","The simulator and maintained capstone operate in explicit fixture mode and make no entitlement claim.","Credentials, precise production payloads, opaque native objects, and provider secrets stay outside workshop inputs and durable examples."],"releaseBoundary":"Workshop completion proves an application-owned reliability design only. Production still requires issued entitlement, exact adapter contract tests, regional and quota validation, security/privacy review, operational drills, and independent release approval.","websitePath":"/journeys/connected-fleet-trip/workshop","apiPath":"/api/journey-workshops?journey=connected-fleet-trip","providerCalls":0,"writesExposed":false}