Skip to main content

Work Order Management System — C4 Architecture Model


C1 — System Context

Narrative

At the system context level, the WO Management System is a subsystem within CODITECT that mediates all change control operations for regulated environments. Four actor categories interact with it: Regulated Operations Staff (system owners, QA, IT operations) who create, approve, and execute work orders through the platform interface; Vendors who receive and execute external work orders for instrument installations and qualifications; CODITECT AI Agents who autonomously create and execute work orders as part of orchestrated workflows; and Regulatory Auditors who query the immutable audit trail during inspections. The WO system connects to three external system categories: the CODITECT Core Platform (orchestrator, compliance engine, event bus), enterprise systems (CMMS, ticketing, asset management), and compliance infrastructure (certificate authority for e-signatures, policy engine).

Diagram

Compliance Implications

Every connection between the WO system and external systems is audited. Agent-initiated WOs carry the same compliance rigor as human-initiated WOs — the audit trail records the agent ID, the task that triggered the WO, and the model tier used. Regulatory auditors have read-only access to audit trails with tenant-scoped filtering; they cannot modify any records.


C2 — Container Diagram

Narrative

Zooming into the WO Management System boundary, it decomposes into six containers. The WO API Service is the primary entry point — a TypeScript/Express service handling REST API requests, validating inputs, and delegating to domain services. The WO Domain Services container holds the core business logic: lifecycle engine, hierarchy manager, resource matcher, approval workflow, schedule tracker, and PM automation. The WO State Store is a PostgreSQL schema (within CODITECT's existing PostgreSQL instance) holding all WO tables with RLS policies. The WO Event Emitter publishes lifecycle events to the CODITECT Event Bus using the transactional outbox pattern. The WO Adapter Layer contains integration adapters for the Agent Orchestrator, Compliance Engine, and IDE Shell. The WO Audit Archive manages long-term audit trail storage, implementing retention policies and archival to cold storage.

Diagram

Container Responsibilities

ContainerTechnologyPrimary ResponsibilityCompliance Role
WO API ServiceTypeScript / ExpressRequest handling, validationInput validation, rate limiting
Lifecycle EngineTypeScriptState machine, transition rulesAudit trail generation per transition
Hierarchy ManagerTypeScriptMaster/Linked WO coordinationDependency integrity for change control
Resource MatcherTypeScriptCapability-based assignmentAuditable assignment decisions
Approval WorkflowTypeScriptE-signature collectionFDA 21 CFR Part 11 §11.50, §11.70
Schedule TrackerTypeScriptDuration tracking, cost attributionBilling evidence, capacity planning
PM AutomationTypeScriptScheduled WO generationPreventive maintenance compliance
WO State StorePostgreSQLDurable state, audit trailImmutable records, RLS isolation
Event EmitterTypeScriptEvent publishingReal-time compliance monitoring
Adapter LayerTypeScript / PythonPlatform integrationCross-system audit correlation
Audit ArchivePostgreSQL + GCSLong-term retentionFDA retention requirements (7+ years)

C3 — Component Diagram (WO Lifecycle Engine)

Narrative

The Lifecycle Engine is the most critical component — every WO operation passes through it. It decomposes into five internal components. The State Machine defines valid transitions and enforces the transition graph (draft → pending_approval → assigned → in_progress → blocked → completed → closed). The Transition Validator applies business rules before each transition: dependency satisfaction for in_progress, approval collection for completed, compliance policy checks via the Compliance Engine. The Audit Trail Writer generates immutable audit entries for every state change — it operates within the same database transaction as the state change to guarantee consistency. The Version Controller implements optimistic locking — every UPDATE increments the version column and the application checks that the version hasn't changed since read. The Event Producer prepares typed events for the Event Emitter, using the transactional outbox pattern to ensure events are published exactly once after commit.

Diagram

Component Interfaces

ComponentInputOutputFailure Mode
State Machine{currentStatus, requestedStatus}Valid/Invalid + allowed transitionsReturns allowed transitions on invalid request
Transition Validator{woId, newStatus, context}Pass/Fail + failure reasons[]Aggregates all failures (doesn't short-circuit)
Audit Trail Writer{woId, action, field, old, new, actor, reason}AuditEntryTransaction rollback (audit and state change are atomic)
Version Controller{woId, expectedVersion, updates}Updated record / Conflict errorRetry with fresh version (up to 3 attempts)
Event Producer{woId, eventType, payload}Outbox recordOutbox write is in same transaction; polling handles delivery

C4 — Code Diagram (WO State Machine + Transition Validator)

Narrative

At the code level, the State Machine is implemented as a WOStateMachine class with an immutable transition map. The transition map is a Record<WOStatus, WOStatus[]> — for each status, it lists the valid target statuses. The Transition Validator is a composition of TransitionRule implementations, each responsible for one validation concern (dependency check, approval check, compliance check). Rules are evaluated in sequence and all failures are collected (fail-open pattern for diagnostics, fail-closed for execution). The AuditTrailWriter is a pure function that takes a transition context and returns an AuditEntry — the caller is responsible for persisting it within the transaction boundary.

Diagram

Design Rationale

The rule composition pattern (Strategy + Composite) ensures that new validation rules can be added without modifying existing code — critical for regulated environments where each code change requires change control. Rules are stateless and pure, making them testable in isolation. The fail-closed-with-diagnostics approach means that if any rule fails, the transition is blocked, but all failures are collected so the operator knows exactly what needs to be resolved — not just the first failure encountered.

Compliance Implications

  • Every TransitionRule implementation is a testable unit with documented behavior — providing validation evidence for IQ/OQ.
  • The AuditTrailWriter produces entries that satisfy FDA 21 CFR Part 11 §11.10(e) requirements: who, what, when, why.
  • The VersionController prevents concurrent modification — satisfying data integrity requirements under §11.10(b).
  • Rule evaluation order and results are logged, enabling reconstruction of every decision during regulatory inspection.