# Diarkis サーバー

## 概要

Diarkis サーバー SDK は Go 言語（Golang）で開発されています。Go の強力な並列処理とネットワークスタックを最大限に活用しており、プロダクション環境において高いスケーラビリティと低レイテンシな通信を実現します。

Diarkis クラスターを構築・稼働させるためには、クラウドサービスの選定に加え、アプリケーションの要件（同時接続数、通信頻度など）に合わせたカスタマイズが必要です。

#### クラスターを構成するサーバータイプ

Diarkis クラスターは、主に以下の 4 種類の役割を持つサーバーで構成されます。

<table><thead><tr><th width="163">サーバー</th><th>説明</th></tr></thead><tbody><tr><td><strong>MARS</strong><a href="#references"><sup>[1]</sup></a></td><td>クラスター内の全ノードの状態管理</td></tr><tr><td><strong>HTTP</strong></td><td>認証連携や接続先エンドポイント（UDP/TCP）</td></tr><tr><td><strong>UDP/RUDP</strong></td><td>UDP または Reliable UDP を使用したリアルタイム通信</td></tr><tr><td><strong>TCP</strong></td><td>TCP を使用したリアルタイム通信を処理</td></tr></tbody></table>

また、以下の図は、Diarkis の基本的なアーキテクチャ構成のシンプルな例を示しています。

### Diarkis アーキテクチャ構成図の例

{% @mermaid/diagram content="architecture-beta
group Clients(internet)\[Clients]
service tcp\_cli(internet)\[Client Devices] in Clients
service udp\_cli(internet)\[Client Devices] in Clients

```
group Kubernetes(cloud)[Kubernetes]
    service lb(server)[Load Balancer] in Kubernetes

    group Diarkis(cloud)[Diarkis] in Kubernetes
        service udp(server)[UDP Servers] in Diarkis
        service http(server)[HTTP Servers] in Diarkis
        service tcp(server)[TCP Servers] in Diarkis
        service mars(server)[MARS] in Diarkis

group External(cloud)[external]
    service api(database)[API Servers] in External

lb:R -- L:http
lb:B -- T:api

tcp_cli:L -- R:tcp
udp_cli:L -- R:udp

%% tcp_cli:B -- R:api
%% udp_cli:B -- R:api

%% Internal cluster routing
udp:B -- T:http
http:B -- T:tcp" %}
```

これらのサーバー構成は [Diarkis サーバーテンプレート](/getting-started/diarkis-server-template.md)を利用することで簡単に始めることができます。

### ユーザーの接続フロー

Diarkis と通信するための接続を確立するには、HTTP API を介して接続エンドポイントとその他の必要なデータをクラスタから取得する必要があります。

以下の図は、ユーザーが Diarkis サーバークラスターとの接続を開始する際のフローを示しています。

{% @mermaid/diagram content="
sequenceDiagram
participant Client as Client Device
participant App as Application Server
box Cloud/Infrastructure
participant LB as Load Balancer
end
box "Diarkis Cluster"
participant D\_HTTP as Diarkis HTTP
participant D\_Net as Diarkis UDP/TCP
end

```
Note over Client, App: User Authentication
Client->>App: Authenticate
App->>LB: Endpoint Request
LB->>D_HTTP: Route Request
D_HTTP->>D_HTTP: User Creation
D_HTTP-->>LB: Return UDP/TCP Endpoint
LB-->>App: Return UDP/TCP Endpoint
App-->>Client: Return UDP/TCP Endpoint

Note over Client, D_Net: Direct Connection
Client->>D_Net: UDP/TCP Direct Connection" %}
```

***

#### References

* \[1]: プロダクション環境では、**MARS** がダウンした場合に備え、クラスター内の他のノードがその役割を継承する自動選出（Election）アルゴリズムが組み込まれています。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.diarkis.io/diarkis-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
