MES / APS · In production · Client NDA
Manufaktura
A manufacturing execution and planning system for a multi-hall textile plant: from the order and its technology, through resource planning and the factory floor, to settlement, the warehouse and ERP documents. I joined it as the C# backend engineer and took it over as its technical owner.
- 460+endpoints in 38 domains
- 4,000+automated tests
- 60+machines in six halls
- Role
- Technical owner · lead MES/APS engineer
- Period
- 2025 – present: backend from February, owner from September, now in handover
- Stack
- .NET 10, ASP.NET Core, EF Core, PostgreSQL, SignalR, React 19, TypeScript, Three.js
- Delivery
- GitHub Actions, self-hosted Windows runner, single Windows service
The system at scale
One codebase, owned end to end. Every point below is a real declaration in it (a C# type; a function, component or constant of the interface; a migration) and every thread one of them using another, laid out by layer: the backend to the left, the operator and planner interfaces to the right. Names are withheld; the shape is not.
7,781 declarations and 26,304 references, drawn when this page loads.
- 553klines of hand-written code
- 3,446source files
- 2,016C# types
- 460+HTTP endpoints in 38 domains
- 393mapped entity sets
- 301schema migrations
- 2,600+backend test cases
- 1,666frontend tests in 440 files
From an order to an ERP document
Seven stages, each owning its own decision; a closed stage never quietly closes the next one.
- Orderitem, quantity and unit, the customer’s deadline, priority
- Technologyversioned operations, inputs, norms, the resources they fit
- Planningmaterial readiness, route, machines, calendar, deadlines
- Releasetasks, reservations and assignments as one transaction
- Floorstart, stop, progress and scrap, at the machine
- Settlementquantities approved, consumption posted, capacity freed
- Warehouse & ERPcartons, document proposals, the ERP’s own confirmation
One request, end to end
A tap on the kiosk goes through a fourteen-step HTTP pipeline (error handling, compression, routing, security headers, CORS, rate limits, sign-in, the kiosk’s own session guard, authorisation, then the controller) before any rule runs; then a service of the planning or execution domain, the calculation it needs, a read or write port, and the database, inside one transaction.
- Kiosk / panela tap on the touch kiosk at a machine, or a click in the planner
- 14-step pipelineerrors, compression, routing, headers, CORS, limits, sign-in, the kiosk’s session, authorisation
- Domain servicethe rule of planning or execution the request is about
- Calculationtime and material, by the kind of machine
- Portexactly the read or write that rule needs
- EF Coreentities and mappings, inside one transaction
- PostgreSQLone operational model of the whole plant
Running underneath
- An outbox turns every settlement into stock movements, retried until the ERP confirms each document number.
- A gateway reads orders, records and stock from the ERP’s SQL Server; mapping an ERP index to a product, a semi-finished good or a raw material is an explicit decision, never a guess.
- Machines report cumulative counters over the network: partial batches, counter overflow and resent reports are all handled, and every connector is mapped to its sensor and machine explicitly.
- Background workers recompute task quantities, and archive and retain operational history; screens update live over SignalR.
The problem
Production in the plant is not a straight line. Orders split into semi-finished goods on drums, work goes out to home-based contractors and comes back, machines break down and get re-tooled, and the ERP must stay the formal source of stock and documents. Planning lived in spreadsheets and people’s heads; the floor had no shared, live picture of what was actually happening.
What I built
- Order intake and import from the ERP, with deadlines, priorities and customer arrangements.
- Technology cards, material norms and a readiness check before anything can be planned.
- Constraint-aware planning (APS): routing, picking from stock, machine choice, calendars, a Gantt view and alerts, released as a reserved plan.
- A touch kiosk for the floor with PIN sign-in: execution, waste, re-tooling, drums and exceptions reported where the work happens.
- Live machine state from PLC counters, a plant dashboard and 2D / 3D maps of the halls.
- Outwork for home-based contractors, maintenance and breakdowns, cartons, pickups and warehouse documents back to the ERP.
Engineering decisions
- Clear data ownership: the MES owns the operational state of the floor, the ERP stays the formal source of commercial stock and documents; discrepancies stay visible instead of being silently reconciled.
- Replay-safe operator reports: a retried report is recognised and never applied twice.
- An outbox towards the ERP with explicit document envelopes; a document only counts as posted when the ERP number matches.
- Releases that cannot race the floor: a plan is released only if its fingerprint still matches (compare-and-swap), reservations run Serializable with contested rows locked FOR UPDATE, and stock moves through one ordered inventory outbox.
- A 4,000+ test gate built from zero: 14 end-to-end production flows, 112 Playwright scenarios, a 2,000-seed fuzzer checked against an independent oracle, 26 settlement invariants, and a replay of 54 fixed bugs, each proven to fail before its fix.
- Security that fails closed: password sign-in by BCrypt only, sessions revocable at once across 17 roles and 10 kiosk personas, and an audit log that, if it cannot be written, makes 251 critical routes refuse (503) rather than act unrecorded.
- Operations rehearsed before they were needed: gated releases, expand-only migrations, and full restore drills in a single transaction (7.9M+ rows).
- A living product specification (~7,900 lines) with requirements traced to tests and acceptance scenarios.
Outcome
An untested prototype became the system the plant runs on every day: 60+ machines in six halls, 27 people on three shifts. Client acceptance surfaced 112 issues (17 critical), all worked through with regression evidence, training and handover material. Profiling with OpenTelemetry removed the major N+1 hotspots and cut measured backend resource use by up to ~80%. It is now being handed over.