# m7mmad-omar/sbarbase architecture

> Architecture diagram of the GitHub repository m7mmad-omar/sbarbase, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m7mmad-omar/sbarbase
- Repository: https://github.com/m7mmad-omar/sbarbase

## Overview

Sbarbase is a self-hosted control plane and gateway for running isolated Supabase projects and environments on one server. Operators and project users manage organizations, projects, credentials, and environment settings through the console; client requests then pass through placement-aware routing to the appropriate upstream services. The README also describes shared-resource admission, workload notifications, and backup/restore capabilities. The source excerpts show the control/gateway wiring and parts of the local runtime; several operational subsystems are represented from documented capabilities and the file tree, not inspected implementations.

Main entry points: [`src/control/handler.ts`](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/handler.ts) (Management routes), [`src/gateway/managed.ts`](https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/managed.ts) (Managed routing), [`src/control/application.ts`](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/application.ts) (HTTP application), [`src/gateway/handler.ts`](https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/handler.ts) (Service gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_console["Management console"]
  node_console_ui["Console UI<br/>[App.tsx]"]
  node_console_api["Console API client<br/>[api.ts]"]
end

subgraph group_control["Control plane"]
  node_catalog[("Project catalog<br/>[catalog.ts]")]
  node_management_auth["Management identity<br/>[auth.ts]"]
  node_control_routes["Management routes<br/>[handler.ts]"]
  node_placement["Runtime placement<br/>[placement.ts]"]
  node_keys["Project keys<br/>[keys.ts]"]
  node_invites["Invitations<br/>[invitations.ts]"]
  node_database_access["Database access<br/>[database.ts]"]
  node_observability["Usage and logs<br/>[observe.ts]"]
end

subgraph group_gateway["Client gateway"]
  node_application["HTTP application<br/>[application.ts]"]
  node_managed_router["Managed routing<br/>[managed.ts]"]
  node_gateway_handler["Service gateway<br/>[handler.ts]"]
  node_concurrency["Concurrency control<br/>[concurrency.ts]"]
end

subgraph group_runtime["Local runtime"]
  node_upstream_services["Supabase services"]
  node_runtime_manager["Local runtime manager<br/>[durable_runtime.py]"]
  node_resource_policy["Resource admission<br/>[resource_policy.py]"]
  node_runtime_lab["Component runtime<br/>[run.py]"]
end

subgraph group_operations["Recovery and operations"]
  node_backup_restore["Backup and restore<br/>[recovery_bundle.py]"]
  node_storage_recovery["Storage recovery"]
  node_notifications["Workload notifications"]
end

node_operator(("Operator"))
node_client(("Project client"))

node_operator -->|"manages projects"| node_console_ui
node_client -->|"sends requests"| node_application
node_console_ui -->|"uses API"| node_console_api
node_console_api -.->|"calls management"| node_control_routes
node_application -->|"routes management"| node_control_routes
node_application -->|"routes client traffic"| node_managed_router
node_application -->|"creates gateway"| node_gateway_handler
node_control_routes -->|"reads and updates"| node_catalog
node_control_routes -->|"dispatches credentials"| node_keys
node_control_routes -->|"dispatches invitations"| node_invites
node_control_routes -->|"dispatches database access"| node_database_access
node_control_routes -->|"dispatches metrics"| node_observability
node_management_auth -.->|"authenticates management"| node_catalog
node_managed_router -->|"reads routing state"| node_catalog
node_managed_router -->|"resolves placement"| node_placement
node_managed_router -->|"loads project keys"| node_keys
node_managed_router -->|"dispatches requests"| node_gateway_handler
node_gateway_handler -->|"checks concurrency"| node_concurrency
node_gateway_handler -->|"forwards service traffic"| node_upstream_services
node_runtime_manager -->|"checks capacity"| node_resource_policy
node_runtime_lab -.->|"starts local services"| node_upstream_services
node_operator -.->|"initiates recovery"| node_backup_restore
node_backup_restore -->|"restores storage"| node_storage_recovery
node_runtime_manager -.->|"produces alerts"| node_notifications
node_resource_policy -.->|"signals overload"| node_notifications

click node_console_ui "https://github.com/m7mmad-omar/sbarbase/blob/main/ui/App.tsx"
click node_console_api "https://github.com/m7mmad-omar/sbarbase/blob/main/ui/api.ts"
click node_catalog "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/catalog.ts"
click node_management_auth "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/auth.ts"
click node_control_routes "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/handler.ts"
click node_placement "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/placement.ts"
click node_keys "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/keys.ts"
click node_invites "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/invitations.ts"
click node_database_access "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/database.ts"
click node_observability "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/observe.ts"
click node_application "https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/application.ts"
click node_managed_router "https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/managed.ts"
click node_gateway_handler "https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/handler.ts"
click node_concurrency "https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/concurrency.ts"
click node_runtime_manager "https://github.com/m7mmad-omar/sbarbase/blob/main/lab/durable_runtime.py"
click node_resource_policy "https://github.com/m7mmad-omar/sbarbase/blob/main/lab/resource_policy.py"
click node_runtime_lab "https://github.com/m7mmad-omar/sbarbase/blob/main/lab/run.py"
click node_backup_restore "https://github.com/m7mmad-omar/sbarbase/blob/main/lab/recovery_bundle.py"
click node_storage_recovery "https://github.com/m7mmad-omar/sbarbase/blob/main/lab/recovery-check-storage.py"
click node_notifications "https://github.com/m7mmad-omar/sbarbase/blob/main/lab/notification_producers.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_console_ui,node_console_api,node_client toneBlue
class node_catalog,node_management_auth,node_control_routes,node_placement,node_keys,node_invites,node_database_access,node_observability toneAmber
class node_application,node_managed_router,node_gateway_handler,node_concurrency toneMint
class node_upstream_services,node_runtime_manager,node_resource_policy,node_runtime_lab toneRose
class node_backup_restore,node_storage_recovery,node_notifications,node_operator toneIndigo
```

## Components

### Management console

- [Console UI](https://github.com/m7mmad-omar/sbarbase/blob/main/ui/App.tsx): `ui/App.tsx`
- [Console API client](https://github.com/m7mmad-omar/sbarbase/blob/main/ui/api.ts): `ui/api.ts`

### Control plane

- [Project catalog](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/catalog.ts): `src/control/catalog.ts`
- [Management identity](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/auth.ts): `src/control/auth.ts`
- [Management routes](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/handler.ts): `src/control/handler.ts`
- [Runtime placement](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/placement.ts): `src/control/placement.ts`
- [Project keys](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/keys.ts): `src/control/keys.ts`
- [Invitations](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/invitations.ts): `src/control/invitations.ts`
- [Database access](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/database.ts): `src/control/database.ts`
- [Usage and logs](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/observe.ts): `src/control/observe.ts`

### Client gateway

- [HTTP application](https://github.com/m7mmad-omar/sbarbase/blob/main/src/control/application.ts): `src/control/application.ts`
- [Managed routing](https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/managed.ts): `src/gateway/managed.ts`
- [Service gateway](https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/handler.ts): `src/gateway/handler.ts`
- [Concurrency control](https://github.com/m7mmad-omar/sbarbase/blob/main/src/gateway/concurrency.ts): `src/gateway/concurrency.ts`

### Local runtime

- **Supabase services**
- [Local runtime manager](https://github.com/m7mmad-omar/sbarbase/blob/main/lab/durable_runtime.py): `lab/durable_runtime.py`
- [Resource admission](https://github.com/m7mmad-omar/sbarbase/blob/main/lab/resource_policy.py): `lab/resource_policy.py`
- [Component runtime](https://github.com/m7mmad-omar/sbarbase/blob/main/lab/run.py): `lab/run.py`

### Recovery and operations

- [Backup and restore](https://github.com/m7mmad-omar/sbarbase/blob/main/lab/recovery_bundle.py): `lab/recovery_bundle.py`
- [Storage recovery](https://github.com/m7mmad-omar/sbarbase/blob/main/lab/recovery-check-storage.py): `lab/recovery-check-storage.py`
- [Workload notifications](https://github.com/m7mmad-omar/sbarbase/blob/main/lab/notification_producers.py): `lab/notification_producers.py`

### Other components

- **Operator**
- **Project client**

## Connections

- Operator → Console UI: manages projects (evidence: `README.md`)
- Project client → HTTP application: sends requests (evidence: `src/control/application.ts`)
- Console UI → Console API client: uses API (evidence: `ui/App.tsx`)
- Console API client → Management routes: calls management
- HTTP application → Management routes: routes management (evidence: `src/control/application.ts`)
- HTTP application → Managed routing: routes client traffic (evidence: `src/control/application.ts`)
- HTTP application → Service gateway: creates gateway (evidence: `src/control/application.ts`)
- Management routes → Project catalog: reads and updates (evidence: `src/control/handler.ts`)
- Management routes → Project keys: dispatches credentials (evidence: `src/control/handler.ts`)
- Management routes → Invitations: dispatches invitations (evidence: `src/control/handler.ts`)
- Management routes → Database access: dispatches database access (evidence: `src/control/handler.ts`)
- Management routes → Usage and logs: dispatches metrics (evidence: `src/control/handler.ts`)
- Management identity → Project catalog: authenticates management
- Managed routing → Project catalog: reads routing state (evidence: `src/gateway/managed.ts`)
- Managed routing → Runtime placement: resolves placement (evidence: `src/gateway/managed.ts`)
- Managed routing → Project keys: loads project keys (evidence: `src/gateway/managed.ts`)
- Managed routing → Service gateway: dispatches requests (evidence: `src/gateway/managed.ts`)
- Service gateway → Concurrency control: checks concurrency (evidence: `src/gateway/handler.ts`)
- Service gateway → Supabase services: forwards service traffic (evidence: `README.md`)
- Local runtime manager → Resource admission: checks capacity (evidence: `lab/durable_runtime.py`)
- Component runtime → Supabase services: starts local services
- Operator → Backup and restore: initiates recovery
- Backup and restore → Storage recovery: restores storage (evidence: `lab/recovery-check-storage.py`)
- Local runtime manager → Workload notifications: produces alerts
- Resource admission → Workload notifications: signals overload
