= Database Diagram

[mermaid,database,png]
....
erDiagram
    User ||--o{ OrganizationMember : "is member of"
    OrganizationMember {
        string role
    }
    Organization ||--o{ OrganizationMember : has
    Organization }|--|| BillingEntity : "belongs to"
    Organization ||--|| OrganizationOrigin : "has"
    
    BillingEntity {
        string name
        string description
        string erp_reference
    }
    
    OrganizationOrigin {
        string name
        string description
    }
    OrganizationOrigin ||--o{ OrganizationOriginServiceProvider : "can filter"
    ServiceProvider ||--o{ OrganizationOriginServiceProvider : "is filtered by"
    
    Service {
        string name
        string description
        string logo
        json external_links
    }
    
    Service ||--o{ ServiceCategory : "belongs to"
    ServiceCategory {
        string name
        string description
        string logo
    }
    ServiceCategory ||--o| ServiceCategory : "has parent"
    
    ServiceProvider {
        string name
        string description
        string logo
        json external_links
    }
    ServiceProvider ||--o{ ControlPlane : "has"
    
    ControlPlane {
        string name
        string description
        string k8s_api_endpoint
        json api_credentials
    }
    
    ServiceOffering {
        string description
    }
    ServiceOffering ||--|| Service : "offers"
    ServiceOffering ||--|| ServiceProvider : "provided by"
    ServiceOffering ||--o{ ControlPlane : "deployed on"
    
    Plan {
        string name
        string description
        json features
        json pricing
        string term
    }
    
    ServiceOffering ||--o{ ServiceOfferingPlan : "has"
    Plan ||--o{ ServiceOfferingPlan : "included in"
    ServiceOfferingPlan {
        json pricing
    }
....

User and Organization Structure::
Users can be members of multiple organizations, and organizations can have multiple members. This relationship is managed through an OrganizationMember junction table that stores the specific role each user has within each organization. A user's role can differ between organizations.

Organizations::
Each organization is required to have exactly one billing entity and one organization origin. Billing entities, which contain name, description, and ERP reference information, can be shared across multiple organizations. Similarly, organization origins (containing name and description) can be associated with multiple organizations.

Organization Origins and Service Providers::
Organization origins can be linked to service providers through a filtering mechanism. This relationship allows controlling which service offerings are available to organizations based on their origin.

Services and Categories::
Services are defined with basic information (name, description, logo) and external links. Each service can belong to multiple service categories. Service categories themselves can be nested, meaning a category can have a parent category, enabling a hierarchical categorization structure. Categories include name, description, and logo attributes.

Service Providers and Control Planes::
Service providers are entities with name, description, logo, and external links. Each service provider can operate zero or more control planes. A control plane belongs to exactly one service provider and contains configuration details including name, description, Kubernetes API endpoint, and API credentials.

Service Offerings and Plans::
Service offerings connect services with service providers. Each service offering:

* Must be associated with exactly one service and one service provider
* Can be deployed on multiple control planes
* Includes multiple plans with customized pricing

Plans are reusable across different service offerings and include:

* Basic information (name, description)
* Feature specifications
* Multi-currency pricing options
* Term details

The relationship between service offerings and plans is managed through a ServiceOfferingPlan junction table, which allows the same plan to have different pricing depending on the specific service offering.
