> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Entity Relationship Diagrams

> Index of ERD documentation for database schema and modules

> **Last Updated:** 2026-01-11\
> **Total Tables:** 433\
> **Modules:** 9

## Overview

This directory contains Entity Relationship Diagrams (ERDs) for all Encore OS Platform database modules. Each diagram shows table relationships, foreign keys, and RLS policy coverage.

## High-Level Architecture

```mermaid theme={null}
erDiagram
    PF_PLATFORM ||--o{ HR_WORKFORCE : "manages employees"
    PF_PLATFORM ||--o{ FA_FINANCE : "handles accounting"
    PF_PLATFORM ||--o{ FW_FORMS : "powers workflows"
    PF_PLATFORM ||--o{ RH_RECOVERY : "tracks residents"
    PF_PLATFORM ||--o{ FM_FACILITIES : "maintains assets"
    PF_PLATFORM ||--o{ GR_GOVERNANCE : "enforces policies"
    PF_PLATFORM ||--o{ LO_LEADERSHIP : "drives strategy"
    PF_PLATFORM ||--o{ IT_SERVICE : "supports users"
    
    PF_PLATFORM {
        uuid organization_id PK
        uuid user_id PK
        uuid site_id PK
        string tenant_isolation
    }
    
    HR_WORKFORCE {
        uuid employee_id PK
        uuid position_id FK
        uuid department_id FK
    }
    
    FA_FINANCE {
        uuid account_id PK
        uuid invoice_id PK
        uuid journal_entry_id PK
    }
    
    FW_FORMS {
        uuid form_id PK
        uuid workflow_id PK
        uuid submission_id PK
    }
    
    RH_RECOVERY {
        uuid resident_id PK
        uuid episode_id PK
        uuid bed_id PK
    }
    
    FM_FACILITIES {
        uuid asset_id PK
        uuid work_order_id PK
        uuid inventory_id PK
    }
    
    GR_GOVERNANCE {
        uuid policy_id PK
        uuid audit_id PK
        uuid risk_id PK
    }
    
    LO_LEADERSHIP {
        uuid meeting_id PK
        uuid rock_id PK
        uuid kpi_id PK
    }
    
    IT_SERVICE {
        uuid ticket_id PK
        uuid sla_id PK
        uuid asset_id PK
    }
```

## Module ERDs

| Module                                        | Prefix | Tables | ERD Document                 | Description                          |
| --------------------------------------------- | ------ | ------ | ---------------------------- | ------------------------------------ |
| [Platform Foundation](/database/erd/PF_ERD)   | `pf_`  | 73     | [View](/database/erd/PF_ERD) | Core tenancy, auth, organizations    |
| [Human Resources](/database/erd/HR_ERD)       | `hr_`  | 75     | [View](/database/erd/HR_ERD) | Employees, positions, leave, payroll |
| [Finance & Accounting](/database/erd/FA_ERD)  | `fa_`  | 45     | [View](/database/erd/FA_ERD) | GL, invoices, payments, budgets      |
| [Forms & Workflow](/database/erd/FW_ERD)      | `fw_`  | 54     | [View](/database/erd/FW_ERD) | Forms, submissions, automations      |
| [Recovery Housing](/database/erd/RH_ERD)      | `rh_`  | 51     | [View](/database/erd/RH_ERD) | Residents, beds, episodes, billing   |
| [Facilities Management](/database/erd/FM_ERD) | `fm_`  | 22     | [View](/database/erd/FM_ERD) | Assets, work orders, inventory       |
| [Governance & Risk](/database/erd/GR_ERD)     | `gr_`  | 49     | [View](/database/erd/GR_ERD) | Policies, audits, compliance         |
| [Leadership OS](/database/erd/LO_ERD)         | `lo_`  | 29     | [View](/database/erd/LO_ERD) | Meetings, goals, KPIs                |
| [IT Service Management](/database/erd/IT_ERD) | `it_`  | 35     | [View](/database/erd/IT_ERD) | Tickets, SLAs, knowledge base        |

## Cross-Module Dependencies

All modules depend on Platform Foundation (PF) for:

* **Organization context** (`pf_organizations`)
* **User identity** (`pf_profiles`, `pf_user_roles`)
* **Site/location** (`pf_sites`)
* **Audit tracking** (`pf_audit_logs`)

```mermaid theme={null}
graph TD
    subgraph "Platform Foundation (PF)"
        ORG[pf_organizations]
        PROF[pf_profiles]
        SITES[pf_sites]
        ROLES[pf_user_roles]
    end
    
    subgraph "Domain Modules"
        HR[HR Tables]
        FA[FA Tables]
        FW[FW Tables]
        RH[RH Tables]
        FM[FM Tables]
        GR[GR Tables]
        LO[LO Tables]
        IT[IT Tables]
    end
    
    ORG --> HR
    ORG --> FA
    ORG --> FW
    ORG --> RH
    ORG --> FM
    ORG --> GR
    ORG --> LO
    ORG --> IT
    
    PROF --> HR
    PROF --> FA
    PROF --> FW
    PROF --> RH
    
    SITES --> HR
    SITES --> RH
    SITES --> FM
```

## RLS Policy Coverage Summary

| Module    | Tables  | Full Coverage | Partial | Special |
| --------- | ------- | ------------- | ------- | ------- |
| PF        | 73      | 68            | 3       | 2       |
| HR        | 75      | 70            | 4       | 1       |
| FA        | 45      | 43            | 2       | 0       |
| FW        | 54      | 48            | 4       | 2       |
| RH        | 51      | 49            | 2       | 0       |
| FM        | 22      | 21            | 1       | 0       |
| GR        | 49      | 47            | 2       | 0       |
| LO        | 29      | 28            | 1       | 0       |
| IT        | 35      | 34            | 1       | 0       |
| **Total** | **433** | **408**       | **20**  | **5**   |

**Legend:**

* **Full Coverage:** 4 policies (SELECT, INSERT, UPDATE, DELETE)
* **Partial:** Intentional \< 4 policies (audit/version tables)
* **Special:** Custom access patterns (deny-all, public read, etc.)

## Related Documentation

* [RLS Policy Coverage Report](/database/RLS_COVERAGE)
* [RLS Patterns Reference](/database/RLS_PATTERNS)
* [Database Development Guide](/development/DATABASE_DEVELOPMENT_GUIDE)
* [Database Audit Report](https://github.com/Encore-OS/encoreos/blob/development/docs/archive/architecture/DATABASE_AUDIT_REPORT.md)
