Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EPIC β€” Enterprise Platform for Industrial Cognition

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


Table of Contents

  1. What It Does
  2. Prerequisites
  3. Installation & First Run
  4. Environment Variables
  5. Running the App
  6. Loading Demo Data
  7. Feature Walkthrough
  8. Document Upload Pipeline
  9. Running Tests
  10. Service Ports & URLs
  11. Architecture
  12. Troubleshooting
  13. Project Structure
  14. API Quick Reference

What It Does

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.


Prerequisites

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.


Installation & First Run

# 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:3000

Tip: Use docker-compose up --build -d to run in the background (detached mode).


Environment Variables

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

Running the App

# 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

Loading Demo Data

Via the UI (recommended)

  1. Open http://localhost:3000
  2. Click the sparkle icon (✨) in the bottom-left sidebar
  3. Click Generate Demo Data
  4. Wait ~10 seconds β€” 53+ entities are created across all tables
  5. The success screen shows Step 2: a list of 9 sample documents to download and upload via the Documents page

What gets created

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.

Via the API

curl -X POST http://localhost:8000/api/v1/admin/generate-demo

Reset all data

# API
curl -X DELETE "http://localhost:8000/api/v1/admin/purge?entity=all"

# Or: sidebar trash icon β†’ select entity types β†’ confirm

Feature Walkthrough

1. Dashboard (/)

  • 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

2. AI Query (/query)

  • 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

3. Sensors (/sensors)

  • 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

4. Equipment (/equipment)

  • Fleet health dashboard β€” click any equipment card for the Equipment Brain: full context including incidents, maintenance, documents, spare parts, compliance

5. Root Cause Analysis (/rca)

  • Live quick events pulled from DB (active alarms, overdue maintenance, critical WOs)
  • Click Run AI RCA β†’ causal chain with probability scores and evidence citations

6. Forms Hub (/forms)

  • 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

7. Permit to Work (/permits)

  • 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. Managed Work Orders (/managed-work-orders)

  • 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

9. Safety Procedures (/procedures)

  • 6-stage workflow: draft β†’ peer_review β†’ technical_review β†’ final_approval β†’ active β†’ obsolete
  • Doc types: SOP, JSA, SWMS, MSDS, ERP, Checklist, Work Instruction

10. Incident Reports

  • 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

11. Quality Inspections (/inspections)

  • Checklist-based inspections with non-conformance tracking and scoring
  • CAPA action items auto-created from findings

12. Documents (/documents)

  • 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

13. Engineering Drawings (/drawings)

  • Project β†’ Plant β†’ Drawing hierarchy navigator with search
  • Upload P&ID drawings for SVG rendering + live analytics (linked incidents, PTWs, WOs)

14. Knowledge Graph (/graph)

  • Force-directed graph β€” 20+ entity types, 30+ relationship types
  • Click any node to explore its subgraph

15. Reports (/reports)

  • 6 tabs: Overview, Equipment, Maintenance, Incidents, Work Orders, Safety
  • All charts pull live data from the database

16. Custom Dashboards (/dashboards)

  • Drag-and-drop widget builder with 10+ widget types
  • Save and reload multiple dashboards

17. Compliance (/compliance)

  • Per-equipment compliance score 0–100 with open issue register
  • AI plant-wide analysis β†’ prioritised remediation action list

18. Audit Trail (/audit)

  • Immutable chronological log of every create/update/approve action
  • Filter by type, actor, date range β€” export to CSV for ISO 45001 audit prep

19. Plant Twin (/plant)

  • Area β†’ Unit β†’ Equipment hierarchy with live status indicators

20. Projects (/projects)

  • Project β†’ Plant β†’ Equipment drill-down
  • Types: Industrial / Shutdown / Turnaround

Sidebar Controls

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

Document Upload Pipeline

After generating demo data, download the 9 sample documents and upload them manually to demonstrate the live AI extraction pipeline.

Steps

  1. Open http://localhost:3000/documents
  2. Click Upload or drag files onto the upload zone
  3. 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
  4. Click the processed document to see the entity panel and AI summary
  5. Subsequent AI queries about the same equipment will now cite this document

Get the sample documents

# 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

Sample document descriptions

File Format Content
DOC-DEMO-PDF-01.pdf PDF P-101 Maintenance Inspection Report (2-page styled report with sensor data table and RCA)
DOC-DEMO-PDF-02.pdf 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

Running Tests

Backend (pytest)

# 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

Frontend (Vitest)

# Inside the running container
docker-compose exec frontend npm test

# Locally (Node.js 18+)
cd frontend
npm install && npm test

Service Ports & URLs

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

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   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

Troubleshooting

Port already in use

lsof -i :3000    # find what is using port 3000
lsof -i :8000
kill -9 <PID>

Backend health check fails / won't start

docker-compose logs backend | tail -50
docker-compose restart backend

"No equipment found" after generating demo data

# 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')"

AI query returns no stream or empty agents

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

Document upload pipeline hangs at a step

# 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 -20

Full reset (wipe all data, fresh start)

docker-compose down -v      # removes all Docker volumes (database data)
docker-compose up --build   # fresh build + empty DB

View live resource usage

docker stats opsbrain-backend opsbrain-frontend opsbrain-postgres opsbrain-neo4j opsbrain-qdrant

Project Structure

hck123/
β”œβ”€β”€ 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

API Quick Reference

# 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages