Trucking Jobs/Loads & Legs β Current Implementation
1. Overviewβ
- Feature name: Trucking Jobs/Loads & Legs
- Primary users: Dispatchers, back-office ops, drivers (via legs), mobile users
- Industries: Trucking
- What this feature solves today:
- Represents a load as a
Jobwith trucking-specific fields and one or moreLegs. - Supports both manual entry and file-based import (roughly 50/50 in practice) for multi-stop loads with mileage and rate calculations.
- Exposes legs to scheduling/dispatch and to the mobile app as driver work items.
- Represents a load as a
2. Repos & Entry Pointsβ
API (@attunelogic-api)β
- Models
src/models/Job.jsβ Job/load containersrc/models/Leg.jsβ Individual trucking legs
- Types
src/types/index.tsβTruckingJob,TruckingJobStatussrc/types/models.tsβTruckingJobSchemaFields,TruckingLegSchemaFields
- Controllers / Services
src/controllers/jobs/create.jsβ Job creation (modern + legacy with legs)src/controllers/jobs/all.js,getById.jsβ Listing and retrievalsrc/controllers/legs/create.js(referenced from legacy create)src/controllers/jobs/items.jsβ Job items / service items (more service-repair focused, but shares job container)
- Routes
src/routes/api/v1/jobs.jssrc/routes/api/v1/legs.js(if enabled via features/config)
Web (@attunelogic-service)β
- Job creation & editing
src/pages/Jobs/CreateModal/index.jsxβ Orchestrates job creation.src/pages/Jobs/CreateModal/TruckingJobForm.tsxβ Trucking-specific job + legs form.src/utils/data-generators/index.tsβgenerateLeghelper (maps form state intoILegobjects).
- Job display
src/pages/Jobs/Show/index.jsxβ Job detail view (switches by appType).src/pages/Jobs/Show/Info/Trucking/LegsInfo.jsxβ Displays trucking legs within a job.
- File-based leg creation
src/components/FileProcessor/*β File upload and extraction.src/components/FileProcessor/configs.jsβcreateLegsFromDataand trucking load extraction presets.
- Types
src/types/index.tsβIJob,ILeg, trucking-related job/leg types.
Mobile (@attunelogic-mobile)β
- Data types
types/index.tsβILeg,IJobItem = ILeg | IMaintenance.
- RTK Query slices
store/api/jobs/api.tsβ Job queries/mutations.store/api/legs/api.tsβ Leg queries for driver views.
- UI components
components/LegCard/*β Leg summary cards.components/JobCard/*β Job/load cards (appType-aware).features/Job/DriverLoads.tsxβ Calendar + leg list per driver.features/Load/LoadShow.tsxandfeatures/Load/LoadDetails.tsxβ Load/leg detail screen(s).
3. Current Implementation (By Platform)β
3.1 Backend APIβ
Data modelβ
-
Job (
Jobmodel, trucking fields):jobId,client,parentCompany,author,assignedTo[]- Trucking-specific fields:
drivers: ObjectId[]β associated driver(s)loadNumber: stringβ load identifier (also used asjobId/orderNumberin create flow)legs: ObjectId[]β references toLegdocuments- Rates:
base,baseRate,fuelRate,flatRate,useFlatRate,useGlobalRates
- Financial and approval-related fields (shared with service/repair) from mixins.
-
Leg (
Legmodel, trucking leg):- Tenant & parent relationships:
parentCompany,jobId,client,author
- Trucking metadata:
status(default"Pending"),activeorderNumber,loadNumber,loadTypedriver(ObjectId β User)appointmentDate,appointment(date, time, number)
- Route & metrics:
route(ObjectId βRoutewith mileage and location links)weight,waitTime,sortKey
- Payout fields:
payoutType,payoutRate,mileageRate,hourlyRate, etc.
- Tenant & parent relationships:
Job creationβ
-
Modern
createJob(src/controllers/jobs/create.js):- Uses
useAuth()anduseCustomerConfig()to getemployeeId,role,appType, andgetRates. - Generates an
orderNumberlikeCLIENTSLUG-000123and uses it for:orderNumber,loadNumber, andjobIdif not supplied.
- Populates trucking rate fields based on:
- Global vs client-specific rates.
appType(truckingvsserviceRepair) anduseGlobalRates.
- Creates the
Jobfirst; legs are attached via other flows (file extraction or legacy multi-create).
- Uses
-
Legacy
legacyCreate(still present for backward compatibility):- Accepts a
data.legsmap, builds multiple leg payloads, and callscreateLegfor each. - Aggregates created leg IDs into
job.legsand setsdriversarray. - Applies flat-rate or mileage/fuel/base charges to the job.
- This is primarily used by older flows and tests; modern UI aims to use
createJob+ leg creation workflows.
- Accepts a
Security & tenancyβ
- All job and leg operations are scoped by:
parentCompany(multi-tenant isolation).- Auth middleware (
verifyToken,verifyParent,verifyRole) on routes.
itemsModeland other mixed fields allow the sameJobmodel to support both trucking and service/repair, controlled by customer config.
3.2 Web App (Service)β
Job creation flowsβ
-
Manual job + leg creation (used frequently in production):
CreateModalpresents a trucking job creation flow whenappType === "trucking".TruckingJobForm.tsx:- Collects job-level data (client, base/fuel/flat rates, load number, transaction date, etc.).
- Manages an internal
legsFormStatearray representing leg drafts. - Converts
legsFormStateβILeg[]usingconvertLegsFormStateToILegand sends to API.
- Each leg includes:
- Identification:
dropNumber,orderNumber,loadNumber,loadType,weight. - Associations:
driverId,driver,origin,destination. - Route data:
routewith mileage. - Financials:
totalMiles,baseCharge,fuelSurcharge,dropCharge,otherCharges,totalCharges. - Appointment data:
appointmentDateand time-related fields.
- Identification:
-
File-based leg creation:
FileProcessor+ configs:- Reads CSV/Excel/PDF using enhanced presets (
TRUCKING_LOAD). - Produces
legsarray with load, customer, location, and charge info. - Integrates with
CreateModalto pre-populate trucking legs and job-level form fields.
- Reads CSV/Excel/PDF using enhanced presets (
- This is the primary path for importing multi-drop loads from customer/broker exports.
Job & leg displayβ
- Job detail pages:
Jobs/Show/index.jsxbranches into trucking-specific subviews.Jobs/Show/Info/Trucking/LegsInfo.jsxdisplays legs with route, drop number, and status.- Legs are often the βitemsβ of a trucking job (vs service items for serviceRepair).
Status lifecycle (trucking)β
- Job-level stages for trucking are defined in
src/pages/Jobs/job-stages.tsx:NewβPendingβEn RouteβDeliveredβInvoiced.
- These stages:
- Drive button labels and actions on the job page (e.g., βStart Jobβ, βMark Deliveredβ).
- Are the statuses dispatchers and the current trucking customer actually see and use today.
3.3 Mobile Appβ
Data usageβ
-
Leg-centric driver workload:
- Drivers primarily interact with legs, not entire jobs.
DriverLoads.tsx:- Fetches legs filtered by
driverIdand date range viauseGetLegsQuery. - Presents a calendar view plus a list of legs for the selected date.
- Fetches legs filtered by
LegCard:- Shows key info: load number, origin/destination, appointment date/time, status.
-
Load details:
LoadShow.tsxandLoadDetails.tsx:- Show detailed data for a given leg/load ID.
- Tabs for details, documents, and tasks (for trucking).
Status handlingβ
- Mobile reflects leg-level status transitions defined in the API and used by scheduler/dispatch.
- Driver actions (where implemented) update leg status and feed back into the Job/Load view on web.
4. Status & Completenessβ
Implemented todayβ
- Backend:
- Robust
Jobmodel that supports trucking loads with multiple legs. Legmodel capturing route, driver, appointment, and payout details.- Modern
createJobcontroller with multi-industry rate handling and legacy leg-creation path.
- Robust
- Web:
- Manual trucking job creation with multiple legs in
TruckingJobForm. - File-based leg creation via
FileProcessorwith trucking-specific configs. - Job detail views with trucking legs display and summary.
- Manual trucking job creation with multiple legs in
- Mobile:
- Driver-focused leg listing (per day) using
useGetLegsQuery. - Load/leg detail screens with basic info, documents, and tasks.
- Driver-focused leg listing (per day) using
Partial / early implementationsβ
- The modern
createJobflow treats legs as a separate concern; some older flows still uselegacyCreatedirectly with legs. - File import + manual editing workflows are well-documented on the Service side, but not yet fully reflected in
@attunelogic-docs. - Mobile currently exposes legs and loads but lacks a fully driver-centric trucking dashboard (still more service-repair biased).
Missing / not implementedβ
- A first-class trucking load quote entity separate from jobs.
- A unified βLoad lifecycleβ doc and API that clearly delineates:
- Quote β Job/Load β Legs β Dispatch β Billing.
- Advanced routing (traffic-aware ETAs, VRP) and full HOS integration at the leg level.
5. Dependencies & Configurationβ
- Customer config (
useCustomerConfig):- Determines
appType(truckingvsserviceRepair) and rate behavior. - Controls
features.Job.items.model(whether legs or maintenance/service items are attached).
- Determines
- Industry / appType:
- When
appType === "trucking":- Jobs behave as loads with legs as items.
- Trucking forms and leg components are rendered on the web.
- Mobile uses trucking-specific flows (legs instead of service items).
- When
- Roles / permissions:
- Dispatchers and admins create and edit jobs/loads; drivers mostly interact with legs on mobile.
- API routes are protected with role- and tenant-based middleware.
6. UX Notes & Known Issuesβ
- What users experience today:
- Dispatchers can manually create and edit multi-leg trucking loads or import them from files.
- Drivers see their assigned legs by date and can view load details/documents.
- Known rough edges:
- The distinction between βJobβ and βLoadβ is mostly naming; both map to the same underlying Job model.
- Legacy and modern job creation flows coexist; behavior can differ slightly depending on entry point.
- There is no single UI action labeled βCreate Load from Quoteβ for trucking; quotes live more in the job-items/proposal layer.
7. Roadmap Alignmentβ
- Relevant roadmap sections:
- API
docs/MASTER_ROADMAP.mdβ Job management enhancements and trucking industry features. - Service
docs/MASTER_ROADMAP.mdβ Job & Leg Creation System and File Processing System (already documented). - Mobile
docs/MASTER_ROADMAP.mdβ Trucking implementation status and gaps (driver UX, HOS, fleet).
- API
- Whatβs planned vs what exists:
- Planned: richer fleet and driver management, HOS-aware scheduling, advanced routing, tighter quoteβload conversion.
- Exists: solid load/leg modeling, creation (manual + file-based), and basic driver-facing leg workflows.
8. Testing & Riskβ
- Tests:
- API:
- Job model and controller tests (including multi-industry behaviors).
- Security and multi-tenant tests that indirectly exercise job/leg queries.
- Service:
- Tests around job creation, shift/schedule behavior, and some leg-related utilities (see
tests/in Service repo).
- Tests around job creation, shift/schedule behavior, and some leg-related utilities (see
- Mobile:
- Limited automated tests; behavior largely validated via manual testing today.
- API:
- Risks / edge cases:
- Legacy vs modern job creation divergence.
- File import edge cases (incomplete/malformed data) impacting leg creation.
- Rate configuration errors (client vs global rates) affecting totals per leg.
- Monitoring:
- Issues surface via job/leg-related API errors, scheduler anomalies, and driver feedback in production.
9. Current Adoption & Next Stepsβ
- Current adoption:
- Used in production by at least one trucking customer (FC Trucking and Logistics Inc.), primarily from the Job page with a mix of manual entry and file import.
- Dispatchers and back office staff rely on this flow to represent loads and drops; drivers consume legs mostly via mobile/web job views.
- Next steps:
- Clarify βJob vs Loadβ in both UI and docs so trucking users see a consistent concept.
- Reduce reliance on legacy job creation by gradually migrating all flows to the modern
createJob+ legs workflow. - Tighten integration with future trucking quote/load-quote designs (Quote β Load β Legs).