How afnan9700/some-document-editor works
1. This is a polyglot collaborative document-editing system split into four deployable pieces: an Angular frontend, a Spring Boot backend, a Node/TypeScript collaboration-state worker, and a Go WebSocket service. A docker-compose.yml and haproxy config suggest the services are intended to run together behind a reverse proxy.
2. The Spring Boot backend is the main application API and business-logic layer. It owns authentication, documents, permissions, sharing/invites, locks, access requests, and issuing WebSocket tickets. It also exposes internal endpoints used by the collaboration worker service.
3. The frontend is an Angular SPA. It contains distinct UI areas for auth, document library, document workspace, sharing/invites, and live collaboration. Frontend services indicate it talks to the backend over HTTP for normal CRUD flows and to the WebSocket service for real-time editing.
4. Authentication is backend-owned and JWT-based. The backend includes AuthController, AuthService, JwtService, JWT and internal auth filters, a CustomUserDetailsService, and a SecurityConfig. The frontend has a JWT interceptor, so authenticated API calls are token-attached on the client side.
5. The document subsystem is the core persistence boundary in the backend. It has document metadata and content models/repositories, plus DocumentService and DocumentController. The frontend mirrors this with document models, library pages, entry pages, and workspace pages, indicating separate flows for browsing documents versus editing a specific document.
6. Sharing and access control are first-class backend subsystems. sharing, invite, permission, and access packages show a model where users can invite others, manage permission levels, and request access. The frontend has matching document-sharing pages and invite-link UI, so sharing is a user-visible workflow rather than an internal admin feature.
7. Locking is a separate coordination layer in the backend. The presence of DocumentLock, LockService, lock status/type enums, and lock repository suggests the system prevents conflicting edits or distinguishes editing modes. This is likely used alongside collaboration to manage who can edit and when.
8. Real-time collaboration is offloaded to dedicated services rather than handled directly in the Spring API. The backend has a collaborationstateworkerclient package with proxying/routing components, and an internal collaborationstateworker package for syncing worker-owned document state. This implies the backend brokers document sessions and delegates live state handling to a separate worker tier.
9. The Node/TypeScript collaboration-state-worker appears to maintain document runtime state and bridge to Spring. Its documentManager, documentRuntime, springClient, and server files suggest it receives collaboration requests, tracks per-document session state, and synchronizes with backend-persisted state or permissions. This is the stateful collaboration layer.
10. The Go ws-service is the real-time transport layer. Its internal packages for ws, hub, broker, auth, and protocol indicate it terminates WebSocket connections, authenticates them via tickets/Redis-backed auth state, and fans messages out through a hub/broker abstraction. This service is the live message bus between editors.
11. WebSocket access is ticket-based rather than raw JWT handoff. The backend has websocketticket models/services, and the frontend has a websocket-ticket.service.ts. That suggests the frontend first asks the backend for a short-lived ticket, then uses that ticket to connect to the Go WebSocket service.
12. The collaboration flow likely looks like this: user logs in through Angular, receives a JWT, loads a document via backend APIs, requests a WebSocket ticket, connects to the WebSocket service, and then exchanges editing events through the collaboration stack. The worker and backend synchronize document/session state, while persistent document data remains in the Spring backend database layer.
13. The repo also includes strong cross-cutting concerns in the backend: a global exception model, API error response type, and utility security helpers. That indicates the Spring service is the canonical place for request validation, authorization failures, and domain errors.
14. From an architecture-diagram perspective, the main boundaries are: browser UI, Spring backend API, worker/state service, WebSocket transport service, and the shared backing stores implied by JPA and Redis usage. The important external interactions are HTTP for normal app operations, Redis for WebSocket/session coordination, and proxied WebSocket connections for live editing.
Main entry points: CollabEditorApplication.java Spring app · server.ts Worker server · collaboration Collab UI · haproxy.cfg Reverse proxy
Components 32
Angular UI
Browser SPA for auth, documents, sharing, and collaboration.
- Angular app · Top-level browser application shell and routing entry point.
frontend/src/app - Auth UI · Login and signup screens plus auth models/services.
frontend/src/app/auth - Document UI · Document library, entry page, and document service for CRUD flows.
frontend/src/app/documents - Workspace UI · Document workspace pages and layout for editing or readonly viewing.
frontend/src/app/document-workspace - Sharing UI · Sharing, invite-link, and access-request screens and service.
frontend/src/app/document-sharing - Collab UI · Collaboration workspace, chat, WebSocket ticket flow, and state-worker integration.
frontend/src/app/collaboration - HTTP core · Shared API client, JWT interceptor, and app-wide tokens/services.
frontend/src/app/core
Spring API
Main application API, business logic, persistence, and security.
- Spring app · Main backend application entry point and runtime.
backend/src/main/java/com/somedomain/collab_editor/CollabEditorApplication.java - Security · JWT auth, internal auth, user details, password, and security config.
backend/src/main/java/com/somedomain/collab_editor/auth - Documents · Document metadata, content, repository, service, and controller.
backend/src/main/java/com/somedomain/collab_editor/document - Sharing · Sharing workflows and access-control orchestration.
backend/src/main/java/com/somedomain/collab_editor/sharing - Access · Access-request model and repository used for document access workflows.
backend/src/main/java/com/somedomain/collab_editor/access - Invites · Invite persistence for share/invite flows.
backend/src/main/java/com/somedomain/collab_editor/invite - Permissions · Document permission model and repository.
backend/src/main/java/com/somedomain/collab_editor/permission - Locks · Document locking and lock-state services for edit coordination.
backend/src/main/java/com/somedomain/collab_editor/lock - WS tickets · Short-lived WebSocket ticket issuance for real-time connections.
backend/src/main/java/com/somedomain/collab_editor/websocketticket - Worker bridge · Proxy endpoints and routing logic that delegate collaboration-state operations to the worker.
backend/src/main/java/com/somedomain/collab_editor/collaborationstateworkerclient - Worker sync · Internal backend endpoints and persistence for worker-synchronized document state.
backend/src/main/java/com/somedomain/collab_editor/internal/collaborationstateworker - API errors · Global exception handling and API error model.
backend/src/main/java/com/somedomain/collab_editor/common
State Worker
Node/TypeScript service that manages collaboration state and bridges to Spring.
- Worker server · Node service entrypoint exposing collaboration-state APIs.
collaboration-state-worker/src/server.ts - Doc runtime · Per-document runtime/session state management.
collaboration-state-worker/src/documentRuntime.ts - Doc manager · Document lifecycle and routing orchestration for collaboration sessions.
collaboration-state-worker/src/documentManager.ts - Spring client · Client used to synchronize with Spring backend services.
collaboration-state-worker/src/springClient.ts
WebSocket Service
Go service that terminates live editor connections and routes messages.
- WS server · Go WebSocket server entrypoint.
ws-service/cmd/ws-server/main.go - WS handler · Connection upgrade and message handling for WebSocket clients.
ws-service/internal/ws/handler.go - Hub · Connected-client hub for room membership and broadcast coordination.
ws-service/internal/hub - Broker · Redis-backed message distribution between WebSocket instances.
ws-service/internal/broker - WS auth · Ticket validation and Redis-backed auth state for WebSocket access.
ws-service/internal/auth - Protocol · Message envelopes and payload definitions for live collaboration.
ws-service/internal/protocol
Shared Infra
Backing stores and edge routing used by the deployable services.
- Reverse proxy · Edge proxy for routing browser and service traffic.
haproxy/haproxy.cfg - Primary DB · Persistent store for users, documents, permissions, locks, and invites.
- Redis · Shared Redis store used by WebSocket auth and broker coordination.
Connections 34
- Angular app → HTTP core: uses · App shell uses shared HTTP/auth plumbing.
- HTTP core → Security: JWT auth · Client attaches JWTs to API calls.
- Auth UI → Security: login/signup · Auth screens call backend auth endpoints.
- Document UI → Documents: CRUD · Document browsing and metadata flows use backend APIs.
- Workspace UI → Document UI: opens · Workspace builds on selected document flows.
- Sharing UI → Sharing: share flows · Invite and access-request UI calls sharing APIs.
- Sharing UI → Access: requests · Access request UI hits access endpoints.
- Collab UI → WS tickets: gets ticket · Frontend requests short-lived WebSocket tickets.
- Collab UI → WS server: connects · Editor connects to live WebSocket transport.
- Collab UI → Worker server: sync state · Collaboration UI interacts with the state worker.
- Spring app → Security: protects · Spring app uses JWT and internal auth filters.
- Spring app → Documents: hosts · Main API exposes document endpoints.
- Spring app → Sharing: hosts · Main API exposes sharing endpoints.
- Spring app → Locks: coordinates · Backend manages document lock state.
- Spring app → WS tickets: issues · Backend issues WebSocket access tickets.
- Spring app → Worker bridge: delegates · Backend proxies collaboration-state operations to the worker tier.
- Worker bridge → Worker server: routes to · Proxy layer forwards requests to the worker service.
- Worker sync → Worker server: syncs · Internal worker-sync endpoints mirror worker-owned state.
- Worker server → Doc manager: orchestrates · Server coordinates document lifecycle logic.
- Doc manager → Doc runtime: creates · Manager maintains per-document runtime state.
- Spring client → Worker sync: syncs state · Worker uses Spring-facing sync endpoints.
- WS server → WS handler: accepts · Server upgrades and handles WebSocket connections.
- WS handler → Hub: joins · Connections are registered in the hub.
- WS handler → Protocol: encodes · Handler uses collaboration message envelopes and payloads.
- Hub → Broker: fanout · Hub uses broker for multi-instance message distribution.
- WS auth → Redis: reads/writes · Ticket auth uses Redis-backed state.
- Broker → Redis: pub/sub · Broker relies on Redis for cross-instance coordination.
- Documents → Primary DB: persists · Documents and content are stored in the main database.
- Sharing → Primary DB: persists · Sharing state is persisted in the main database.
- Locks → Primary DB: persists · Lock state is persisted in the main database.
- Worker sync → Primary DB: persists · Worker-sync state is stored in the main database.
- Reverse proxy → Angular app: routes UI · Proxy routes browser traffic to the frontend.
- Reverse proxy → Spring app: routes API · Proxy routes HTTP API traffic to Spring.
- Reverse proxy → WS server: routes WS · Proxy routes WebSocket traffic to the Go service.