Deterministic Rules Engine Pipeline for secure clinical knowledge retrieval and context filtering. Built using FastAPI, Supabase, React, and PostgreSQL with DAG traversal, hierarchical permission enforcement, BFS-based filtering, and zero LLM involvement.
- Python 3.11+
- Node.js v18+
- Supabase account (free tier)
git clone https://github.com/Anubhav852/brahmo
cd brahmo
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Mac/Linux
pip install -r requirements.txt
cp .env.example .env # add your Supabase URL and KEY
uvicorn main:app --reload --port 8000- Create a Supabase project at supabase.com
- Go to SQL Editor
- Run
supabase/schema.sql - Run
supabase/seed.sql - Verify:
SELECT COUNT(*) FROM knowledge_nodes→ 50 - Verify:
SELECT COUNT(*) FROM users→ 7
cd frontend
npm install
npm start
# Opens at http://localhost:3000A Rules Engine pipeline that:
- Traverses a Directed Acyclic Graph (DAG) of knowledge nodes upward from a user's entry point
- Injects globally-relevant Zone 2 nodes (drug safety constraints, hospital-wide policies)
- Applies 5 sequential checks to filter down to a candidate set of 12-42 nodes
- All deterministically — ZERO LLM involvement
User opens session (role: VIEWER, ceiling: L10, dept: Ortho Ward) → Permission Compiler — O(1) lookup compiled once from cache → Entry Point Resolver — maps dept to DAG leaf node → BFS Traversal — walks UP the DAG via parent_ids (pure Python, zero DB) → Zone 2 Injection — global safety nodes added after BFS → 5 Sequential Checks: Check 1: Isolation — org_id match Check 2: Compliance — MNPI/clearance tags Check 3: Permission — hierarchy ceiling Check 4: Temporal — not expired/superseded Check 5: Derivability — score < 0.7 → Candidate Set — annotated nodes with metadata
All DB fetches happen ONCE at server startup in parallel. Zero DB calls during requests.
| User | Role | Ceiling | Final Nodes | Pipeline Time |
|---|---|---|---|---|
| Nurse Priya | VIEWER | L10 | 16 | 0.32ms |
| Dr. Vikram | HOD | L4 | 12 | 0.13ms |
| Admin Suresh | ADMIN | L1 | 42 | 0.34ms |
Total pipeline time: <1ms (spec target: <500ms)
The same graph, same 50 nodes, completely different candidate sets based on who is asking:
- Priya sees only Ortho + global safety nodes. Zero Cardiology, zero Paeds, zero MNPI nodes.
- Vikram sees Ortho dept decisions Priya cannot (lower ceiling). Still no MNPI+CONFIDENTIAL.
- Suresh sees all departments including MNPI/CONFIDENTIAL nodes (N-A01, N-A02, N-O11, N-O12, N-C04).
brahmo/
├── main.py # FastAPI app + full pipeline + startup cache
├── main_api.py # Re-exports app (legacy shim)
├── permission_compiler.py # O(1) permission hashmap
├── traversal.py # BFS entry (original)
├── requirements.txt
├── .env.example
├── README.md
├── architecture.md # BFS strategy + filter ordering rationale
├── data_sources.md # Clinical data sources
├── backend/
│ ├── filters.py # 5 sequential checks
│ ├── traversal.py # BFS cached + original
│ └── permission_compiler.py
├── frontend/
│ └── src/
│ └── App.js # React dashboard + funnel visualisation
├── supabase/
│ ├── schema.sql # Database schema
│ └── seed.sql # 50 nodes + 7 users
└── docs/
└── architecture.md
- Nurse Priya — VIEWER, L10, Ortho → 16 nodes, Ortho + global safety only
- Dr. Vikram — HOD, L4, Ortho → 12 nodes, sees dept-level decisions Priya cannot
- Admin Suresh — ADMIN, L1 → 42 nodes, full hospital access including MNPI
- Zone 2 Toggle — disable to remove global drug safety nodes and watch count drop
- Silent exclusion — unauthorized nodes absent, no error messages, no 403s
- ZERO LLM — all filtering is deterministic, binary, rule-based
- Startup cache — all tables fetched once in parallel at boot, zero DB calls per request
- Sequential checks — output of check N is input to check N+1 (compliance before permission)
- O(1) permission lookup — compiled once per session into a hashmap, not per node
- Silent exclusion — unauthorized nodes simply absent, never a 403 or access denied
- Zone 2 injection — after BFS, before checks, so global nodes still go through all 5 filters
- Pure Python BFS — adjacency map built from parent_ids at startup, traversal is in-memory
- MNPI-tagged nodes invisible to users without compliance clearance
- Department isolation enforced at BFS level — Priya's traversal never reaches Cardiology
- Permission ceiling enforced at Check 3 — HOD decisions invisible to VIEWER
- Compliance check runs before permission check — excluded nodes never reach permission stage
- No indication of hidden nodes — silent exclusion throughout