Knowledge-Based Engineering (KBE) Proof-of-Concept - Demonstrating how to transform passive building ontologies (Brick/REC) into active operational systems with Palantir-style kinetic capabilities.
This demo portal showcases a complete Knowledge-Based Engineering system for building automation, featuring:
- ActionDefinition Templates - Reusable operation specifications with SHACL-style validation
- ActionExecution Instances - Reified transactions with complete audit trails
- ODRL Governance - Role-based access control and permission policies
- Interactive Knowledge Graph - D3.js visualization of ontology relationships
- Real-time Validation - Client-side constraint enforcement with violation reporting
# Using Make (easiest)
make quick-start
# Or using Docker Compose
docker compose up -d
# Or using Docker CLI
docker build -t kbe-demo-portal .
docker run -d -p 8008:8008 kbe-demo-portalAccess at: http://localhost:8008
Prerequisites: Python 3.13, uv
# Install dependencies
uv sync
# Run development server
uv run python src/main.py
# Or using uvicorn directly
uv run uvicorn src.main:app --reload --port 8008- 5-Zone Building Model (Z001-Z005)
- HVAC zones with temperature control
- Occupancy tracking
- Power usage monitoring
- FastAPI REST API - 16 endpoints
- Thread-safe State Management - Async/await throughout
- Pydantic v2 Validation - Type-safe models
Available Actions:
- Adjust Temperature Setpoint - Modify zone setpoints with validation
- Load Shed - Demand management through lighting reduction
- Pre-Cooling - Optimize peak demand costs through strategic pre-cooling
Action Properties:
- SHACL-style validation rules (60-80F range, max 15F delta)
- ODRL governance policies
- Side effects tracking (HVAC mode changes, power consumption, audit logs)
- Complete audit trail with violation logging
SHACL Constraints:
- Adjust Setpoint: 60-80F range, max 15F delta, operator 5F limit
- Load Shed: Levels 1-5, max 240 min duration, level 4-5 max 120 min
- Pre-Cooling: 60-75F target, 30 min - 8 hour window, max 10F/hr cooling rate
ODRL Policies:
- Operator: Basic setpoint controls (5F limit), no load shed or pre-cooling
- Facility Manager: Full setpoint access, shed levels 1-3, pre-cooling (3 zones max, $50 cost limit)
- Energy Manager: Full access to all actions including high shed levels (4-5) and unrestricted pre-cooling
- Contractor: Limited setpoint access, no emergency actions, no optimization features
Security Features:
- Failed action logging for security monitoring
- Comprehensive violation collection and reporting
- Role-based access control enforcement
- Audit trail with full KBE ontology exposure
Visualize the complete semantic structure:
- 31 Nodes: Brick classes, KBE actions, properties, constraints, policies, roles
- 43 Relationships: Composition, validation, permissions, enforcement
- 3 Layout Modes: Force-Directed, Hierarchical, Radial
- Filtering: View by node type (all/classes/actions/properties)
- Interactive: Click to select, drag to reposition, zoom/pan
- Export: Download as SVG
Access at: http://localhost:8008/static/graph.html
- Architecture Summary - System design and components
- API Design - REST endpoint specifications
- Building Model - Zone and equipment details
- Test Summary - Test coverage report (232 tests)
- Graph Visualization - Knowledge graph guide
- Docker Guide - Container deployment instructions
# All tests (232 tests)
uv run pytest
# With coverage
uv run pytest --cov=src --cov-report=html
# Specific test file
uv run pytest tests/test_api/test_actions_endpoints.py -v# Lint
uv run ruff check src/
# Format
uv run ruff format src/
# Type checking
uv run mypy src/make help # Show all available commands
make build # Build Docker image
make run # Run container
make test # Run tests in container
make logs # View container logs
make shell # Access container shell
make clean # Remove container and imagesrc/
api/ # REST API endpoints
actions.py # Action execution endpoints (5)
building.py # Building state endpoints (6)
audit.py # Audit trail endpoints (5)
models/ # Pydantic models
building.py # Building, Zone, Equipment
kbe_actions.py # ActionDefinition, ActionExecution
actions/ # Specific action types
services/ # Business logic
action_executor.py # Core execution engine
validator.py # SHACL validation
state_manager.py # State management
static/ # Web UI
index.html # Demo portal
graph.html # Knowledge graph
main.py # FastAPI application
GET /- Demo portal web UIGET /health- Health checkGET /docs- OpenAPI documentationGET /redoc- ReDoc documentation
POST /actions/execute- Execute an actionPOST /actions/validate- Validate action parametersGET /actions/active- List active actionsPOST /actions/{action_id}/cancel- Cancel an actionGET /actions/types- List available action types
GET /building/state- Get all zone statesGET /building/zones/{zone_id}/state- Get zone statePOST /building/zones/{zone_id}/initialize- Initialize zoneGET /building/zones/{zone_id}/history- Get state historyGET /building/statistics- Get system statisticsGET /building/zones- List all zones
GET /audit/history- Get action historyGET /audit/{action_id}- Get action detailsGET /audit/zone/{zone_id}- Get zone audit trailGET /audit/summary- Get audit summaryGET /audit/recent- Get recent actions
Test Coverage: 232 tests, >85% coverage
tests/
test_models/ # Model validation tests (141)
test_building.py
test_kbe_actions.py
test_action_validation.py
test_api/ # API endpoint tests (76)
test_actions_endpoints.py
test_building_endpoints.py
test_audit_endpoints.py
test_services/ # Service logic tests (15)
test_action_executor.py
test_validator.py
- Select zone (Z001-Z005)
- Choose user role (Operator/Facility Manager/Energy Manager/Contractor)
- Set new temperature setpoint
- Select priority level
- Execute action
- View validation results and audit trail
Try these violations:
- Operator trying to change >5F (denied)
- Contractor trying emergency priority (denied)
- Anyone trying to set outside 60-80F range (denied)
- Switch to "Load Shed" action
- Select shed level (1-5)
- Set duration (max 240 min)
- Energy Manager can execute level 4-5
- Other roles limited to level 1-3
- Switch to "Pre-Cooling" action
- Set target temperature (60-75F)
- Configure start time (e.g., 05:00) and occupancy time (e.g., 08:00)
- Adjust max cooling rate (1-10F/hr)
- Energy Manager has full access
- Facility Manager limited to 3 zones and $50 cost
- Operators and Contractors denied access
Try these violations:
- Operator trying to execute (denied - requires optimization expertise)
- Facility Manager with 4+ zones (denied - 3 zone limit)
- Target temp below 62F (denied - too aggressive for economics)
- Time window less than 30 min (denied - insufficient pre-cooling time)
Base Image: ghcr.io/astral-sh/uv:python3.13-bookworm-slim
Features:
- Multi-stage build for optimal size (~150-200MB final image)
- UV for 150x faster dependency installation
- Non-root user for security
- Built-in health checks
- Bytecode compilation for faster startup
See DOCKER.md for complete deployment guide.
ENV=production # Environment (development/production)
LOG_LEVEL=info # Logging level (debug/info/warning/error)
PORT=8008 # Application portThe application runs on port 8008 by default (configurable in src/main.py).
- Backend: Python 3.13, FastAPI, Pydantic v2
- Package Manager: Astral UV
- Frontend: Vanilla JavaScript, D3.js v7, responsive CSS
- Testing: pytest, pytest-asyncio
- Container: Docker with multi-stage builds
This is a proof-of-concept demo built with the Hive Mind Collective Intelligence System.
- Fork the repository
- Create a feature branch
- Make changes with tests
- Run test suite (
make test) - Submit pull request
- Python 3.13+ type hints
- Pydantic v2 models
- FastAPI async/await patterns
- Maximum line length: 100 characters
- Docstrings for all public functions
[Add your license here]
- Brick Schema - Building ontology foundation
- SHACL - Validation constraint language
- ODRL - Open Digital Rights Language for policies
- Astral UV - Fast Python package management
- FastAPI - Modern web framework
- D3.js - Interactive graph visualization
This project was built using the Hive Mind Collective Intelligence System, coordinating 4 specialized agents in parallel:
- Researcher Agent - Domain analysis and specifications
- Coder Agent #1 - Pydantic model layer
- Coder Agent #2 - FastAPI application layer
- Tester Agent - Comprehensive test suite
See HIVE_SUMMARY.md for complete development details.
Questions? Check the documentation or explore the interactive graph to understand the KBE framework.