Quickstart
This gets one station running on your machine with npx factory, which comes with the factory template. You don't need an account for any of it. The example station flags invoices above an approval limit.
You'll need Node.js 18 or later and git.
1. Create a factory repo from the template
git clone https://github.com/assemblyline-sh/factory-template.git factory-acme
cd factory-acme
rm -rf .git && git init
Replace the template's placeholders with your organisation's short name (here acme) and the place this factory runs (here acme-office). On macOS:
grep -rlE '\{\{(ORG_NAME|LOCATION|FACTORY_NAME|FACTORY_DESCRIPTION)\}\}' . --exclude-dir=.git | xargs sed -i '' \
-e 's/{{ORG_NAME}}/acme/g' -e 's/{{LOCATION}}/acme-office/g' \
-e 's/{{FACTORY_NAME}}/factory-acme/g' -e 's/{{FACTORY_DESCRIPTION}}/Factory for acme/g'
On Linux, use sed -i instead of sed -i ''. Then install:
cp .env.example .env
npm install
npm install brings in lib-factory, which provides defineStation() and the npx factory command. Check it works:
npx factory stations list
2. Write a station
A station's code is a folder under src/stations/ whose station.js exports defineStation(). Create src/stations/IN1__check_invoices/station.js:
import { defineStation } from '@assemblyline/lib-factory';
import { z } from 'zod';
export default defineStation({
code: 'IN1',
configSchema: z.object({
approval_limit: z.number().default(5000),
invoices: z.array(z.object({ number: z.string(), amount: z.number() })).default([]),
}),
execute: async (config) => {
const above_limit = config.invoices
.filter((invoice) => invoice.amount > config.approval_limit)
.map((invoice) => invoice.number);
return { checked: config.invoices.length, above_limit };
},
});
3. Run it on your machine
A station gets its config from its station file, and a station sits on a line. Create the line's file, .orchestrator/lines/IN.json:
{
"code": "IN",
"name": "Invoices",
"location": "acme-office"
}
and the station's, .orchestrator/stations/IN1__check_invoices.json, with a test config:
{
"short_code": "IN1",
"line": "IN",
"name": "check_invoices",
"config": {
"invoices": [
{ "number": "INV-1001", "amount": 1250 },
{ "number": "INV-1002", "amount": 7400 }
]
}
}
Then run the station with that config:
npx factory stations run IN1
[Factory] Discovered 3 stations
Station: IN1
Config: station file: IN1__check_invoices.json
[IN1] Config: {"invoices":[{"number":"INV-1001","amount":1250},{"number":"INV-1002","amount":7400}]}
------------------------------------------------------------
Output:
------------------------------------------------------------
{
"checked": 2,
"above_limit": [
"INV-1002"
]
}
Output saved: temp/IN1.json
Station completed successfully
Edit station.js and run it again. That's the loop. To change one config key for a run, add --set: npx factory stations run IN1 --set approval_limit=1000 flags both invoices. The value is read as JSON, so 1000 is a number and true is a boolean. A local run is real: if a station calls an API or writes to a system, that happens.
4. Run a line on the Orchestrator
To run stations on a schedule and get a work record for every run, you need an account.
- Sign up and verify your email. Your account comes with an organisation.
- In the Orchestrator, open Settings → API keys and create a key. Copy the key and the secret; the secret is shown only once.
- Put them in
.envasORCHESTRATOR_API_KEYandORCHESTRATOR_API_SECRET.ORCHESTRATOR_URLandFACTORY_LOCATIONare already set. - Install the CLIs and give al-orc the same key:
npm install -g @assemblyline/al-orc @assemblyline/al-control
al-orc config profiles add acme --api-key <key> --api-secret <secret>
al-orc status
The template ships an example line, EX, that turns the text files in samples/ into workpieces and counts their words. Push its line and stations, start a factory session in a second terminal, then trigger the first station:
al-orc lines push --all && al-orc stations push --all
npm start # in a second terminal: the factory session
al-orc stations run EX0
al-control lines status EX -f .
Two workpieces finish and one fails: samples/empty.txt is empty on purpose, so it lands in temp/stations/EX1/failed/ with its error. al-orc work-records list shows the record of each run.
The push also registered your IN line and its IN1 station. Neither has a trigger yet, so IN1 runs only when you run it: al-orc stations run IN1. To make a station run on a schedule or when work arrives, see Lay out a factory repo and copy the EX files.
Next
- Concepts: how stations hand work to each other through bins.
- Write a station and Run and test a station: go further than the first station.
- Use with AI agents: let a coding agent take over the edit-and-run loop.