# chifendse/postly_server architecture

> Architecture diagram of the GitHub repository chifendse/postly_server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chifendse/postly_server
- Repository: https://github.com/chifendse/postly_server

## Overview

Postly is a Go backend composed of independently deployable services, with an HTTP gateway in front of gRPC domain services. The principal workflow is a client request entering the gateway and reaching a domain service; messaging can also update chat state and publish per-user realtime events. Separate capabilities include account and profile management, social relationships, file storage, and DTLS/SFU calling. The README describes realtime broadcasting, but the sampled sources do not show the WebSocket subscriber wiring; those connections are therefore left unasserted.

Main entry points: [`services/gateway-service/internal/router`](https://github.com/chifendse/postly_server/tree/main/services/gateway-service/internal/router) (HTTP routes), [`services/messaging-service/internal/server/server.go`](https://github.com/chifendse/postly_server/blob/main/services/messaging-service/internal/server/server.go) (Messages and history), [`services/chat-service/internal/server/server.go`](https://github.com/chifendse/postly_server/blob/main/services/chat-service/internal/server/server.go) (Chats and groups), [`services/gateway-service/cmd/main.go`](https://github.com/chifendse/postly_server/blob/main/services/gateway-service/cmd/main.go) (HTTP gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_gateway["HTTP gateway<br/>[main.go]"]
  node_gateway_routes["HTTP routes"]
  node_gateway_clients["Service clients<br/>[clients.go]"]
end

subgraph group_domains["Domain services"]
  node_auth["Authentication<br/>[server.go]"]
  node_user["User profiles<br/>[server.go]"]
  node_chat["Chats and groups<br/>[server.go]"]
  node_friends["Friend relationships<br/>[server.go]"]
  node_messaging["Messages and history<br/>[server.go]"]
  node_proto_auth["Auth contract<br/>[auth.proto]"]
  node_proto_chat["Chat contract<br/>[chat.proto]"]
  node_proto_friends["Friends contract<br/>[friends.proto]"]
  node_proto_messaging["Messaging contract<br/>[messaging.proto]"]
  node_proto_user["User contract<br/>[user.proto]"]
end

subgraph group_realtime["Realtime and calls"]
  node_realtime_hub["Realtime hub<br/>[ws.go]"]
  node_calls["DTLS call handling<br/>[main.go]"]
  node_call_rooms["Call rooms<br/>[rooms.go]"]
  node_call_sfu["SFU forwarding<br/>[sfu.go]"]
  node_ws_sfu["WebSocket SFU<br/>[wsfu.go]"]
end

subgraph group_storage["Persistence and files"]
  node_postgres[("SQL database")]
  node_redis[("Redis Pub/Sub and cache")]
  node_s3_service["File service<br/>[server.go]"]
  node_s3_storage[("Object storage<br/>[s3.go]")]
  node_proto_s3["File contract<br/>[s3.proto]"]
end

subgraph group_legacy["Legacy protocol"]
  node_legacy_handlers["Legacy protocol handlers<br/>[handlers.go]"]
  node_legacy_udp["Legacy UDP rooms<br/>[rooms.go]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_gateway
node_gateway -->|"configures routes"| node_gateway_routes
node_gateway -->|"creates clients"| node_gateway_clients
node_gateway -.->|"routes WebSocket"| node_realtime_hub
node_gateway_routes -.->|"dispatches requests"| node_auth
node_gateway_routes -.->|"dispatches requests"| node_user
node_gateway_routes -.->|"dispatches requests"| node_chat
node_gateway_routes -.->|"dispatches requests"| node_friends
node_gateway_routes -.->|"dispatches requests"| node_messaging
node_auth -.->|"implements contract"| node_proto_auth
node_user -.->|"implements contract"| node_proto_user
node_chat -.->|"implements contract"| node_proto_chat
node_friends -.->|"implements contract"| node_proto_friends
node_messaging -.->|"implements contract"| node_proto_messaging
node_s3_service -->|"implements contract"| node_proto_s3
node_messaging -->|"updates last message"| node_chat
node_messaging -->|"reads and writes"| node_postgres
node_chat -->|"reads and writes"| node_postgres
node_chat -->|"caches results"| node_redis
node_messaging -->|"caches and publishes"| node_redis
node_friends -->|"publishes events"| node_redis
node_realtime_hub -.->|"subscribes events"| node_redis
node_s3_service -->|"uploads and presigns"| node_s3_storage
node_messaging -.->|"uses file client"| node_s3_service
node_calls -->|"manages participants"| node_call_rooms
node_calls -->|"forwards packets"| node_call_sfu
node_calls -->|"starts hub"| node_ws_sfu
node_legacy_handlers -.->|"handles separately"| node_legacy_udp

click node_gateway "https://github.com/chifendse/postly_server/blob/main/services/gateway-service/cmd/main.go"
click node_gateway_routes "https://github.com/chifendse/postly_server/tree/main/services/gateway-service/internal/router"
click node_gateway_clients "https://github.com/chifendse/postly_server/blob/main/services/gateway-service/internal/clients/clients.go"
click node_auth "https://github.com/chifendse/postly_server/blob/main/services/auth-service/internal/server/server.go"
click node_user "https://github.com/chifendse/postly_server/blob/main/services/user-service/internal/server/server.go"
click node_chat "https://github.com/chifendse/postly_server/blob/main/services/chat-service/internal/server/server.go"
click node_friends "https://github.com/chifendse/postly_server/blob/main/services/friends-service/internal/server/server.go"
click node_messaging "https://github.com/chifendse/postly_server/blob/main/services/messaging-service/internal/server/server.go"
click node_realtime_hub "https://github.com/chifendse/postly_server/blob/main/services/gateway-service/internal/router/ws.go"
click node_calls "https://github.com/chifendse/postly_server/blob/main/services/call-service/cmd/main.go"
click node_call_rooms "https://github.com/chifendse/postly_server/blob/main/services/call-service/internal/udp/rooms.go"
click node_call_sfu "https://github.com/chifendse/postly_server/blob/main/services/call-service/internal/sfu/sfu.go"
click node_ws_sfu "https://github.com/chifendse/postly_server/blob/main/services/call-service/internal/wsfu/wsfu.go"
click node_s3_service "https://github.com/chifendse/postly_server/blob/main/services/s3-service/internal/server.go"
click node_s3_storage "https://github.com/chifendse/postly_server/blob/main/services/s3-service/internal/s3.go"
click node_proto_auth "https://github.com/chifendse/postly_server/blob/main/proto/auth/auth.proto"
click node_proto_chat "https://github.com/chifendse/postly_server/blob/main/proto/chat/chat.proto"
click node_proto_friends "https://github.com/chifendse/postly_server/blob/main/proto/friends/friends.proto"
click node_proto_messaging "https://github.com/chifendse/postly_server/blob/main/proto/messaging/messaging.proto"
click node_proto_s3 "https://github.com/chifendse/postly_server/blob/main/proto/s3/s3.proto"
click node_proto_user "https://github.com/chifendse/postly_server/blob/main/proto/user/user.proto"
click node_legacy_handlers "https://github.com/chifendse/postly_server/blob/main/services/old/internal/protocol_stack/handlers.go"
click node_legacy_udp "https://github.com/chifendse/postly_server/blob/main/services/old/internal/udp/rooms.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gateway,node_gateway_routes,node_gateway_clients,node_client toneBlue
class node_auth,node_user,node_chat,node_friends,node_messaging,node_proto_auth,node_proto_chat,node_proto_friends,node_proto_messaging,node_proto_user toneAmber
class node_realtime_hub,node_calls,node_call_rooms,node_call_sfu,node_ws_sfu toneMint
class node_postgres,node_redis,node_s3_service,node_s3_storage,node_proto_s3 toneRose
class node_legacy_handlers,node_legacy_udp toneIndigo
```

## Components

### API entry

- [HTTP gateway](https://github.com/chifendse/postly_server/blob/main/services/gateway-service/cmd/main.go): `services/gateway-service/cmd/main.go`
- [HTTP routes](https://github.com/chifendse/postly_server/tree/main/services/gateway-service/internal/router): `services/gateway-service/internal/router`
- [Service clients](https://github.com/chifendse/postly_server/blob/main/services/gateway-service/internal/clients/clients.go): `services/gateway-service/internal/clients/clients.go`

### Domain services

- [Authentication](https://github.com/chifendse/postly_server/blob/main/services/auth-service/internal/server/server.go): `services/auth-service/internal/server/server.go`
- [User profiles](https://github.com/chifendse/postly_server/blob/main/services/user-service/internal/server/server.go): `services/user-service/internal/server/server.go`
- [Chats and groups](https://github.com/chifendse/postly_server/blob/main/services/chat-service/internal/server/server.go): `services/chat-service/internal/server/server.go`
- [Friend relationships](https://github.com/chifendse/postly_server/blob/main/services/friends-service/internal/server/server.go): `services/friends-service/internal/server/server.go`
- [Messages and history](https://github.com/chifendse/postly_server/blob/main/services/messaging-service/internal/server/server.go): `services/messaging-service/internal/server/server.go`
- [Auth contract](https://github.com/chifendse/postly_server/blob/main/proto/auth/auth.proto): `proto/auth/auth.proto`
- [Chat contract](https://github.com/chifendse/postly_server/blob/main/proto/chat/chat.proto): `proto/chat/chat.proto`
- [Friends contract](https://github.com/chifendse/postly_server/blob/main/proto/friends/friends.proto): `proto/friends/friends.proto`
- [Messaging contract](https://github.com/chifendse/postly_server/blob/main/proto/messaging/messaging.proto): `proto/messaging/messaging.proto`
- [User contract](https://github.com/chifendse/postly_server/blob/main/proto/user/user.proto): `proto/user/user.proto`

### Realtime and calls

- [Realtime hub](https://github.com/chifendse/postly_server/blob/main/services/gateway-service/internal/router/ws.go): `services/gateway-service/internal/router/ws.go`
- [DTLS call handling](https://github.com/chifendse/postly_server/blob/main/services/call-service/cmd/main.go): `services/call-service/cmd/main.go`
- [Call rooms](https://github.com/chifendse/postly_server/blob/main/services/call-service/internal/udp/rooms.go): `services/call-service/internal/udp/rooms.go`
- [SFU forwarding](https://github.com/chifendse/postly_server/blob/main/services/call-service/internal/sfu/sfu.go): `services/call-service/internal/sfu/sfu.go`
- [WebSocket SFU](https://github.com/chifendse/postly_server/blob/main/services/call-service/internal/wsfu/wsfu.go): `services/call-service/internal/wsfu/wsfu.go`

### Persistence and files

- **SQL database**
- **Redis Pub/Sub and cache**
- [File service](https://github.com/chifendse/postly_server/blob/main/services/s3-service/internal/server.go): `services/s3-service/internal/server.go`
- [Object storage](https://github.com/chifendse/postly_server/blob/main/services/s3-service/internal/s3.go): `services/s3-service/internal/s3.go`
- [File contract](https://github.com/chifendse/postly_server/blob/main/proto/s3/s3.proto): `proto/s3/s3.proto`

### Legacy protocol

- [Legacy protocol handlers](https://github.com/chifendse/postly_server/blob/main/services/old/internal/protocol_stack/handlers.go): `services/old/internal/protocol_stack/handlers.go`
- [Legacy UDP rooms](https://github.com/chifendse/postly_server/blob/main/services/old/internal/udp/rooms.go): `services/old/internal/udp/rooms.go`

### Other components

- **API client**

## Connections

- API client → HTTP gateway: sends requests
- HTTP gateway → HTTP routes: configures routes (evidence: `services/gateway-service/cmd/main.go`)
- HTTP gateway → Service clients: creates clients (evidence: `services/gateway-service/cmd/main.go`)
- HTTP gateway → Realtime hub: routes WebSocket
- HTTP routes → Authentication: dispatches requests
- HTTP routes → User profiles: dispatches requests
- HTTP routes → Chats and groups: dispatches requests
- HTTP routes → Friend relationships: dispatches requests
- HTTP routes → Messages and history: dispatches requests
- Authentication → Auth contract: implements contract
- User profiles → User contract: implements contract
- Chats and groups → Chat contract: implements contract
- Friend relationships → Friends contract: implements contract
- Messages and history → Messaging contract: implements contract
- File service → File contract: implements contract
- Messages and history → Chats and groups: updates last message (evidence: `services/messaging-service/internal/server/server.go`)
- Messages and history → SQL database: reads and writes (evidence: `services/messaging-service/internal/server/server.go`)
- Chats and groups → SQL database: reads and writes (evidence: `services/chat-service/internal/server/server.go`)
- Chats and groups → Redis Pub/Sub and cache: caches results (evidence: `services/chat-service/internal/server/server.go`)
- Messages and history → Redis Pub/Sub and cache: caches and publishes (evidence: `services/messaging-service/internal/server/server.go`)
- Friend relationships → Redis Pub/Sub and cache: publishes events (evidence: `services/friends-service/internal/server/server.go`)
- Realtime hub → Redis Pub/Sub and cache: subscribes events
- File service → Object storage: uploads and presigns (evidence: `services/s3-service/internal/server.go`)
- Messages and history → File service: uses file client
- DTLS call handling → Call rooms: manages participants (evidence: `services/call-service/cmd/main.go`)
- DTLS call handling → SFU forwarding: forwards packets (evidence: `services/call-service/cmd/main.go`)
- DTLS call handling → WebSocket SFU: starts hub (evidence: `services/call-service/cmd/main.go`)
- Legacy protocol handlers → Legacy UDP rooms: handles separately
