MATIH Platform is in active MVP development. Documentation reflects current implementation status.
8. Platform Services
Provisioning

Provisioning

The TenantInfrastructureService and InfrastructureController manage the complete lifecycle of tenant infrastructure. Provisioning creates isolated namespaces, databases, storage, and service deployments for each tenant. The process follows a state machine pattern with transitions tracked in the InfrastructureStateTransition table.


Provisioning Flow

PhaseDescription
1. RequestProvision request received with tenant ID and configuration
2. PlanTerraform plan generated for the tenant's infrastructure
3. ApplyTerraform applies the infrastructure changes
4. DeployServices are deployed into the tenant namespace
5. ConfigureIngress, DNS, and service mesh configured
6. VerifyHealth checks validate the deployment
7. CompleteInfrastructure marked as ready

Provision Tenant Infrastructure

Endpoint: POST /api/v1/infrastructure/tenants/:tenantId/provision

curl -X POST http://localhost:8089/api/v1/infrastructure/tenants/550e8400/provision \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "tier": "professional",
    "region": "eastus",
    "cloudProvider": "AZURE",
    "configuration": {
      "databaseSize": "Standard_D2s_v3",
      "storageGb": 100,
      "enableHa": false
    }
  }'

Infrastructure State

Endpoint: GET /api/v1/infrastructure/tenants/:tenantId

Returns the current infrastructure state for a tenant.

TenantInfrastructure Entity

FieldTypeDescription
idUUIDInfrastructure record ID
tenantIdUUIDOwning tenant
statusStringCurrent status (PROVISIONING, ACTIVE, UPDATING, etc.)
cloudProviderStringCloud provider (AZURE, AWS, GCP)
regionStringDeployment region
namespaceStringKubernetes namespace
configurationJSONInfrastructure configuration
terraformStateKeyStringTerraform state backend key

Update Infrastructure

Endpoint: PUT /api/v1/infrastructure/tenants/:tenantId

Updates the tenant infrastructure configuration (e.g., scaling, adding resources).


Deprovision

Endpoint: DELETE /api/v1/infrastructure/tenants/:tenantId

Initiates infrastructure teardown for a tenant. This is an irreversible operation that removes all tenant resources.


State Transitions

The InfrastructureStateTransition entity tracks every state change for audit and debugging:

FieldTypeDescription
idUUIDTransition ID
tenantIdUUIDTenant
fromStateStringPrevious state
toStateStringNew state
triggerStringWhat triggered the transition
detailsJSONAdditional context
timestampInstantWhen the transition occurred

Desired State Reconciliation

The DesiredInfrastructureState entity and InfrastructureReconciler implement a Kubernetes-style reconciliation pattern. The desired state is declared, and the reconciler continuously works to match the actual state to the desired state.

The reconciler publishes events via ReconciliationEventPublisher for observability of reconciliation progress.