# Lay out a factory repo and push its lines

A factory is a repo of lines and stations. Your code lives under `src/stations/`; the definitions of your lines and stations live as JSON files under `.orchestrator/`, and you push them to the Orchestrator with al-orc. Start from the [factory template](https://github.com/assemblyline-sh/factory-template), as in the [Quickstart](/docs/quickstart).

```text
factory-acme/
├── src/
│   ├── index.js                       the factory session: discovers stations, polls, watches bins
│   ├── stations/
│   │   ├── IN0__intake/station.js
│   │   └── IN1__check/station.js      one folder per station, its handler in station.js
│   └── shared/                        handlers two stations share (optional)
├── .orchestrator/
│   ├── lines/IN.json                  one file per line
│   └── stations/IN0__intake.json      one file per station
├── .env                               the session's settings and secrets (not committed)
├── .env.example                       every variable the factory reads, without values
└── temp/                              bins and run scratch, created at runtime (not committed)
```

## Line files

A line file is `.orchestrator/lines/<CODE>.json`. It names the line and says where its stations run:

```json
{
  "code": "IN",
  "name": "Invoice intake",
  "description": "Takes invoices from the inbox, checks them and posts them to the ledger",
  "location": "acme-office"
}
```

| Field | Required | Meaning |
|---|---|---|
| `code` | yes | The line's handle, unique in your organisation: 1 to 50 letters, digits, `-` or `_`. Station files name it in `line`. |
| `location` | yes | Where every station on this line runs. A factory session runs only the lines whose `location` equals its `FACTORY_LOCATION`. |
| `name` | no | Display name; defaults to `code` |
| `description` | no | What the line does, end to end |

A line runs at exactly one location, because its stations hand work to each other through folders on one disk. There is no location on a station. When you change a line's `location` and push it, runs that start from then on go to the new location; a run already started stays where it was. To run the same work in a second place, see [Run a factory session](/docs/guides/run-a-factory-session).

## Station files

A station file is `.orchestrator/stations/<SHORT_CODE>__<name>.json`, with `IN1__check.json` for station `IN1` named `check`. The folder is flat: the `line` field, not a subfolder, puts a station on its line.

```json
{
  "short_code": "IN1",
  "line": "IN",
  "name": "check",
  "description": "Checks each invoice against its purchase order",
  "conveyor": { "from": "IN0/output" },
  "config": { "approval_limit": 5000 },
  "dependencies": ["IN0"],
  "is_enabled": true,
  "watch_enabled": true
}
```

Every field is described in the [station object reference](https://orchestrator.assemblyline.sh/docs/objects/station). What matters for the file:

- **`line` must name a line that exists.** Push the line file first. A station with no `line` doesn't push.
- **No `location`.** It belongs to the line. al-orc drops a `location` it finds in a station file and says so.
- **Short codes** are unique in your organisation. By convention a short code is the line code plus a number, with the line head at `0` (`IN0`, `IN1`, `IN2`). A letter after the number marks stations that work side by side at the same stage (`IN0a`, `IN0b`).
- **`conveyor.from`** names the bins the station takes work from; a line head has none. See [Connect stations](/docs/guides/connect-stations).
- **`config`** is one JSON object, the config the station's handler gets, checked by its `configSchema`. The code is found by `short_code`: the handler in `src/stations/<SHORT_CODE>__<name>/station.js`. See [Write a station](/docs/guides/write-a-station).
- **No `steps`.** A station file with `steps`, the format before lib-factory 0.41, is refused by the Orchestrator and by the factory session. The [lib-factory README](https://github.com/assemblyline-sh/lib-factory#usage) says how to move an old factory over.
- See [Start stations](/docs/guides/trigger-stations) for `watch_enabled` and the schedule fields.

## Push and pull

Run al-orc from the factory's root folder. It uses the credentials of its own profile (`al-orc config profiles add`), not your `.env`.

```bash
al-orc lines push --all        # every line file
al-orc stations push --all     # every line file first, then every station file
al-orc stations push IN1       # one station, by short code or file name
```

- **A file without an `id` is created.** al-orc then rewrites it with the record the Orchestrator returns, including the new `id`, and renames it to `<SHORT_CODE>__<name>.json`. Commit the rewritten file, so the next push updates the station instead of creating it again.
- **A file with an `id` is updated.** If that `id` doesn't exist on the Orchestrator you push to, the push stops. `--force` creates it there with the same `id`, for moving a factory to a new organisation or Orchestrator.
- **`dependencies`** can name short codes; al-orc turns them into ids when it pushes. A pulled file shows ids.
- **`tags`** are names. A tag that doesn't exist yet is created. `[]` removes every tag; leaving the field out leaves the tags as they are.

To bring the Orchestrator's copy down, for example in a fresh clone:

```bash
al-orc stations pull --all     # every line file, then every station file
al-orc lines pull --all        # line files only
```

Your factory session reads the local files too: it uses them to decide which stations to watch. Push every change, so the two copies match.

## Next

- [Run a factory session](/docs/guides/run-a-factory-session): start the process that runs these stations.
- [Give stations their credentials](/docs/guides/environment-and-secrets): what goes in `.env`.
- [Write a station that processes workpieces](/docs/guides/process-workpieces): the code under `src/stations/`.
