# Where a station keeps its data

| The data | Where it goes | Who reads it |
|---|---|---|
| What the station found out about one workpiece (`extraction.json`, `check.json`) | A file in the workpiece, under `wp_doing` | Later stations, by file name |
| A file about the whole run, such as a spreadsheet to attach with `attachFile` | `workRecordFile(work_record.id, 'invoices.xlsx')` | This run, and you when debugging it |
| Scratch: page images, unpacked archives, downloads you'll throw away | A hidden folder beside the bins, such as `temp/stations/IN1/.render/inv-1001/`, deleted in `finally` | Nobody after the run |
| Counts and ids | The return value of `execute` | The Orchestrator, as the work record's `output` |

## Only the workpiece travels

A station hands work to the next one only through the workpiece folder. Don't add a side channel, such as a shared `data/` folder that one station writes and another reads on its next run. The bins wouldn't show it: a workpiece could reach the next station while the data it needs is missing or from an older run. If the next station needs it, write it into the workpiece. See [Workpieces](/docs/method/workpieces) and [Stations pull work](/docs/method/pull-dont-push).

## Files for the run

Within one run, `execute` does all the work, so pass data from one part of it to the next in variables. When the run needs a file on disk, such as a spreadsheet you build and then attach, put it in the work record's folder:

```js
const file = workRecordFile(work_record.id, 'invoices.xlsx');
await writeWorkbook(file, rows);
await attachFile(work_record.id, 'Invoices posted', file);
```

`workRecordFile(work_record_id, name)` returns a path in `temp/work_records/<work_record_id>/` and creates the folder. A local run writes its attachments there too.

- **The folder is on the disk of the machine that ran the station.** Nothing else reads it, and the next run has a different id.
- **The lib never deletes the folder.** Remove old work record folders with a job in your factory, as you do completed workpieces.

## The output holds counts, not data

What `execute` returns is sent to the Orchestrator and stored on the work record as `output`. Return counts and ids (`done_count`, `failed_count`), not lists of rows. Put what a person reads about the run in the run's report: see [Report a run](/docs/guides/report-a-run).

The exact signatures are in the [lib-factory README](https://github.com/assemblyline-sh/lib-factory#exports).
