AI Operations Brain Β· Industrial Knowledge Graph + Multi-Agent AI for Plant Operations
Stack: FastAPI Β· Next.js 14 Β· PostgreSQL Β· Neo4j Β· Qdrant Β· GPT-4.1 Β· Docker Compose
- What It Does
- Prerequisites
- Installation & First Run
- Environment Variables
- Running the App
- Loading Demo Data
- Feature Walkthrough
- Document Upload Pipeline
- Running Tests
- Service Ports & URLs
- Architecture
- Troubleshooting
- Project Structure
- API Quick Reference
EPIC connects equipment, incidents, maintenance records, compliance standards, engineering drawings, and expert documents into a live knowledge graph. When an operator asks a question, five specialised AI agents query this graph simultaneously and stream a structured answer β with cited sources, risk scoring, and an auto-generated work order β in under 15 seconds.
Core demo scenario: Pump P-101 vibration alarm fires at 2 AM β operator opens EPIC β AI diagnoses 75% bearing failure risk, surfaces 3 compliance issues, matches 2 historical incidents, and issues a work order β all before the senior engineer picks up the phone.
| Requirement | Version | Notes |
|---|---|---|
| Docker Desktop | β₯ 4.20 | Must be running |
| Docker Compose | v2 (bundled) | docker compose version |
| Git | any | To clone the repo |
| OpenAI API key | optional | App works offline with heuristic fallback |
No Python, Node.js, or database installation required β everything runs in containers.
# 1. Clone the repository
git clone <repo-url> hck123
cd hck123
# 2. Copy environment template
cp .env.example .env
# 3. (Optional) Add your OpenAI key for full AI features
# Without it, all 5 agents work via heuristic fallback
nano .env
# 4. Build and start all services
docker-compose up --build
# First build takes ~3-4 minutes. Subsequent starts take ~15 seconds.
# 5. Open the app
open http://localhost:3000Tip: Use
docker-compose up --build -dto run in the background (detached mode).
Edit .env in the project root:
# Required for full LLM features (optional β fallback works without it)
OPENAI_API_KEY=sk-...
# Database passwords (defaults work for local dev)
POSTGRES_PASSWORD=opsbrain2024
NEO4J_PASSWORD=opsbrain2024
# OpenAI model
OPENAI_MODEL=gpt-4.1| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
(empty) | GPT-4.1 key. Omit to use offline heuristic fallback. |
POSTGRES_PASSWORD |
opsbrain2024 |
PostgreSQL password |
NEO4J_PASSWORD |
opsbrain2024 |
Neo4j password |
OPENAI_MODEL |
gpt-4.1 |
LLM model name |
# Start (background)
docker-compose up -d
# Start (foreground β see all logs)
docker-compose up
# Stop
docker-compose down
# Stop and wipe all data (full reset)
docker-compose down -v
# Rebuild after code changes
docker-compose up --build
# Logs for a specific service
docker-compose logs -f backend
docker-compose logs -f frontend
# Restart only the backend
docker-compose restart backend- Open http://localhost:3000
- Click the sparkle icon (β¨) in the bottom-left sidebar
- Click Generate Demo Data
- Wait ~10 seconds β 53+ entities are created across all tables
- The success screen shows Step 2: a list of 9 sample documents to download and upload via the Documents page
| Entity | Count |
|---|---|
| Project + Plants | 1 project, 2 plants (CDU Unit 4, VDU Unit 5) |
| Equipment | 6 (P-101 pump with vibration alarm, K-401 compressor, HX-201, V-301, P-202, G-101) |
| Users / Roles | 6 users covering all 7 roles (technician β manager) |
| Spare Parts | 4 with stock levels |
| Legacy Incidents | 4 (AI knowledge base + vector indexed) |
| Incident Reports | 3 (reported / investigation / CAPA stages) |
| Maintenance Records | 5 (completed + overdue) |
| Managed Work Orders | 4 (draft β approved β in_progress β closed) |
| Permits to Work | 3 (issued, under review, closed) |
| Safety Procedures | 3 (active SOP, peer-review JSA, draft) |
| Quality Inspections | 3 (scheduled, in_progress, closed with findings) |
| Action Items / CAPA | 3 |
| Sensor History | 30-day data for P-101 vibration + K-401 pressure |
| Knowledge Graph | Nodes + links for all entities |
| Compliance Records | 1 per equipment with open issues |
Sample documents are not inserted into the DB automatically β you upload them manually through the Documents page to demonstrate the live AI extraction pipeline.
curl -X POST http://localhost:8000/api/v1/admin/generate-demo# API
curl -X DELETE "http://localhost:8000/api/v1/admin/purge?entity=all"
# Or: sidebar trash icon β select entity types β confirm- Plant health score, alarm count, open work orders, compliance status
- Alert feed showing threshold breaches auto-raised by the background monitor
- Equipment health rings with failure probability badges
- Select equipment from the dropdown (e.g. P-101)
- Type or speak (click microphone) your question:
"Pump vibration increased today. Can I continue operating?"
- Watch 5 agents stream in real-time: Equipment Brain β Maintenance Advisor β Compliance Agent β Lessons Learned β Synthesizer
- Review: Risk card (Health / Failure Prob / Compliance / Maintenance Due), auto work order, cited sources
- Select equipment to see all sensor parameters as live line charts
- Alarm (orange dashed) and trip (red dashed) threshold overlays
- 30-day trending with anomaly periods highlighted
- Fleet health dashboard β click any equipment card for the Equipment Brain: full context including incidents, maintenance, documents, spare parts, compliance
- Live quick events pulled from DB (active alarms, overdue maintenance, critical WOs)
- Click Run AI RCA β causal chain with probability scores and evidence citations
- Quick Capture forms: Maintenance Record, Sensor Log, Incident Report, Work Order, Defect Report, Equipment Registration
- AI-generated forms β equipment fields pre-filled from the database
- Submissions dual-write to both AI-agent tables and workflow tables
- Create hot work / cold work / confined space / electrical isolation permits
- Full 10-stage approval workflow: draft β submitted β area_authority_review β safety_review β ap_approval β issued β active β suspended β completion_requested β closed
- Use the Acting As picker in the sidebar footer to switch roles and approve each stage without logging out
- 8-stage workflow with two-person rule enforced at the API level
- Try to verify a WO as the same user who completed it β system returns HTTP 403
- 6-stage workflow: draft β peer_review β technical_review β final_approval β active β obsolete
- Doc types: SOP, JSA, SWMS, MSDS, ERP, Checklist, Work Instruction
- Full 5-stage workflow: reported β investigation β root_cause_analysis β CAPA β closed
- 9 incident types (near miss, first aid, lost time, environmental, fire, spill, etc.)
- Severity P1βP5, cost and downtime tracking
- Checklist-based inspections with non-conformance tracking and scoring
- CAPA action items auto-created from findings
- Upload any industrial file (18+ formats: PDF, DOCX, XLSX, PPTX, TXT, CSV, DXF, DWG, STEP, IGES, IFC, SVG, PNG, JPG, and more)
- 6-step AI pipeline shown as a live progress bar
- Extracted entities panel shows equipment IDs, regulations, measurements, people
- Project β Plant β Drawing hierarchy navigator with search
- Upload P&ID drawings for SVG rendering + live analytics (linked incidents, PTWs, WOs)
- Force-directed graph β 20+ entity types, 30+ relationship types
- Click any node to explore its subgraph
- 6 tabs: Overview, Equipment, Maintenance, Incidents, Work Orders, Safety
- All charts pull live data from the database
- Drag-and-drop widget builder with 10+ widget types
- Save and reload multiple dashboards
- Per-equipment compliance score 0β100 with open issue register
- AI plant-wide analysis β prioritised remediation action list
- Immutable chronological log of every create/update/approve action
- Filter by type, actor, date range β export to CSV for ISO 45001 audit prep
- Area β Unit β Equipment hierarchy with live status indicators
- Project β Plant β Equipment drill-down
- Types: Industrial / Shutdown / Turnaround
| Control | Location | Function |
|---|---|---|
| βοΈ / π toggle | Sidebar header | Switch light / dark theme |
| Acting As picker | Sidebar footer | Impersonate any role for workflow demos |
| ποΈ trash icon | Sidebar bottom | Delete data (select entity types) |
| β¨ sparkle icon | Sidebar bottom | Generate demo data + download sample docs |
After generating demo data, download the 9 sample documents and upload them manually to demonstrate the live AI extraction pipeline.
- Open http://localhost:3000/documents
- Click Upload or drag files onto the upload zone
- Watch the 6-step progress bar:
- File saved β stored in uploads volume
- Text extracted β PyMuPDF / docx / openpyxl / pptx parsers
- Entities extracted β GPT-4.1 (or regex fallback) finds equipment IDs, regulations, people
- Drawing extracted β SVG generated for P&IDs and CAD files
- Knowledge graph updated β new nodes and relationships added to Neo4j
- Vector index updated β chunks indexed in Qdrant for semantic search
- Click the processed document to see the entity panel and AI summary
- Subsequent AI queries about the same equipment will now cite this document
# Copy all 9 files from the Docker container to ./abc/
mkdir -p abc
docker cp opsbrain-backend:/app/uploads/demo_samples/. abc/
ls abc/
# Or download via the API
curl -O http://localhost:8000/api/v1/admin/demo-docs/DOC-DEMO-PDF-01.pdf
# List what's available
curl http://localhost:8000/api/v1/admin/demo-docs| File | Format | Content |
|---|---|---|
DOC-DEMO-PDF-01.pdf |
P-101 Maintenance Inspection Report (2-page styled report with sensor data table and RCA) | |
DOC-DEMO-PDF-02.pdf |
K-401 Compressor Incident Investigation Report with 5-Why analysis and CAPA table | |
DOC-DEMO-DOCX-01.docx |
Word | SOP-P101-BEARING-REV3: Bearing Replacement Procedure (hazards, tools, step table) |
DOC-DEMO-DOCX-02.docx |
Word | Night Shift Handover Log β CDU Unit 4 (event timeline, equipment status, pending actions) |
DOC-DEMO-XLSX-01.xlsx |
Excel | Equipment Maintenance Schedule 2026 (colour-coded overdue/due/scheduled) |
DOC-DEMO-XLSX-02.xlsx |
Excel | Spare Parts Inventory Register (12 SKUs with stock levels and reorder alerts) |
DOC-DEMO-PPTX-01.pptx |
PowerPoint | Safety Toolbox Talk β Rotating Equipment (5 slides, dark theme) |
DOC-DEMO-TXT-01.txt |
Text | Night Shift Handover Notes (chronological event log + cost avoidance calculation) |
DOC-DEMO-CSV-01.csv |
CSV | P-101 Sensor Data Export β 30-day history for 4 parameters |
# Inside the running container
docker-compose exec backend python -m pytest tests/ -v
# Locally (Python 3.11 + venv)
cd backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python -m pytest tests/ -v# Inside the running container
docker-compose exec frontend npm test
# Locally (Node.js 18+)
cd frontend
npm install && npm test| Service | URL | Default Credentials |
|---|---|---|
| Frontend | http://localhost:3000 | β |
| Backend API | http://localhost:8000 | β |
| Swagger UI | http://localhost:8000/docs | β |
| Redoc | http://localhost:8000/redoc | β |
| Neo4j Browser | http://localhost:7474 | neo4j / opsbrain2024 |
| Qdrant Dashboard | http://localhost:6333/dashboard | β |
| PostgreSQL | localhost:5432 |
user opsbrain Β· db opsbrain |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js 14 Frontend β
β Industrial Dark UI Β· 21 pages Β· Zustand β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β REST + SSE (Server-Sent Events)
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (Python 3.11) β
β 25 Routers Β· 150+ endpoints Β· Async SQLAlchemy β
β β
β Agent Orchestrator βββββββββββββββββββββββββββββββββββ β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β βEquipment β βMaint. β βComplianceβ βLessons β β
β βBrain β βAdvisor β βAgent β βLearned β Synth β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β
β Background: Threshold Monitor Β· Document Pipeline β
ββββββββ¬βββββββββββββββββββ¬βββββββββββββββββββββββββ¬ββββββββββ
β β β
ββββββββΌβββββββ ββββββββββΌββββ βββββββββΌβββββ
β PostgreSQL β β Neo4j β β Qdrant β
β 25 models β β Knowledge β β Vector DB β
β async ORM β β Graph β β (RAG) β
βββββββββββββββ ββββββββββββββ ββββββββββββββ
Key data flows:
Document Upload β Text Extract β LLM Entity Extraction
β Equipment auto-register β Knowledge Graph update
β Vector index β Available for AI queries
Sensor Reading β Threshold Monitor background agent
β Auto Work Order β Dashboard Alert
AI Query β 5 agents (parallel DB + graph queries)
β SSE stream to UI β Risk score + Work Order + Citations
lsof -i :3000 # find what is using port 3000
lsof -i :8000
kill -9 <PID>docker-compose logs backend | tail -50
docker-compose restart backend# Check the generate endpoint directly
curl -X POST http://localhost:8000/api/v1/admin/generate-demo | python3 -m json.tool
# Check equipment count
curl http://localhost:8000/api/v1/equipment | python3 -c "import json,sys; print(len(json.load(sys.stdin)), 'equipment records')"The heuristic fallback runs without an API key. If the stream is completely empty:
docker-compose logs backend | grep -iE "error|agent|llm|exception" | tail -30# Check the document status directly
curl http://localhost:8000/api/v1/documents | python3 -m json.tool | grep -A5 "status"
docker-compose logs backend | grep "Pipeline" | tail -20docker-compose down -v # removes all Docker volumes (database data)
docker-compose up --build # fresh build + empty DBdocker stats opsbrain-backend opsbrain-frontend opsbrain-postgres opsbrain-neo4j opsbrain-qdranthck123/
βββ backend/
β βββ main.py # App entry, router registration
β βββ requirements.txt
β βββ app/
β β βββ api/ # 25 REST routers (one per domain)
β β β βββ admin.py # Demo gen, purge, stats, doc downloads
β β β βββ agents.py # SSE query endpoint
β β β βββ documents.py # Upload + pipeline
β β β βββ equipment.py
β β β βββ sensors.py
β β β βββ permits.py
β β β βββ managed_work_orders.py
β β β βββ ...
β β βββ agents/
β β β βββ orchestrator.py # 5-agent SSE pipeline
β β βββ services/
β β β βββ db_service.py # All DB read/write operations
β β β βββ llm_service.py # GPT-4.1 + heuristic fallback
β β β βββ demo_docs.py # Sample document generator (PDF/DOCX/XLSX/PPTX/TXT/CSV)
β β β βββ doc_entity_mapper.py # Document entities β DB tables
β β β βββ vector_service.py # Qdrant indexing
β β β βββ seed.py # DB seed on first startup
β β β βββ threshold_monitor.py # Background sensor alarm agent
β β βββ db/
β β β βββ models.py # 25 SQLAlchemy models
β β β βββ database.py # Async session factory
β β βββ core/config.py # Settings loaded from .env
β βββ tests/ # pytest suite (13 tests)
β
βββ frontend/
β βββ src/
β β βββ app/ # 21 Next.js App Router pages
β β βββ components/
β β β βββ Layout/Sidebar.tsx # Navigation + demo generator modal
β β β βββ Dashboard/ # Widget components
β β β βββ ui/ # Shared primitives
β β βββ lib/
β β βββ api.ts # All API fetch helpers
β β βββ types.ts # TypeScript interfaces
β β βββ page-state.ts # Zustand page-state store
β β βββ theme-context.tsx # Light/dark theme
β β βββ user-context.tsx # Acting-As user context
β βββ package.json
β
βββ docker-compose.yml
βββ .env.example
βββ abc/ # Downloaded sample documents
βββ README.md
# Equipment
GET /api/v1/equipment # List all
GET /api/v1/equipment/{id} # Detail
GET /api/v1/equipment/{id}/brain # Full knowledge context
GET /api/v1/equipment/{id}/timeline # Chronological event history
# AI Query (streaming SSE)
POST /api/v1/agents/query # Body: {"query": "...", "equipment_id": "P-101"}
# Documents
GET /api/v1/documents # List
POST /api/v1/documents/upload # Upload (multipart/form-data, field: file)
GET /api/v1/documents/{id} # Detail + extracted entities
# Sensors
GET /api/v1/sensors # All equipment sensor overview
GET /api/v1/sensors/{equipment_id} # Full sensor dashboard + history
# Workflow objects
GET/POST /api/v1/work-orders # Managed work orders
GET/POST /api/v1/permits # Permits to Work
GET/POST /api/v1/incidents # Incident reports
GET/POST /api/v1/inspections # Quality inspections
GET/POST /api/v1/procedures # Safety procedures
# Admin
POST /api/v1/admin/generate-demo # Seed full demo dataset
GET /api/v1/admin/stats # Record counts per entity type
DELETE /api/v1/admin/purge?entity=all # Full data reset
GET /api/v1/admin/demo-docs # List downloadable sample docs
GET /api/v1/admin/demo-docs/{filename} # Download a sample document
# Graph
GET /api/v1/knowledge-graph/nodes # All graph nodes
GET /api/v1/knowledge-graph/links # All graph edges
# Interactive docs
GET /docs # Swagger UI
GET /redoc # Redoc