Data Flow
How a vehicle travels from a JSON file on disk to a card in the browser, and how a bid
travels back. One rule shapes everything: derive, don't store. Windows, statuses,
galleries, and the 100k inventory are all computed from stable ids, never persisted.

A preview. Open the data flow diagram in a new page
to zoom in and follow it; every diagram on this site opens that way (ADR: Diagram pages).
The source is docs/images/dataflow.svg.
Every box in the diagram is a file; each step below names its path.
Every HTTP endpoint lives in its slice under api/TheYard.Api/Features/, one folder per feature with a Module.cs that maps it.
api/TheYard.Api/Program.cs is the table of contents: it calls the registrations in
api/TheYard.Api/Shared/ (sources, then services) and each slice's module, then maps each module. A
handler binds the request and hands straight off to the Application layer; the auction's
handlers are queries and commands (ADR-115), and every query reads a vehicle through StandingReader
(api/TheYard.Application/Shared/Auction/StandingReader.cs), which lays the catalogue, everybody's bids and the
simulated room in the one order the rules need. ADR:
Program.cs, explained walks the entry point top to bottom.
In plain words
This page follows one vehicle from a data file on disk to a card on screen, and one bid on its way back. The rule behind it is to work facts out from stable ids each time (derive, don't store) instead of saving them, and to keep every auction rule on the server.
What that is worth: a developer can trace any request to the file that handles it, because every step names its path. The organization gets one home for the auction rules, so the screen shows what the server decided.
The read path
- Seed. The catalogue is read once at startup from the store, Azure SQL Database,
Azure Cosmos DB or SQLite;
data/vehicles.json (the challenge's 200 records, untouched)
seeds a fresh store on first boot through JsonFileVehicleSource
(api/TheYard.Infrastructure/Shared/Auction/JsonFileSources.cs), deserializing into the Vehicle record, which lives with the other pure data shapes
in api/TheYard.Data/.
- Scale.
SyntheticVehicleSource (api/TheYard.Infrastructure/Shared/Auction/SyntheticVehicleSource.cs)
expands it to 100,000 deterministic variants: each new id is hashed (FNV-1a,
api/TheYard.Domain/Shared/Auction/Fnv1a.cs) to vary VIN, year, odometer, prices, and bid state
while inheriting the seed's make/model/trim mix.
- Enrich and cache.
Stock (api/TheYard.Application/Shared/Auction/Stock.cs)
applies each vehicle's photo gallery (hash-picked by api/TheYard.Domain/Shared/Auction/PhotoGallery.cs
from api/TheYard.Api/photo-manifest.json pools, preferring the vehicle's own make)
and fills the store's catalogue with them, which a page is then a query against: the
process holds none of the hundred thousand in memory (ADR: The store does the work).
- Query. A request like
GET /api/vehicles?make=Ford&status=live&sort=price-asc
binds through api/TheYard.Api/Features/Vehicles/VehicleQueryParams.cs, which validates and produces
a filter, a sort, and a clock (api/TheYard.Api/Shared/Instance/Clocks.cs): now, and the UTC
midnight that began the day, the same for every caller, so schedule math
(api/TheYard.Domain/Shared/Auction/AuctionSchedule.cs, AuctionClock.cs) puts every visitor in
the same auction. Everybody's bids, then the simulated room's, overlay before
filtering (StandingReader.Overlay in api/TheYard.Application/Shared/Auction/StandingReader.cs, each raise made by
StandingRules.RaisedTo in api/TheYard.Domain/Shared/Auction/StandingRules.cs), so price bounds see
the same figures the UI shows. Then Where → OrderBy → Skip/Take, in the store:
Stock.SearchAsync resolves the filter to the store's own spelling and plans
the page, and the store's adapter (EfVehicleCatalogue.cs over the Catalogue table,
CosmosVehicleCatalogue.cs over the catalogue container) answers it off an index, so only
the page comes back (ADR: The store does the work).
- Wire.
api/TheYard.Api/Shared/Wire/VehicleWire.cs stamps the server-derived auction facts
onto each vehicle (auction_starts_at, auction_ends_at, auction_status,
min_next_bid, and sold, from everybody's standing), and the endpoint
(api/TheYard.Api/Features/Vehicles/VehicleEndpoints.cs) responds with a snake_case envelope
{ total, vehicles }.
- Fetch.
src/lib/data.ts is the browser's single seam: it debounces filter
changes (500 ms), caches responses per query string (5-minute TTL; hits skip the
debounce), and aborts superseded requests. The query string itself is built by
src/lib/inventory.ts, the same serializer that feeds the address bar.
- Render.
src/app/hooks/useAddressBar.ts holds the view and mirrors filters plus ?vehicle={id}
into the URL; components (src/components/) format currency
(src/lib/format.ts), tick countdowns from the server's window, and recompute
live/ended locally as time passes (src/lib/auction.ts). No business math runs in
the browser.
Step 4's overlay, read from this build. It is chosen once per listing, so a cold catalogue
with no bid and no room pays for neither:
private ListingOverlay? Overlay()
{
if (bids.IsEmpty && room.IsEmpty)
{
return null;
}
var moved = new HashSet<string>(StringComparer.Ordinal);
if (!bids.IsEmpty)
{
moved.UnionWith(bids.Standing().Keys);
}
if (!room.IsEmpty)
{
moved.UnionWith(room.Snapshot().Keys);
}
return new ListingOverlay(moved, AsItStands);
}
private Vehicle AsItStands(Vehicle vehicle) => room.Apply(bids.Apply(vehicle));
Live from api/TheYard.Application/Shared/Auction/StandingReader.cs, region overlays, read from this build at 99df7a8.
Step 6's seam, the one function every list view goes through:
export interface FetchVehiclesOptions {
sort?: SortKey;
offset?: number;
signal?: AbortSignal;
forceRefresh?: boolean;
background?: boolean;
}
export async function fetchVehicles(
filters?: InventoryFilters,
{ sort, offset = 0, signal, forceRefresh = false, background }: FetchVehiclesOptions = {}
): Promise<VehiclePage> {
const query = queryString(filters, sort, offset);
const key = cacheKey(query);
if (!forceRefresh) {
const hit = cachedPage(key);
if (hit) return hit;
}
const url = query ? `/api/vehicles?${query}` : '/api/vehicles';
const response = await counted(() => fetch(url, { signal }), { background });
if (!response.ok) {
throw new Error(
await problemDetail(response, `The inventory API responded with ${response.status}`)
);
}
const page = (await response.json()) as VehiclePage;
queryCache.delete(key);
queryCache.set(key, { at: Date.now(), page });
if (queryCache.size > CACHE_MAX_ENTRIES) {
const oldest = queryCache.keys().next().value;
if (oldest !== undefined) queryCache.delete(oldest);
}
return page;
}
Live from src/lib/data.ts, region fetch-vehicles, read from this build at 99df7a8.
The write path (bids)
src/components/vehicle/BidPanel/BidPanel.tsx posts { amount } to
POST /api/vehicles/{id}/bids via src/lib/data.ts; the clock is the server's.
api/TheYard.Api/Features/Bids/BidEndpoints.cs hands it to PlaceBidHandler, which
measures it against the room's standing price as well as everybody's bids.
api/TheYard.Domain/Shared/Auction/BidRules.cs is the sole authority: sold first (a vehicle anybody
has bought takes no bid and no second purchase, a fact BidBook supplies from
everybody's standing), then the live-window check, the tiered minimum increment, and
the buy-now override (a bid at or above buy_now_price wins outright at that price).
- Accepted or won bids are written to the store first, Azure SQL Database or Azure
Cosmos DB through
IBidStore, and then to the in-memory standing in
api/TheYard.Application/Shared/Auction/BidBook.cs, under the signed-in account's id (ADR:
Accounts and per-user bids); rejections return 400 with a human-readable reason the
panel shows.
- The response carries the updated vehicle (fresh
min_next_bid included); src/lib/data.ts
clears the query cache and the client (src/hooks/useBids.ts) refetches, so lists, filters, and
totals all reflect the new bid, because the overlay in read-step 4 feeds the same
pipeline every read uses.
Step 2's first check, read from this build. Sold is a fact the rules cannot know from the
vehicle alone, so the caller that holds everybody's standing supplies it, and it is asked
before the clock and before the buy-now shortcut:
public const string SoldReason = "This vehicle has been sold.";
public static BidOutcome ResolveBid(Vehicle vehicle, int amount, AuctionClock clock, bool sold)
{
if (sold)
{
return BidOutcome.Rejected(SoldReason);
}
if (amount > MaxBid)
{
return BidOutcome.Rejected($"A bid can be at most ${MaxBid.ToString("N0", CultureInfo.InvariantCulture)}.");
}
var status = AuctionSchedule.StatusFor(vehicle.Id, clock);
if (status == AuctionStatus.Live && vehicle.BuyNowPrice is { } buyNow && amount >= buyNow)
{
return BidOutcome.Won(buyNow);
}
if (status == AuctionStatus.Upcoming)
{
return BidOutcome.Rejected("This auction has not started yet.");
}
if (status == AuctionStatus.Ended)
{
return BidOutcome.Rejected("This auction has ended.");
}
int min = MinNextBid(vehicle);
return amount < min
? BidOutcome.Rejected($"Bid must be at least ${min.ToString("N0", CultureInfo.InvariantCulture)}.")
: BidOutcome.Accepted(amount);
}
public static BidOutcome ResolveBuyNow(Vehicle vehicle, AuctionClock clock, bool sold)
{
if (sold)
{
return BidOutcome.Rejected(SoldReason);
}
if (vehicle.BuyNowPrice is not { } buyNow)
{
return BidOutcome.Rejected("This vehicle has no Buy Now price.");
}
return AuctionSchedule.StatusFor(vehicle.Id, clock) == AuctionStatus.Live
? BidOutcome.Won(buyNow)
: BidOutcome.Rejected("Buy Now is only available while the auction is live.");
}
Live from api/TheYard.Domain/Shared/Auction/BidRules.cs, region sold, read from this build at 99df7a8.