{
  "repo": "tidbcloud/dataservices",
  "binary": "dataapi",
  "binary_path": "cmd/dataapi/main.go",
  "dependencies": {
    "DataAPILifecycle.LoadConfigAndDatabase": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "READ FILE",
              "trigger": "Load the global config before logger and DB initialization",
              "conditions": [
                "Always"
              ],
              "implementation": "config.InitConfig(configPath)"
            }
          ]
        },
        "mysql": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Create the shared SQL connection used by eventbus and central helpers",
              "conditions": [
                "Always"
              ],
              "implementation": "database.Connect(ctx, ...)"
            }
          ]
        }
      },
      "services": []
    },
    "DataAPILifecycle.StartEventbus": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when local mode is disabled"
          ],
          "operations": [
            {
              "operation": "SUBSCRIBE / RUN LOOP",
              "trigger": "Run the dataservice_dataapi eventbus consumer",
              "conditions": [
                "!config.IsLocalMode()"
              ],
              "implementation": "eventbusStartup -> eventbus.Init(\"dataservice_dataapi\", db); bus.Run()"
            }
          ]
        }
      },
      "services": []
    },
    "DataAPILifecycle.InitApikeyEncrypter": {
      "infrastructure": {},
      "services": []
    },
    "DataAPILifecycle.InitRuntimeDependencies": {
      "infrastructure": {
        "dynamodb": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Initialize DynamoDB-backed dataapp metadata used by central helper code",
              "conditions": [
                "Always"
              ],
              "implementation": "ddb.Init(ctx, config)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "infra-api / gardener discovery",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "dbhubsdk.InitSdk",
          "operation_type": "sdk_init",
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "INITIALIZE SDK",
              "trigger": "Prepare DBHub helpers used later for account and metadata resolution",
              "conditions": [
                "Always"
              ],
              "implementation": "dbhubsdk.InitSdk(config.DBHubSdkConf.KubeConfigPath, config.DBHubSdkConf.GardenerProjectName, config.DBHubSdkConf.InfraAPIConfigPath)"
            }
          ]
        }
      ]
    },
    "DataAPILifecycle.StartTracing": {
      "infrastructure": {},
      "services": []
    },
    "DataAPILifecycle.StartMetricsServer": {
      "infrastructure": {},
      "services": []
    },
    "DataAPILifecycle.StartGrpcServer": {
      "infrastructure": {
        "tcp": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "LISTEN",
              "trigger": "Expose the DataAPIService gRPC server",
              "conditions": [
                "Always"
              ],
              "implementation": "startupGRPC -> net.Listen(\"tcp\", \":\"+GrpcPort); grpcServer.Serve(listen)"
            }
          ]
        }
      },
      "services": []
    },
    "HTTP GET /metrics": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.GetClusterMeta": {
      "infrastructure": {},
      "services": [
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetClusterWithoutPermCheck",
          "operation_type": "grpc_unary",
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER",
              "trigger": "Resolve cluster region and provider before forwarding the metadata query",
              "conditions": [
                "Always"
              ],
              "implementation": "service.GetClusterMeta -> ExecSql -> grpc.GetClusterWithoutPermCheck(ctx, in.ClusterId)"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/exec/sql",
          "operation_type": "http_post",
          "conditions": [
            "Only after cluster lookup and credential derivation succeed"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Execute the INFORMATION_SCHEMA query in the regional data path",
              "conditions": [
                "ExecSql(...) reached http.ExecSqlWithProvider"
              ],
              "implementation": "service.GetClusterMeta -> ExecSql -> http.ExecSqlWithProvider(ctx, clusterInfo.RegionName, providerPrefix, req)"
            }
          ]
        }
      ]
    },
    "DataAPIService.GetDatabaseMeta": {
      "infrastructure": {},
      "services": [
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetClusterWithoutPermCheck",
          "operation_type": "grpc_unary",
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER",
              "trigger": "Resolve cluster region and provider before forwarding the metadata query",
              "conditions": [
                "Always"
              ],
              "implementation": "service.GetDatabaseMeta -> ExecSql -> grpc.GetClusterWithoutPermCheck(ctx, in.ClusterId)"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/exec/sql",
          "operation_type": "http_post",
          "conditions": [
            "Only after cluster lookup and credential derivation succeed"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Execute the INFORMATION_SCHEMA query in the regional data path",
              "conditions": [
                "ExecSql(...) reached http.ExecSqlWithProvider"
              ],
              "implementation": "service.GetDatabaseMeta -> ExecSql -> http.ExecSqlWithProvider(ctx, clusterInfo.RegionName, providerPrefix, req)"
            }
          ]
        }
      ]
    },
    "DataAPIService.ExecSqlWithSession": {
      "infrastructure": {},
      "services": [
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetClusterWithoutPermCheck",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when ProjectId/ClusterId or SessionId validation passes"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER",
              "trigger": "Resolve cluster region and provider before forwarding the SQL request",
              "conditions": [
                "in.ProjectId and in.ClusterId are valid or SessionId already carries target cluster context"
              ],
              "implementation": "service.ExecSql -> grpc.GetClusterWithoutPermCheck(ctx, in.ClusterId)"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/exec/sql",
          "operation_type": "http_post",
          "conditions": [
            "Only after cluster lookup and credential derivation succeed"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Execute the SQL through the regional gateway",
              "conditions": [
                "service.ExecSql built dto.ExecSqlReq successfully"
              ],
              "implementation": "service.ExecSql -> http.ExecSqlWithProvider(ctx, clusterInfo.RegionName, providerPrefix, req)"
            }
          ]
        }
      ]
    },
    "DataAPIService.ExecSqlDirectly": {
      "infrastructure": {},
      "services": [
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetClusterWithoutPermCheck",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when ProjectId and ClusterId validation passes"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER",
              "trigger": "Resolve cluster region and provider before forwarding the SQL request",
              "conditions": [
                "in.ProjectId != 0 and in.ClusterId != 0"
              ],
              "implementation": "service.ExecSql -> grpc.GetClusterWithoutPermCheck(ctx, in.ClusterId)"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/exec/sql",
          "operation_type": "http_post",
          "conditions": [
            "Only after cluster lookup and credential derivation succeed"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Execute the SQL through the regional gateway",
              "conditions": [
                "service.ExecSql built dto.ExecSqlReq successfully"
              ],
              "implementation": "service.ExecSql -> http.ExecSqlWithProvider(ctx, clusterInfo.RegionName, providerPrefix, req)"
            }
          ]
        }
      ]
    },
    "DataAPIService.CreateSession": {
      "infrastructure": {},
      "services": [
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetClusterWithoutPermCheck",
          "operation_type": "grpc_unary",
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER",
              "trigger": "Resolve cluster region and provider before creating a regional SQL session",
              "conditions": [
                "Always"
              ],
              "implementation": "service.CreateSession -> grpc.GetClusterWithoutPermCheck(ctx, in.ClusterId)"
            }
          ]
        },
        {
          "name": "account-service",
          "target_repo": "tidbcloud/account",
          "target_interface": "GetUserByToken",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when Credential.Type is AUTH0 and AccountId is empty"
          ],
          "operations": [
            {
              "operation": "RESOLVE USER",
              "trigger": "Fill the missing account email before forwarding the session request",
              "conditions": [
                "in.Credential != nil",
                "in.Credential.Type == AUTH0",
                "in.Credential.AccountId == \"\""
              ],
              "implementation": "service.CreateSession -> grpc.GetUserByToken(ctx, &account.GetUserByTokenRequest{Token: req.Credential.Key})"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/session/create",
          "operation_type": "http_post",
          "conditions": [
            "Only after cluster lookup and optional user lookup succeed"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Create the regional SQL session",
              "conditions": [
                "dto.CreateSessionReq built successfully"
              ],
              "implementation": "service.CreateSession -> http.CreateSessionWithProvider(ctx, clusterInfo.RegionName, providerPrefix, req)"
            }
          ]
        }
      ]
    },
    "DataAPIService.CloseSession": {
      "infrastructure": {},
      "services": [
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetClusterWithoutPermCheck",
          "operation_type": "grpc_unary",
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER",
              "trigger": "Resolve cluster region and provider before closing the regional SQL session",
              "conditions": [
                "Always"
              ],
              "implementation": "service.CloseSession -> grpc.GetClusterWithoutPermCheck(ctx, in.ClusterId)"
            }
          ]
        },
        {
          "name": "account-service",
          "target_repo": "tidbcloud/account",
          "target_interface": "GetUserByToken",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when Credential.Type is AUTH0 and AccountId is empty"
          ],
          "operations": [
            {
              "operation": "RESOLVE USER",
              "trigger": "Fill the missing account email before forwarding the close-session request",
              "conditions": [
                "in.Credential != nil",
                "in.Credential.Type == AUTH0",
                "in.Credential.AccountId == \"\""
              ],
              "implementation": "service.CloseSession -> grpc.GetUserByToken(ctx, &account.GetUserByTokenRequest{Token: req.Credential.Key})"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/session/close",
          "operation_type": "http_post",
          "conditions": [
            "Only after cluster lookup and optional user lookup succeed"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Close the regional SQL session",
              "conditions": [
                "dto.CloseSessionReq built successfully"
              ],
              "implementation": "service.CloseSession -> http.CloseSessionWithProvider(ctx, clusterInfo.RegionName, providerPrefix, req)"
            }
          ]
        }
      ]
    },
    "DataAPIService.CreateAPIKey": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.DeleteAPIKey": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.ListAPIKey": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.AuthAPIKey": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.CreateDataApp": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.ShowDataApp": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.ListDataApp": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.DeleteDataApp": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.ShowAPIKey": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.ParseOneStmt": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.EndpointCodeExample": {
      "infrastructure": {},
      "services": []
    },
    "DataAPIService.GetClusterStatus": {
      "infrastructure": {},
      "services": []
    }
  }
}
