# DAT Load Board Authenticated Search Integration Architecture

## Purpose
This architecture track defines how a Dispatch Spot workspace can connect an approved DAT account context and let CORI search suitable next loads inside Dispatch Spot without forcing the dispatcher to leave the app.

## Core product goal
Dispatchers should be able to say or type requests such as:
- find the best next DAT loads for this truck
- search DAT for reefer loads heading back toward Atlanta
- rank DAT loads that keep this truck above target RPM

## Scope
- workspace DAT connection status
- DAT seat / subscription-aware access posture
- authenticated DAT load search
- truck-aware and carrier-aware search context
- CORI-assisted search and ranking
- result normalization into Dispatch Spot records and workflows
- retry / error / permission handling

## Recommended architecture layers

### 1. Workspace DAT connection layer
- workspace-level DAT integration record
- connection status
- seat / access posture
- token or service-account mapping depending on DAT-approved auth pattern
- last successful check
- last error state

### 2. DAT search adapter layer
- DAT-authenticated search request builder
- permission-aware request guard
- lane/equipment/date/radius/rate filters
- result pagination support
- normalized Dispatch Spot search result shape
- DAT-specific fields kept out of the operator surface unless needed

### 3. CORI search orchestration layer
- use truck, driver, lane, equipment, target RPM, and operational context already known in Dispatch Spot
- ask DAT for candidate next loads
- rank results using Dispatch Spot business logic
- explain best-fit reasoning in simple dispatcher language

### 4. Result normalization layer
Normalize DAT results into a Dispatch Spot-friendly shortlist:
- broker / customer
- origin / destination
- equipment
- miles
- rate
- RPM estimate
- timing fit
- deadhead exposure
- confidence / fit summary

### 5. Guard and fallback layer
- blocked when DAT auth is missing
- blocked when DAT seat/access posture is not valid
- retry when DAT is temporarily unavailable
- fall back to internal guidance when DAT cannot be searched

## Planned user experience

### Workspace admin
- connect DAT
- review connection status
- confirm access posture
- see sync/search errors

### Dispatcher
- ask CORI for next loads
- receive a short ranked DAT shortlist
- open the best candidate quickly
- preserve truck-aware context without retyping the search

## Key design rules
- DAT remains the external source for approved load-board search data
- Dispatch Spot adds operational context, ranking, and workflow continuity
- CORI should speak in dispatcher language, not DAT API language
- blocked/permission states should be short and clear
- search results should stay compact and action-first

## Future build sequence
1. workspace DAT connection architecture
2. authenticated DAT access posture and guard model
3. normalized DAT search adapter
4. CORI-assisted next-load ranking
5. result review and follow-up actions inside Dispatch Spot
