# yumjiin/bank-ontology-layer architecture

> Architecture diagram of the GitHub repository yumjiin/bank-ontology-layer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yumjiin/bank-ontology-layer
- Repository: https://github.com/yumjiin/bank-ontology-layer

## Overview

Bank Ontology Layer lets users ask banking-data questions through an LLM agent, which uses constrained ontology tools rather than writing SQL. The service exposes ontology description, object and linked-object searches, metric calculations, role-based masking/filter restrictions, and approval-governed actions; it also records agent traces. Ontology metadata drives SQL compilation and query execution against PostgreSQL. The README documents the overall app-to-agent-to-service-to-database flow. Some detailed runtime links are supported only by the shown excerpts or README; unsampled subsystems are represented without speculative internal call chains.

Main entry points: [`service/main.py`](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/main.py) (FastAPI endpoints), [`service/query.py`](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/query.py) (Query execution), [`service/actions.py`](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/actions.py) (Action approvals), [`data/seed.py`](https://github.com/yumjiin/bank-ontology-layer/blob/main/data/seed.py) (Data seeding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client_agent["Demo and agent"]
  node_demo["Streamlit demo<br/>[streamlit_app.py]"]
  node_agent_loop["Agent loop<br/>[loop.py]"]
  node_tool_defs["Tool definitions<br/>[tools.py]"]
  node_llm_client["LLM client<br/>[llm.py]"]
end

subgraph group_ontology_service["Ontology service"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_api_contract["Request schemas<br/>[schemas.py]"]
  node_ontology["Ontology definitions<br/>[ontology.yaml]"]
  node_metadata["Metadata loader<br/>[metadata.py]"]
  node_sql_compiler["SQL compiler<br/>[compiler.py]"]
  node_query_exec["Query execution<br/>[query.py]"]
  node_role_policy["Role policies<br/>[policy.py]"]
  node_action_flow["Action approvals<br/>[actions.py]"]
end

subgraph group_bank_data["Bank data"]
  node_postgres[("PostgreSQL")]
  node_db_schema["Database schema<br/>[schema.sql]"]
  node_mock_data["Mock data generator"]
  node_seed["Data seeding<br/>[seed.py]"]
end

subgraph group_external_systems["External systems"]
  node_openai["OpenAI API"]
end

node_user(("User"))

node_user -->|"asks"| node_demo
node_demo -->|"invokes"| node_agent_loop
node_agent_loop -->|"requests completion"| node_llm_client
node_llm_client -->|"sends tools"| node_tool_defs
node_agent_loop -->|"executes tools"| node_tool_defs
node_llm_client -->|"calls"| node_openai
node_tool_defs -->|"routes requests"| node_api
node_api -->|"validates requests"| node_api_contract
node_api -->|"loads ontology"| node_metadata
node_ontology -->|"defines metadata"| node_metadata
node_api -->|"dispatches queries"| node_query_exec
node_api -->|"dispatches actions"| node_action_flow
node_query_exec -->|"compiles queries"| node_sql_compiler
node_query_exec -->|"checks and masks"| node_role_policy
node_action_flow -->|"compiles target lookup"| node_sql_compiler
node_action_flow -->|"checks roles"| node_role_policy
node_query_exec -->|"executes SQL"| node_postgres
node_action_flow -->|"reads and writes"| node_postgres
node_seed -->|"builds data from"| node_mock_data
node_seed -->|"applies schema"| node_db_schema
node_seed -->|"loads records"| node_postgres
node_api -->|"stores traces"| node_postgres

click node_demo "https://github.com/yumjiin/bank-ontology-layer/blob/main/app/streamlit_app.py"
click node_agent_loop "https://github.com/yumjiin/bank-ontology-layer/blob/main/agent/loop.py"
click node_tool_defs "https://github.com/yumjiin/bank-ontology-layer/blob/main/agent/tools.py"
click node_llm_client "https://github.com/yumjiin/bank-ontology-layer/blob/main/agent/llm.py"
click node_api "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/main.py"
click node_api_contract "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/schemas.py"
click node_ontology "https://github.com/yumjiin/bank-ontology-layer/blob/main/ontology/ontology.yaml"
click node_metadata "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/metadata.py"
click node_sql_compiler "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/compiler.py"
click node_query_exec "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/query.py"
click node_role_policy "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/policy.py"
click node_action_flow "https://github.com/yumjiin/bank-ontology-layer/blob/main/service/actions.py"
click node_db_schema "https://github.com/yumjiin/bank-ontology-layer/blob/main/data/schema.sql"
click node_mock_data "https://github.com/yumjiin/bank-ontology-layer/blob/main/data/reference/generate_mock_data.py"
click node_seed "https://github.com/yumjiin/bank-ontology-layer/blob/main/data/seed.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_demo,node_agent_loop,node_tool_defs,node_llm_client,node_user toneBlue
class node_api,node_api_contract,node_ontology,node_metadata,node_sql_compiler,node_query_exec,node_role_policy,node_action_flow toneAmber
class node_postgres,node_db_schema,node_mock_data,node_seed toneMint
class node_openai toneRose
```

## Components

### Demo and agent

- [Streamlit demo](https://github.com/yumjiin/bank-ontology-layer/blob/main/app/streamlit_app.py): `app/streamlit_app.py`
- [Agent loop](https://github.com/yumjiin/bank-ontology-layer/blob/main/agent/loop.py): `agent/loop.py`
- [Tool definitions](https://github.com/yumjiin/bank-ontology-layer/blob/main/agent/tools.py): `agent/tools.py`
- [LLM client](https://github.com/yumjiin/bank-ontology-layer/blob/main/agent/llm.py): `agent/llm.py`

### Ontology service

- [FastAPI endpoints](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/main.py): `service/main.py`
- [Request schemas](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/schemas.py): `service/schemas.py`
- [Ontology definitions](https://github.com/yumjiin/bank-ontology-layer/blob/main/ontology/ontology.yaml): `ontology/ontology.yaml`
- [Metadata loader](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/metadata.py): `service/metadata.py`
- [SQL compiler](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/compiler.py): `service/compiler.py`
- [Query execution](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/query.py): `service/query.py`
- [Role policies](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/policy.py): `service/policy.py`
- [Action approvals](https://github.com/yumjiin/bank-ontology-layer/blob/main/service/actions.py): `service/actions.py`

### Bank data

- **PostgreSQL**
- [Database schema](https://github.com/yumjiin/bank-ontology-layer/blob/main/data/schema.sql): `data/schema.sql`
- [Mock data generator](https://github.com/yumjiin/bank-ontology-layer/blob/main/data/reference/generate_mock_data.py): `data/reference/generate_mock_data.py`
- [Data seeding](https://github.com/yumjiin/bank-ontology-layer/blob/main/data/seed.py): `data/seed.py`

### External systems

- **OpenAI API**

### Other components

- **User**

## Connections

- User → Streamlit demo: asks (evidence: `README.md`)
- Streamlit demo → Agent loop: invokes (evidence: `app/streamlit_app.py`)
- Agent loop → LLM client: requests completion (evidence: `agent/loop.py`)
- LLM client → Tool definitions: sends tools (evidence: `agent/llm.py`)
- Agent loop → Tool definitions: executes tools (evidence: `agent/loop.py`)
- LLM client → OpenAI API: calls (evidence: `agent/llm.py`)
- Tool definitions → FastAPI endpoints: routes requests (evidence: `agent/tools.py`)
- FastAPI endpoints → Request schemas: validates requests (evidence: `service/main.py`)
- FastAPI endpoints → Metadata loader: loads ontology (evidence: `service/main.py`)
- Ontology definitions → Metadata loader: defines metadata (evidence: `README.md`)
- FastAPI endpoints → Query execution: dispatches queries (evidence: `service/main.py`)
- FastAPI endpoints → Action approvals: dispatches actions (evidence: `service/main.py`)
- Query execution → SQL compiler: compiles queries (evidence: `service/query.py`)
- Query execution → Role policies: checks and masks (evidence: `service/query.py`)
- Action approvals → SQL compiler: compiles target lookup (evidence: `service/actions.py`)
- Action approvals → Role policies: checks roles (evidence: `service/actions.py`)
- Query execution → PostgreSQL: executes SQL (evidence: `service/query.py`)
- Action approvals → PostgreSQL: reads and writes (evidence: `service/actions.py`)
- Data seeding → Mock data generator: builds data from (evidence: `data/seed.py`)
- Data seeding → Database schema: applies schema (evidence: `data/seed.py`)
- Data seeding → PostgreSQL: loads records (evidence: `data/seed.py`)
- FastAPI endpoints → PostgreSQL: stores traces (evidence: `service/main.py`)
