First Deployment

Deploy all 9 UNS components and see KPIs flowing.

Overview

Each component builds on the previous one:

1. Infrastructure  →  2. Capture  →  3. Process  →  4. Report
   (network,           (sim,          (state,        (kpi)
    cache,              framework)     stoppage,
    postgres)                          productivity,
                                       input, log,
                                       cache)

Step 1: Infrastructure

# Create shared network
docker network create fnkit-network 2>/dev/null || true

# Start Valkey cache
fnkit cache start

# Start PostgreSQL
docker run -d --name fnkit-postgres \
  --network fnkit-network \
  -e POSTGRES_USER=fnkit \
  -e POSTGRES_PASSWORD=fnkit \
  -e POSTGRES_DB=fnkit \
  -p 5432:5432 \
  postgres:17

Step 2: UNS Capture Layer

# uns-framework (topic monitor) — start first
cd uns-framework
cp .env.example .env
# Edit .env — set MQTT_BROKER
docker compose up -d
cd ..

# uns-sim (machine simulator)
cd uns-sim
cp .env.example .env
# Edit .env — set MQTT_BROKER
docker compose up -d
cd ..

# Verify data is being cached
docker exec fnkit-cache valkey-cli SMEMBERS uns:topics
# → 12 topics (4 machines × 3 tags)

Step 3: Processing Functions

Set Valkey Configs

# uns-state config (watches /status topics)
docker exec fnkit-cache valkey-cli SET fnkit:config:uns-state \
  '{"table":"uns_state","topics":["v1.0/enterprise/site1/area1/cnc-01/status","v1.0/enterprise/site1/area1/cnc-02/status","v1.0/enterprise/site1/area2/cnc-03/status","v1.0/enterprise/site1/area2/cnc-04/status"]}'

# uns-productivity config (watches /program topics)
docker exec fnkit-cache valkey-cli SET fnkit:config:uns-productivity \
  '{"table":"uns_productivity","topics":["v1.0/enterprise/site1/area1/cnc-01/program","v1.0/enterprise/site1/area1/cnc-02/program","v1.0/enterprise/site1/area2/cnc-03/program","v1.0/enterprise/site1/area2/cnc-04/program"]}'

Start Processing Functions

# Start each function
for fn in uns-state uns-stoppage uns-productivity uns-input uns-log uns-cache; do
  cd $fn && cp .env.example .env && docker compose up -d && cd ..
done

Start Polling

# Poll uns-state every 5 seconds
while true; do curl -s http://localhost:8080/uns-state > /dev/null; sleep 5; done &

# Poll uns-productivity every 10 seconds
while true; do curl -s http://localhost:8080/uns-productivity > /dev/null; sleep 10; done &

# Poll uns-stoppage every 15 seconds
while true; do curl -s http://localhost:8080/uns-stoppage > /dev/null; sleep 15; done &
i In production, use the fnkit gateway orchestrator or a cron job instead of shell loops.

Step 4: KPI Reporter

cd uns-kpi
cp .env.example .env
docker compose up -d

# Wait a few minutes for data, then query KPIs
curl "http://localhost:8080/uns-kpi?hours=1" | jq

Step 5: Verify Everything

Check Data in PostgreSQL

# State durations
docker exec fnkit-postgres psql -U fnkit -c \
  "SELECT machine, state, duration_s FROM uns_state ORDER BY id DESC LIMIT 5"

# Stoppages
docker exec fnkit-postgres psql -U fnkit -c \
  "SELECT machine, reason_code, category FROM uns_stoppage ORDER BY id DESC LIMIT 5"

# Production runs
docker exec fnkit-postgres psql -U fnkit -c \
  "SELECT machine, program_name, parts_completed FROM uns_productivity ORDER BY id DESC LIMIT 5"

Test Manual Input

# Submit a scrap entry
curl -X POST -H "Content-Type: application/json" \
  -d '{"type":"scrap","machine":"cnc-01","operator":"John","data":{"quantity":2,"reason":"burr"}}' \
  http://localhost:8080/uns-input | jq

Remote Deployment

Once everything works locally, deploy to a server:

# Set up remote (one-time per function)
cd uns-state
fnkit deploy remote --host root@your-server.com
git add . && git commit -m "init" && git push deploy main

# Repeat for each function...