@startuml
title "Application"
left to right direction
package "AppFlowy Application" {
  [User]
}

cloud "Supabase Server" {
  [RESTful Component]
  [Realtime Component]
  [Postgres DB]
}

database "LocalServer" {
  [Local Server Component]
}


cloud "AppFlowy Cloud Server" {
  [RESTful Component] as [AppFlowy RESTful Component]
  [Realtime Component] as [AppFlowy Realtime Component]
  [Postgres DB] as [AppFlowy Postgres DB]
}

User --> [AppFlowy Application]
[AppFlowy Application] --> [Local Server Component] : Connect

[AppFlowy Application] --> [RESTful Component] : RESTful API Communication
[AppFlowy Application] <..> [Realtime Component] : WebSocket Communication

[AppFlowy Application] --> [AppFlowy RESTful Component] : RESTful API Communication
[AppFlowy Application] <..> [AppFlowy Realtime Component] : WebSocket Communication

@enduml


@startuml
left to right direction

interface AppFlowyServer {
  + enable_sync(_enable: bool)
  + user_service(): Arc<dyn UserService>
  + folder_service(): Arc<dyn FolderCloudService>
  + database_service(): Arc<dyn DatabaseCloudService>
  + document_service(): Arc<dyn DocumentCloudService>
  + collab_storage(): Option<Arc<dyn RemoteCollabStorage>>
}

class SupabaseServer {
  + enable_sync(_enable: bool)
  + user_service(): Arc<dyn UserService>
  + folder_service(): Arc<dyn FolderCloudService>
  + database_service(): Arc<dyn DatabaseCloudService>
  + document_service(): Arc<dyn DocumentCloudService>
  + collab_storage(): Option<Arc<dyn RemoteCollabStorage>>
}

class SelfHostServer {
  + user_service(): Arc<dyn UserService>
  + folder_service(): Arc<dyn FolderCloudService>
  + database_service(): Arc<dyn DatabaseCloudService>
  + document_service(): Arc<dyn DocumentCloudService>
  + collab_storage(): Option<Arc<dyn RemoteCollabStorage>>
}

class LocalServer {
  + user_service(): Arc<dyn UserService>
  + folder_service(): Arc<dyn FolderCloudService>
  + database_service(): Arc<dyn DatabaseCloudService>
  + document_service(): Arc<dyn DocumentCloudService>
  + collab_storage(): Option<Arc<dyn RemoteCollabStorage>>
}

SupabaseServer -u-|> AppFlowyServer
SelfHostServer -u-|> AppFlowyServer
LocalServer -u-|> AppFlowyServer

@enduml
