# adiwidia-dev/crucible-db architecture

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

- Interactive diagram: https://gitdiagram.com/adiwidia-dev/crucible-db
- Repository: https://github.com/adiwidia-dev/crucible-db

## Overview

Crucible DB is a governed database-access control plane: engineers submit deployment batches or time-bounded Query Access requests, which are governed by role policy and review, then executed or exposed through a controlled native-client tunnel. The README documents the product workflow and major capabilities; sampled source and the SOURCE INDEX support selected execution and proxy links. Many feature modules are unsampled, so their internal call relationships are not asserted.

Main entry points: [`app/Http/Controllers/QueryRequestController.php`](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/QueryRequestController.php) (Request handling), [`app/Services/QuerySessionWorkflow.php`](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QuerySessionWorkflow.php) (Session workflow), [`app/Jobs/ExecuteQueryRequest.php`](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Jobs/ExecuteQueryRequest.php) (Batch execution job), [`app/Jobs/ExecuteQuerySessionQuery.php`](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Jobs/ExecuteQuerySessionQuery.php) (Session query execution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Request workflow"]
  node_request_ui["Request workspace"]
  node_request_controller["Request handling"]
  node_request_workflow["Request policy workflow"]
  node_review["Review decisions"]
  node_queue["Redis query queue"]
  node_request_job["Batch execution job"]
  node_preflight["Preflight checks"]
  node_executor["Database executor"]
  node_target_db[("Target databases")]
end

subgraph group_access["Query access"]
  node_query_sessions["Session workflow"]
  node_session_ui["Session workspace"]
  node_session_query["Session query execution"]
  node_result_store[("Result snapshots")]
end

subgraph group_native["Native client proxy"]
  node_cli["Crucible CLI"]
  node_gateway["Embedded gateway<br/>[server.go]"]
  node_proxy["Private proxy<br/>[server.go]"]
  node_protocol_servers["SQL protocol listeners"]
  node_tunnel["Tunnel bridge"]
  node_native_api["Native access API"]
end

subgraph group_governance["Governance and operations"]
  node_role_policy["Role-scoped access<br/>[User.php]"]
  node_sql_policy["SQL policy"]
  node_audit[("Audit trail<br/>[AuditLogger.php]")]
  node_notifications["Notifications"]
end

subgraph group_identity["Identity and setup"]
  node_auth["Authentication"]
  node_setup["Initial setup"]
  node_app_db[("Application database")]
end

node_engineer(("Engineer"))
node_reviewer(("Reviewer"))
node_scheduler(("Scheduler"))

node_engineer -->|"submits batch"| node_request_ui
node_request_ui -.->|"sends request"| node_request_controller
node_request_controller -.->|"manages requests"| node_request_workflow
node_request_controller -.->|"requests review"| node_review
node_reviewer -->|"reviews batch"| node_review
node_request_controller -->|"dispatches approved"| node_queue
node_review -->|"dispatches approved"| node_queue
node_scheduler -->|"dispatches due"| node_queue
node_queue -.->|"runs job"| node_request_job
node_request_job -->|"checks freshness"| node_preflight
node_request_job -->|"executes SQL"| node_executor
node_executor -->|"runs statements"| node_target_db
node_request_job -->|"records activity"| node_audit
node_engineer -->|"requests session"| node_session_ui
node_session_ui -.->|"manages session"| node_query_sessions
node_query_sessions -.->|"executes query"| node_session_query
node_session_query -.->|"runs query"| node_executor
node_session_query -.->|"stores results"| node_result_store
node_scheduler -->|"expires sessions"| node_query_sessions
node_cli -->|"opens tunnel"| node_gateway
node_gateway -->|"bridges traffic"| node_tunnel
node_proxy -.->|"serves protocols"| node_protocol_servers
node_protocol_servers -.->|"forwards statements"| node_tunnel
node_native_api -.->|"authorizes access"| node_proxy
node_query_sessions -->|"issues session access"| node_native_api
node_protocol_servers -->|"connects privately"| node_target_db
node_request_controller -.->|"checks permissions"| node_role_policy
node_request_job -.->|"evaluates policy"| node_sql_policy
node_query_sessions -->|"enforces scope"| node_role_policy
node_query_sessions -->|"checks statements"| node_sql_policy
node_request_controller -.->|"notifies users"| node_notifications
node_auth -.->|"authenticates"| node_engineer
node_setup -.->|"configures storage"| node_app_db

click node_request_ui "https://github.com/adiwidia-dev/crucible-db/tree/main/resources/js/pages/query-requests"
click node_request_controller "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/QueryRequestController.php"
click node_request_workflow "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QueryRequestWorkflow.php"
click node_review "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/QueryReviewController.php"
click node_request_job "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Jobs/ExecuteQueryRequest.php"
click node_preflight "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/DeploymentPreflight.php"
click node_executor "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/DatabaseQueryExecutor.php"
click node_query_sessions "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QuerySessionWorkflow.php"
click node_session_ui "https://github.com/adiwidia-dev/crucible-db/tree/main/resources/js/pages/query-sessions"
click node_session_query "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Jobs/ExecuteQuerySessionQuery.php"
click node_result_store "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QueryResultSnapshotStore.php"
click node_cli "https://github.com/adiwidia-dev/crucible-db/tree/main/native/internal/cli"
click node_gateway "https://github.com/adiwidia-dev/crucible-db/blob/main/native/internal/gateway/server.go"
click node_proxy "https://github.com/adiwidia-dev/crucible-db/blob/main/native/internal/proxy/server.go"
click node_protocol_servers "https://github.com/adiwidia-dev/crucible-db/tree/main/native/internal/mysql"
click node_tunnel "https://github.com/adiwidia-dev/crucible-db/tree/main/native/internal/tunnel"
click node_native_api "https://github.com/adiwidia-dev/crucible-db/tree/main/app/Http/Controllers/NativeProxy"
click node_role_policy "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Models/User.php"
click node_sql_policy "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/SqlPolicyManager.php"
click node_audit "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/AuditLogger.php"
click node_notifications "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/NotificationDispatcher.php"
click node_auth "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/AuthProviderController.php"
click node_setup "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/SetupController.php"
click node_app_db "https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/ApplicationDatabaseManager.php"

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_request_ui,node_request_controller,node_request_workflow,node_review,node_queue,node_request_job,node_preflight,node_executor,node_target_db,node_reviewer toneBlue
class node_query_sessions,node_session_ui,node_session_query,node_result_store toneAmber
class node_cli,node_gateway,node_proxy,node_protocol_servers,node_tunnel,node_native_api toneMint
class node_role_policy,node_sql_policy,node_audit,node_notifications,node_scheduler toneRose
class node_auth,node_setup,node_app_db,node_engineer toneIndigo
```

## Components

### Request workflow

- [Request workspace](https://github.com/adiwidia-dev/crucible-db/tree/main/resources/js/pages/query-requests): `resources/js/pages/query-requests`
- [Request handling](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/QueryRequestController.php): `app/Http/Controllers/QueryRequestController.php`
- [Request policy workflow](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QueryRequestWorkflow.php): `app/Services/QueryRequestWorkflow.php`
- [Review decisions](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/QueryReviewController.php): `app/Http/Controllers/QueryReviewController.php`
- **Redis query queue**
- [Batch execution job](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Jobs/ExecuteQueryRequest.php): `app/Jobs/ExecuteQueryRequest.php`
- [Preflight checks](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/DeploymentPreflight.php): `app/Services/DeploymentPreflight.php`
- [Database executor](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/DatabaseQueryExecutor.php): `app/Services/DatabaseQueryExecutor.php`
- **Target databases**

### Query access

- [Session workflow](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QuerySessionWorkflow.php): `app/Services/QuerySessionWorkflow.php`
- [Session workspace](https://github.com/adiwidia-dev/crucible-db/tree/main/resources/js/pages/query-sessions): `resources/js/pages/query-sessions`
- [Session query execution](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Jobs/ExecuteQuerySessionQuery.php): `app/Jobs/ExecuteQuerySessionQuery.php`
- [Result snapshots](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/QueryResultSnapshotStore.php): `app/Services/QueryResultSnapshotStore.php`

### Native client proxy

- [Crucible CLI](https://github.com/adiwidia-dev/crucible-db/tree/main/native/internal/cli): `native/internal/cli`
- [Embedded gateway](https://github.com/adiwidia-dev/crucible-db/blob/main/native/internal/gateway/server.go): `native/internal/gateway/server.go`
- [Private proxy](https://github.com/adiwidia-dev/crucible-db/blob/main/native/internal/proxy/server.go): `native/internal/proxy/server.go`
- [SQL protocol listeners](https://github.com/adiwidia-dev/crucible-db/tree/main/native/internal/mysql): `native/internal/mysql`
- [Tunnel bridge](https://github.com/adiwidia-dev/crucible-db/tree/main/native/internal/tunnel): `native/internal/tunnel`
- [Native access API](https://github.com/adiwidia-dev/crucible-db/tree/main/app/Http/Controllers/NativeProxy): `app/Http/Controllers/NativeProxy`

### Governance and operations

- [Role-scoped access](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Models/User.php): `app/Models/User.php`
- [SQL policy](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/SqlPolicyManager.php): `app/Services/SqlPolicyManager.php`
- [Audit trail](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/AuditLogger.php): `app/Services/AuditLogger.php`
- [Notifications](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/NotificationDispatcher.php): `app/Services/NotificationDispatcher.php`

### Identity and setup

- [Authentication](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/AuthProviderController.php): `app/Http/Controllers/AuthProviderController.php`
- [Initial setup](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Http/Controllers/SetupController.php): `app/Http/Controllers/SetupController.php`
- [Application database](https://github.com/adiwidia-dev/crucible-db/blob/main/app/Services/ApplicationDatabaseManager.php): `app/Services/ApplicationDatabaseManager.php`

### Other components

- **Engineer**
- **Reviewer**
- **Scheduler**

## Connections

- Engineer → Request workspace: submits batch
- Request workspace → Request handling: sends request
- Request handling → Request policy workflow: manages requests (evidence: `app/Http/Controllers/QueryRequestController.php`)
- Request handling → Review decisions: requests review
- Reviewer → Review decisions: reviews batch
- Request handling → Redis query queue: dispatches approved
- Review decisions → Redis query queue: dispatches approved
- Scheduler → Redis query queue: dispatches due
- Redis query queue → Batch execution job: runs job
- Batch execution job → Preflight checks: checks freshness (evidence: `app/Jobs/ExecuteQueryRequest.php`)
- Batch execution job → Database executor: executes SQL (evidence: `app/Jobs/ExecuteQueryRequest.php`)
- Database executor → Target databases: runs statements
- Batch execution job → Audit trail: records activity (evidence: `app/Jobs/ExecuteQueryRequest.php`)
- Engineer → Session workspace: requests session
- Session workspace → Session workflow: manages session
- Session workflow → Session query execution: executes query (evidence: `app/Services/QuerySessionWorkflow.php`)
- Session query execution → Database executor: runs query
- Session query execution → Result snapshots: stores results
- Scheduler → Session workflow: expires sessions
- Crucible CLI → Embedded gateway: opens tunnel
- Embedded gateway → Tunnel bridge: bridges traffic (evidence: `native/internal/gateway/server.go`)
- Private proxy → SQL protocol listeners: serves protocols
- SQL protocol listeners → Tunnel bridge: forwards statements
- Native access API → Private proxy: authorizes access
- Session workflow → Native access API: issues session access
- SQL protocol listeners → Target databases: connects privately
- Request handling → Role-scoped access: checks permissions (evidence: `app/Http/Controllers/QueryRequestController.php`)
- Batch execution job → SQL policy: evaluates policy
- Session workflow → Role-scoped access: enforces scope (evidence: `app/Services/QuerySessionWorkflow.php`)
- Session workflow → SQL policy: checks statements
- Request handling → Notifications: notifies users
- Authentication → Engineer: authenticates
- Initial setup → Application database: configures storage
