# t-sharabi/tenant-onboarding architecture

> Architecture diagram of the GitHub repository t-sharabi/tenant-onboarding, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/t-sharabi/tenant-onboarding
- Repository: https://github.com/t-sharabi/tenant-onboarding

## Overview

##### Project type and purpose
- This is a small Python-based CLI tool (“Tenant Schema Automation”) for onboarding new tenants in a multi-tenant SaaS platform (e.g., Odoo).
- It exposes two scripts:
- create_tenant.py (creates schema + inserts tenant record)
- create_dns_record.py (optionally registers DNS entries)

##### File structure
- Top level only:
- .env.example – template for environment variables
- README.md – project description
- create_tenant.py – main tenant-creation logic
- create_dns_record.py – DNS API integration
- No web UI or frontend; purely a backend/CLI automation.

##### README for additional insights
- Scripts expect a PostgreSQL database with a “tenant_base.tenants” registry table.
- Environment variables drive DB connectivity.
- The tool logs results to stdout or log file (not shown in tree).
- Intended use: CLI workflows, DevOps/Cloud automation.

##### Main components & interactions (
a. Python CLI Application
- Module A: Tenant Creator (create_tenant.py)
- Module B: DNS Record Creator (create_dns_record.py)
b. External Services
- PostgreSQL Database (single instance, with postgres role)
- DNS Provider API (e.g., AWS Route53, Cloudflare)
c. Configuration
- Environment Variables (.env)

##### Relationships & data flows
- The CLI App reads .env ➔ config loader.
- Tenant Creator module connects to PostgreSQL over TCP, issues DDL (CREATE SCHEMA) and INSERT into tenant registry.
- DNS Record Creator module invokes DNS provider’s REST/SDK to provision a DNS record for the new tenant.
- Optionally, return status/logs back to the operator.

##### Architectural patterns & design principles
- Single responsibility per script (separate concerns: schema vs DNS).
- Externalize config (12-factor style via environment variables).
- Idempotent CLI operations (safe to re-run).
- Logging & error handling (important for automation pipelines).

##### Final checklist
- [ ] Annotation of protocols (TCP:5432, HTTPS) and config sources

## Diagram (Mermaid)

```mermaid
flowchart TD
    README["README.md"]:::doc
    Config[".env Configuration"]:::config
    subgraph "Python CLI Application"
        TenantCreator["Tenant Creator"]:::tenant
        DNSCreator["DNS Record Creator"]:::dns
    end
    DB["PostgreSQL Database"]:::db
    DNSAPI["DNS Provider API"]:::api
    Logs["Stdout / Log File"]:::log

    README --> Config
    Config --> TenantCreator
    Config --> DNSCreator
    TenantCreator -->|"TCP/5432"| DB
    DNSCreator -->|"HTTPS"| DNSAPI
    TenantCreator --> Logs
    DNSCreator --> Logs

    click TenantCreator "https://github.com/t-sharabi/tenant-onboarding/blob/main/create_tenant.py"
    click DNSCreator "https://github.com/t-sharabi/tenant-onboarding/blob/main/create_dns_record.py"
    click Config "https://github.com/t-sharabi/tenant-onboarding/blob/main/.env.example"
    click README "https://github.com/t-sharabi/tenant-onboarding/blob/main/README.md"

    classDef cli fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef tenant fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef dns fill:#F5B041,stroke:#D68910,stroke-width:2px;
    classDef db fill:#D5D8DC,stroke:#85929E,stroke-width:2px;
    classDef api fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef config fill:#D6EAF8,stroke:#2980B9,stroke-width:2px,stroke-dasharray: 5 5;
    classDef doc fill:#E5E7E9,stroke:#5D6D7E,stroke-width:2px,stroke-dasharray: 5 5;
    classDef log fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px,stroke-dasharray: 5 5;

    class TenantCreator,DNSCreator cli
    class TenantCreator tenant
    class DNSCreator dns
```
