Job Management
This document covers the job management system architecture and implementation details for the AttuneLogic API.
ποΈ Job Architectureβ
Core Job Modelβ
The job management system is built around a flexible, multi-industry job model that supports:
- Trucking Industry: Load management, route optimization, delivery tracking
- Service/Repair Industry: Work orders, maintenance schedules, service requests
- Universal Features: Scheduling, status tracking, resource allocation
Job Lifecycleβ
Created β Scheduled β Assigned β In Progress β Completed β Invoiced β Archived
π Job States and Transitionsβ
Primary Statesβ
pending: Job created but not yet scheduledscheduled: Job scheduled with date/time assignmentassigned: Job assigned to specific resources (drivers, technicians)in_progress: Job actively being worked oncompleted: Job finished successfullycancelled: Job cancelled before completionfailed: Job could not be completed
Industry-Specific Sub-Statesβ
Trucking Industryβ
dispatched: Load assigned to driveren_route_pickup: Driver heading to pickup locationat_pickup: Driver at pickup locationloaded: Cargo loaded, en route to deliveryat_delivery: Driver at delivery locationdelivered: Cargo delivered successfully
Note: Trucking has a canonical, snake_case Job + Leg status system with backward-compatible normalization. See:
docs/developer/development/trucking-status-canonicalization.md
Service/Repair Industryβ
diagnosed: Issue identified and assessedparts_ordered: Required parts orderedparts_received: Parts available for repairrepair_in_progress: Active repair worktesting: Post-repair testing and validationcustomer_approval: Awaiting customer approval
ποΈ Database Schemaβ
Jobs Collectionβ
{
_id: ObjectId,
title: String,
description: String,
status: String,
priority: String, // low, medium, high, urgent
appType: String, // trucking, serviceRepair, hvac, plumbing, electrical
// Scheduling
scheduledDate: Date,
estimatedDuration: Number, // minutes
actualStartTime: Date,
actualEndTime: Date,
// Assignment
assignedTo: [ObjectId], // references to Users
assignedTeam: ObjectId, // reference to Team
// Location
serviceAddress: Object,
pickupAddress: Object, // trucking specific
deliveryAddress: Object, // trucking specific
// Industry-Specific Data
industryData: {
// Trucking
loadDetails: Object,
routeOptimization: Object,
driverRequirements: Object,
// Service/Repair
equipmentDetails: Object,
serviceType: String,
partsRequired: Array,
customerPreferences: Object
},
// Relationships
parentCompany: ObjectId,
client: ObjectId,
equipment: [ObjectId],
items: [ObjectId], // job items/sub-tasks
// Metadata
createdAt: Date,
updatedAt: Date,
createdBy: ObjectId,
updatedBy: ObjectId,
// Tracking
timeline: [Object], // status change history
notes: [Object], // comments and updates
attachments: [Object] // photos, documents
}
π Job Item Systemβ
Job Items (Sub-Tasks)β
Jobs can contain multiple items representing:
- Trucking: Multiple stops, cargo types, delivery requirements
- Service/Repair: Individual repair tasks, parts installation, testing procedures
Item Schemaβ
{
_id: ObjectId,
jobId: ObjectId,
title: String,
description: String,
status: String,
sequence: Number, // order of execution
// Time tracking
estimatedTime: Number,
actualTime: Number,
startTime: Date,
endTime: Date,
// Resources
assignedTo: ObjectId,
requiredSkills: [String],
toolsRequired: [String],
partsRequired: [Object],
// Completion
completionNotes: String,
qualityCheck: Boolean,
customerSignature: String,
photos: [String],
// Industry-specific
industryData: Object
}
π API Endpointsβ
Core Job Operationsβ
// Create job
POST /api/v1/jobs
Body: CreateJobRequest
// Get jobs (with filtering)
GET /api/v1/jobs?status=pending&appType=trucking&assignedTo=userId
// Get single job
GET /api/v1/jobs/:jobId
// Update job
PATCH /api/v1/jobs/:jobId
Body: UpdateJobRequest
// Delete job
DELETE /api/v1/jobs/:jobId
// Job status transitions
POST /api/v1/jobs/:jobId/status
Body: { status: 'in_progress', notes: 'Started work' }
Job Item Operationsβ
// Add item to job
POST /api/v1/jobs/:jobId/items
Body: CreateJobItemRequest
// Update job item
PATCH /api/v1/jobs/:jobId/items/:itemId
// Complete job item
POST /api/v1/jobs/:jobId/items/:itemId/complete
Body: CompletionData
// Reorder job items
POST /api/v1/jobs/:jobId/items/reorder
Body: { itemIds: [id1, id2, id3] }
π Industry-Specific Featuresβ
Trucking Industryβ
- Route Optimization: Integration with mapping services
- Load Optimization: Weight, space, and compatibility calculations
- Driver Assignment: Based on qualifications, location, HOS compliance
- Real-time Tracking: GPS integration for live location updates
- BOL Management: Digital bill of lading generation and tracking
Service/Repair Industryβ
- Skill-Based Assignment: Match technicians to required skills
- Parts Management: Inventory tracking and automatic ordering
- Customer Communication: Automated updates and approval workflows
- Equipment History: Service history and maintenance schedules
- Quality Assurance: Photo documentation and completion checklists
π± Mobile Integrationβ
Mobile Job Featuresβ
- Offline Capability: Work without internet connection
- Photo Capture: Document progress and completion
- Digital Signatures: Customer approval and sign-off
- Real-time Updates: Sync status changes immediately
- Navigation: Integrated GPS for route guidance
Mobile API Endpointsβ
// Sync jobs for mobile user
GET /api/v1/mobile/jobs/sync?lastSync=timestamp
// Update job status from mobile
POST /api/v1/mobile/jobs/:jobId/status
Body: { status, location, timestamp, photos }
// Upload job completion data
POST /api/v1/mobile/jobs/:jobId/complete
Body: CompletionData with photos and signatures
π Search and Filteringβ
Advanced Job Searchβ
// Search with multiple criteria
GET /api/v1/jobs/search?q=urgent+repair&dateRange=2024-01-01,2024-01-31&status=pending,assigned&assignedTo=userId
// Geospatial search
GET /api/v1/jobs/nearby?lat=40.7128&lng=-74.0060&radius=50&unit=miles
// Industry-specific filters
GET /api/v1/jobs?appType=trucking&loadType=flatbed&route=interstate
π Performance Optimizationβ
Database Indexesβ
// Compound indexes for common queries
db.jobs.createIndex({ parentCompany: 1, status: 1, scheduledDate: 1 });
db.jobs.createIndex({ parentCompany: 1, assignedTo: 1, status: 1 });
db.jobs.createIndex({ parentCompany: 1, appType: 1, createdAt: -1 });
// Geospatial index for location-based queries
db.jobs.createIndex({ "serviceAddress.location": "2dsphere" });
// Text search index
db.jobs.createIndex({
title: "text",
description: "text",
"client.name": "text",
});
Caching Strategyβ
- Job Lists: Cache frequently accessed job lists by status and assignee
- Job Details: Cache individual job data for mobile offline access
- Aggregated Data: Cache dashboard statistics and reports
- Search Results: Cache common search queries and filters
π Security Considerationsβ
Access Controlβ
- Multi-tenant Isolation: Jobs isolated by parentCompany
- Role-based Access: Different permissions for managers, dispatchers, field workers
- Field-level Security: Sensitive data (pricing, customer info) restricted by role
- Audit Trail: All job modifications logged with user and timestamp
Data Validationβ
- Status Transitions: Validate allowed state changes
- Business Rules: Enforce industry-specific constraints
- Input Sanitization: Prevent injection attacks
- File Upload Security: Validate and sanitize attachment uploads
π Analytics and Reportingβ
Key Metricsβ
- Job Completion Rate: Percentage of jobs completed successfully
- Average Completion Time: Time from creation to completion
- Resource Utilization: How efficiently resources are being used
- Customer Satisfaction: Based on feedback and ratings
Industry-Specific Analyticsβ
- Trucking: Route efficiency, fuel costs, delivery times
- Service/Repair: First-time fix rate, parts usage, technician productivity