# won-life/aideep_websocket architecture

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

- Interactive diagram: https://gitdiagram.com/won-life/aideep_websocket
- Repository: https://github.com/won-life/aideep_websocket

## Overview

This is a NestJS realtime server for Aideep, centered on Socket.IO and Yjs collaborative node editing. The main HTTP path validates an authenticated Markdown operation, checks workspace access and node state, applies it to the in-memory CRDT document, persists it, then broadcasts the update. The server also supports realtime presence, event-bus subscriptions, file attachments, and embedding jobs. Source excerpts establish the content-operation and document-save paths; several module capabilities are visible only in the tree or source index, so their unverified connections are omitted.

Main entry points: [`src/domain/node-content/service/node-content.service.ts`](https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/service/node-content.service.ts) (Operation coordinator), [`src/global/yjs/yjs-doc-manager.ts`](https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-doc-manager.ts) (Yjs document manager), [`src/domain/ws/controller/ws.gateway.ts`](https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/controller/ws.gateway.ts) (Socket gateway), [`src/app.module.ts`](https://github.com/won-life/aideep_websocket/blob/main/src/app.module.ts) (Nest application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Server runtime"]
  node_app["Nest application<br/>[app.module.ts]"]
  node_http["HTTP bootstrap<br/>[main.ts]"]
end

subgraph group_content["Node content"]
  node_controller["Content operations API"]
  node_dto["Operation contract"]
  node_contentservice["Operation coordinator"]
  node_noderepo["Node lookup"]
  node_membership["Workspace membership"]
end

subgraph group_realtime["Realtime collaboration"]
  node_gateway["Socket gateway<br/>[ws.gateway.ts]"]
  node_presence["Presence tracking"]
  node_wslog["Socket event logging<br/>[ws-log.service.ts]"]
  node_wsevent["Socket event types<br/>[ws.event.ts]"]
  node_docmanager["Yjs document manager<br/>[yjs-doc-manager.ts]"]
  node_crdt["Yjs persistence service"]
  node_markdown["Markdown conversion<br/>[markdown-yjs.ts]"]
  node_awareness["Yjs awareness"]
  node_yjsconstants["Yjs event constants<br/>[yjs.constants.ts]"]
end

subgraph group_infra["Persistence and jobs"]
  node_redis[("Redis")]
  node_redisservice["Redis client service<br/>[redis.service.ts]"]
  node_rediskeys["Redis key definitions<br/>[redis.keys.ts]"]
  node_embedqueue["Embedding queue"]
  node_prisma[("Relational database")]
  node_prismaservice["Prisma service<br/>[prisma.service.ts]"]
end

subgraph group_shared["Shared services"]
  node_auth["JWT authentication<br/>[jwt.strategy.ts]"]
  node_authmodule["Realtime auth module"]
  node_eventbus["Event bus subscriber"]
  node_fileattach["File attachment service"]
  node_filerepo["Attachment repository"]
end

node_client(("API or socket client"))
node_s3[("Object storage")]

node_client -->|"sends request"| node_http
node_http -->|"starts"| node_app
node_app -->|"registers module"| node_controller
node_app -->|"registers module"| node_gateway
node_app -->|"registers module"| node_authmodule
node_authmodule -->|"configures strategy"| node_auth
node_client -->|"posts operation"| node_controller
node_controller -->|"executes operation"| node_contentservice
node_controller -->|"accepts contract"| node_dto
node_contentservice -->|"checks access"| node_membership
node_contentservice -->|"loads node"| node_noderepo
node_contentservice -->|"claims idempotency"| node_redisservice
node_contentservice -->|"builds cache key"| node_rediskeys
node_contentservice -->|"appends Markdown"| node_docmanager
node_contentservice -->|"broadcasts update"| node_gateway
node_docmanager -->|"loads and saves state"| node_crdt
node_docmanager -->|"converts document"| node_markdown
node_docmanager -->|"queues embedding"| node_embedqueue
node_docmanager -->|"uses timings"| node_yjsconstants
node_crdt -->|"uses conversion"| node_markdown
node_gateway -->|"updates presence"| node_presence
node_gateway -->|"logs events"| node_wslog
node_gateway -->|"uses event types"| node_wsevent
node_presence -->|"stores presence"| node_redisservice
node_presence -->|"selects key"| node_rediskeys
node_awareness -->|"uses event constants"| node_yjsconstants
node_redisservice -->|"connects"| node_redis
node_embedqueue -->|"enqueues through"| node_redisservice
node_embedqueue -->|"uses queue key"| node_rediskeys
node_noderepo -->|"queries through"| node_prismaservice
node_filerepo -->|"queries through"| node_prismaservice
node_filerepo -.->|"reads and writes"| node_prisma
node_prismaservice -.->|"accesses database"| node_prisma
node_fileattach -->|"delegates storage"| node_filerepo
node_fileattach -.->|"uses object storage"| node_s3
node_eventbus -.->|"subscribes externally"| node_client

click node_app "https://github.com/won-life/aideep_websocket/blob/main/src/app.module.ts"
click node_http "https://github.com/won-life/aideep_websocket/blob/main/src/main.ts"
click node_auth "https://github.com/won-life/aideep_websocket/blob/main/src/global/auth/strategy/jwt.strategy.ts"
click node_authmodule "https://github.com/won-life/aideep_websocket/blob/main/src/global/auth/realtime-auth.module.ts"
click node_controller "https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/controller/node-content.controller.ts"
click node_dto "https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/dto/nodeContentOperation.dto.ts"
click node_contentservice "https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/service/node-content.service.ts"
click node_noderepo "https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/repository/node-content.repository.ts"
click node_membership "https://github.com/won-life/aideep_websocket/blob/main/src/domain/membership/repository/membership.repository.ts"
click node_gateway "https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/controller/ws.gateway.ts"
click node_presence "https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/service/presence.service.ts"
click node_wslog "https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/service/ws-log.service.ts"
click node_wsevent "https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/type/ws.event.ts"
click node_docmanager "https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-doc-manager.ts"
click node_crdt "https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-crdt.service.ts"
click node_markdown "https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/markdown-yjs.ts"
click node_awareness "https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-ws-awareness.service.ts"
click node_yjsconstants "https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs.constants.ts"
click node_redisservice "https://github.com/won-life/aideep_websocket/blob/main/src/global/redis/redis.service.ts"
click node_rediskeys "https://github.com/won-life/aideep_websocket/blob/main/src/global/redis/redis.keys.ts"
click node_embedqueue "https://github.com/won-life/aideep_websocket/blob/main/src/global/redis/embed-queue.service.ts"
click node_prismaservice "https://github.com/won-life/aideep_websocket/blob/main/src/global/prisma/prisma.service.ts"
click node_eventbus "https://github.com/won-life/aideep_websocket/blob/main/src/domain/event-bus/service/event-bus.subscriber.ts"
click node_fileattach "https://github.com/won-life/aideep_websocket/blob/main/src/domain/file-attachment/service/file-attachment.service.ts"
click node_filerepo "https://github.com/won-life/aideep_websocket/blob/main/src/domain/file-attachment/repository/file-attachment.repository.ts"

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_app,node_http,node_client toneBlue
class node_controller,node_dto,node_contentservice,node_noderepo,node_membership,node_s3 toneAmber
class node_gateway,node_presence,node_wslog,node_wsevent,node_docmanager,node_crdt,node_markdown,node_awareness,node_yjsconstants toneMint
class node_redis,node_redisservice,node_rediskeys,node_embedqueue,node_prisma,node_prismaservice toneRose
class node_auth,node_authmodule,node_eventbus,node_fileattach,node_filerepo toneIndigo
```

## Components

### Server runtime

- [Nest application](https://github.com/won-life/aideep_websocket/blob/main/src/app.module.ts): `src/app.module.ts`
- [HTTP bootstrap](https://github.com/won-life/aideep_websocket/blob/main/src/main.ts): `src/main.ts`

### Node content

- [Content operations API](https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/controller/node-content.controller.ts): `src/domain/node-content/controller/node-content.controller.ts`
- [Operation contract](https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/dto/nodeContentOperation.dto.ts): `src/domain/node-content/dto/nodeContentOperation.dto.ts`
- [Operation coordinator](https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/service/node-content.service.ts): `src/domain/node-content/service/node-content.service.ts`
- [Node lookup](https://github.com/won-life/aideep_websocket/blob/main/src/domain/node-content/repository/node-content.repository.ts): `src/domain/node-content/repository/node-content.repository.ts`
- [Workspace membership](https://github.com/won-life/aideep_websocket/blob/main/src/domain/membership/repository/membership.repository.ts): `src/domain/membership/repository/membership.repository.ts`

### Realtime collaboration

- [Socket gateway](https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/controller/ws.gateway.ts): `src/domain/ws/controller/ws.gateway.ts`
- [Presence tracking](https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/service/presence.service.ts): `src/domain/ws/service/presence.service.ts`
- [Socket event logging](https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/service/ws-log.service.ts): `src/domain/ws/service/ws-log.service.ts`
- [Socket event types](https://github.com/won-life/aideep_websocket/blob/main/src/domain/ws/type/ws.event.ts): `src/domain/ws/type/ws.event.ts`
- [Yjs document manager](https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-doc-manager.ts): `src/global/yjs/yjs-doc-manager.ts`
- [Yjs persistence service](https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-crdt.service.ts): `src/global/yjs/yjs-crdt.service.ts`
- [Markdown conversion](https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/markdown-yjs.ts): `src/global/yjs/markdown-yjs.ts`
- [Yjs awareness](https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs-ws-awareness.service.ts): `src/global/yjs/yjs-ws-awareness.service.ts`
- [Yjs event constants](https://github.com/won-life/aideep_websocket/blob/main/src/global/yjs/yjs.constants.ts): `src/global/yjs/yjs.constants.ts`

### Persistence and jobs

- **Redis**
- [Redis client service](https://github.com/won-life/aideep_websocket/blob/main/src/global/redis/redis.service.ts): `src/global/redis/redis.service.ts`
- [Redis key definitions](https://github.com/won-life/aideep_websocket/blob/main/src/global/redis/redis.keys.ts): `src/global/redis/redis.keys.ts`
- [Embedding queue](https://github.com/won-life/aideep_websocket/blob/main/src/global/redis/embed-queue.service.ts): `src/global/redis/embed-queue.service.ts`
- **Relational database**
- [Prisma service](https://github.com/won-life/aideep_websocket/blob/main/src/global/prisma/prisma.service.ts): `src/global/prisma/prisma.service.ts`

### Shared services

- [JWT authentication](https://github.com/won-life/aideep_websocket/blob/main/src/global/auth/strategy/jwt.strategy.ts): `src/global/auth/strategy/jwt.strategy.ts`
- [Realtime auth module](https://github.com/won-life/aideep_websocket/blob/main/src/global/auth/realtime-auth.module.ts): `src/global/auth/realtime-auth.module.ts`
- [Event bus subscriber](https://github.com/won-life/aideep_websocket/blob/main/src/domain/event-bus/service/event-bus.subscriber.ts): `src/domain/event-bus/service/event-bus.subscriber.ts`
- [File attachment service](https://github.com/won-life/aideep_websocket/blob/main/src/domain/file-attachment/service/file-attachment.service.ts): `src/domain/file-attachment/service/file-attachment.service.ts`
- [Attachment repository](https://github.com/won-life/aideep_websocket/blob/main/src/domain/file-attachment/repository/file-attachment.repository.ts): `src/domain/file-attachment/repository/file-attachment.repository.ts`

### Other components

- **API or socket client**
- **Object storage**

## Connections

- API or socket client → HTTP bootstrap: sends request (evidence: `src/main.ts`)
- HTTP bootstrap → Nest application: starts (evidence: `src/main.ts`)
- Nest application → Content operations API: registers module (evidence: `src/app.module.ts`)
- Nest application → Socket gateway: registers module (evidence: `src/app.module.ts`)
- Nest application → Realtime auth module: registers module (evidence: `src/app.module.ts`)
- Realtime auth module → JWT authentication: configures strategy (evidence: `src/global/auth/realtime-auth.module.ts`)
- API or socket client → Content operations API: posts operation (evidence: `src/domain/node-content/controller/node-content.controller.ts`)
- Content operations API → Operation coordinator: executes operation (evidence: `src/domain/node-content/controller/node-content.controller.ts`)
- Content operations API → Operation contract: accepts contract (evidence: `src/domain/node-content/controller/node-content.controller.ts`)
- Operation coordinator → Workspace membership: checks access (evidence: `src/domain/node-content/service/node-content.service.ts`)
- Operation coordinator → Node lookup: loads node (evidence: `src/domain/node-content/service/node-content.service.ts`)
- Operation coordinator → Redis client service: claims idempotency (evidence: `src/domain/node-content/service/node-content.service.ts`)
- Operation coordinator → Redis key definitions: builds cache key (evidence: `src/domain/node-content/service/node-content.service.ts`)
- Operation coordinator → Yjs document manager: appends Markdown (evidence: `src/domain/node-content/service/node-content.service.ts`)
- Operation coordinator → Socket gateway: broadcasts update (evidence: `src/domain/node-content/service/node-content.service.ts`)
- Yjs document manager → Yjs persistence service: loads and saves state (evidence: `src/global/yjs/yjs-doc-manager.ts`)
- Yjs document manager → Markdown conversion: converts document (evidence: `src/global/yjs/yjs-doc-manager.ts`)
- Yjs document manager → Embedding queue: queues embedding (evidence: `src/global/yjs/yjs-doc-manager.ts`)
- Yjs document manager → Yjs event constants: uses timings (evidence: `src/global/yjs/yjs-doc-manager.ts`)
- Yjs persistence service → Markdown conversion: uses conversion (evidence: `src/global/yjs/yjs-crdt.service.ts`)
- Socket gateway → Presence tracking: updates presence (evidence: `src/domain/ws/controller/ws.gateway.ts`)
- Socket gateway → Socket event logging: logs events (evidence: `src/domain/ws/controller/ws.gateway.ts`)
- Socket gateway → Socket event types: uses event types (evidence: `src/domain/ws/controller/ws.gateway.ts`)
- Presence tracking → Redis client service: stores presence (evidence: `src/domain/ws/service/presence.service.ts`)
- Presence tracking → Redis key definitions: selects key (evidence: `src/domain/ws/service/presence.service.ts`)
- Yjs awareness → Yjs event constants: uses event constants (evidence: `src/global/yjs/yjs-ws-awareness.service.ts`)
- Redis client service → Redis: connects (evidence: `src/global/redis/redis.service.ts`)
- Embedding queue → Redis client service: enqueues through (evidence: `src/global/redis/embed-queue.service.ts`)
- Embedding queue → Redis key definitions: uses queue key (evidence: `src/global/redis/embed-queue.service.ts`)
- Node lookup → Prisma service: queries through (evidence: `src/domain/node-content/repository/node-content.repository.ts`)
- Attachment repository → Prisma service: queries through (evidence: `src/domain/file-attachment/repository/file-attachment.repository.ts`)
- Attachment repository → Relational database: reads and writes
- Prisma service → Relational database: accesses database
- File attachment service → Attachment repository: delegates storage (evidence: `src/domain/file-attachment/service/file-attachment.service.ts`)
- File attachment service → Object storage: uses object storage
- Event bus subscriber → API or socket client: subscribes externally
