Skip to content

Commit 7bd4ded

Browse files
authored
BC-7905 - Update documentation on tldraw (#42)
2 parents aed8456 + 3692db0 commit 7bd4ded

19 files changed

+408
-213
lines changed

docs/services/tldraw/How it works.md

Lines changed: 0 additions & 81 deletions
This file was deleted.

docs/services/tldraw/Local setup.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/services/tldraw/Technical details.md

Lines changed: 0 additions & 90 deletions
This file was deleted.
-46.9 KB
Binary file not shown.

docs/services/tldraw/assets/Create TLDRAW.drawio.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.
-43.8 KB
Binary file not shown.

docs/services/tldraw/assets/Delete TLDRAW.drawio.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.
-72.3 KB
Binary file not shown.

docs/services/tldraw/assets/Use tldraw.drawio.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/tldraw-server/How it works.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# How it works
2+
3+
The terms Redis and Valkey are used here synonymously and should describe the used in-memory-database.
4+
5+
## Configuration
6+
7+
- AUTHORIZATION_API_HOST - host address of the authorization endpoint (schuldcloud-server)
8+
- FEATURE_TLDRAW_ENABLED - flag determining if tldraw is enabled
9+
- LOGGER_LOG_LEVEL - logging level
10+
- LOGGER_EXIT_ON_ERROR - flag whether an error will cause the application to stop
11+
- METRICS_COLLECT_DEFAULT - flag whether the default metrics shall be collected
12+
- REDIS_CLUSTER_ENABLED - flag whether a redis cluster or used or not
13+
- REDIS_URL - redis connection string
14+
- REDIS_SENTINEL_SERVICE_NAME - name of the redis sentinel service
15+
- REDIS_PREFIX - prefix to be used with redis database
16+
- REDIS_SENTINEL_NAME - name of the redis sentinel
17+
- REDIS_SENTINEL_PASSWORD - password for the redis sentinel
18+
- S3_ACCESS_KEY - access key for S3 storage
19+
- S3_BUCKET - name of the S3 bucket
20+
- S3_ENDPOINT - URL of the S3 service
21+
- S3_PORT - port number for the S3 service
22+
- S3_SECRET_KEY - secret key for S3 storage
23+
- S3_SSL - flag to enable or disable SSL for S3 storage
24+
- TLDRAW_ASSETS_ENABLED - enables uploading assets to tldraw board
25+
- TLDRAW_ASSETS_MAX_SIZE_BYTES - maximum asset size in bytes
26+
- TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST - list of allowed assets MIME types
27+
- TLDRAW_WEBSOCKET_PATH - path for the tldraw websocket connection
28+
- TLDRAW_WEBSOCKET_URL - URL for the tldraw websocket connection
29+
- WORKER_MIN_MESSAGE_LIFETIME - minimal lifetime of a update message consumed by the worker
30+
- WORKER_TASK_DEBOUNCE - minimum idle time (in milliseconds) of the pending task messages to be claimed
31+
- WORKER_TRY_CLAIM_COUNT - the maximum number of task messages to claim
32+
- X_API_ALLOWED_KEYS - list of allowed xAPI keys
33+
34+
In order to have deletion functionality fully working locally you have to fill those feature flags, e.g.:
35+
36+
tldraw-server :
37+
- X_API_ALLOWED_KEYS="7ccd4e11-c6f6-48b0-81eb-abcdef123456"
38+
39+
schulcloud-server :
40+
- TLDRAW_ADMIN_API_CLIENT_API_KEY="7ccd4e11-c6f6-48b0-81eb-abcdef123456"
41+
- TLDRAW_ADMIN_API_CLIENT_BASE_URL="http://localhost:3349"
42+
43+
## Create
44+
![Create tldraw workflow](./assets/Create_TLDRAW.drawio.svg)
45+
46+
The Tldraw board can be created by the user on the courses ColumnBoard. It has a representation in ColumnBoard as DrawingElement inside a card (BoardNode in db). After creating representation as DrawingElement we can enter actual Tldraw SPA client on click.
47+
48+
1. User enters ColumnBoard and creates Representation of whiteboard (tldraw) in Card.
49+
2. Data is saved and feedback with proper creation is given - user can see Representation and can enter whiteboard.
50+
3. By entering whiteboard user is redirected to SPA tldraw-client.
51+
4. Tldraw-client is starting WS connection with tldraw-server.
52+
5. Tldraw-server first checks if user has permission to this resource (by checking if user has a permission to Representation of whiteboard - BoardNode).
53+
Id of Representation is same as drawingName, which is visible in tldraw-client url.
54+
6. If user has permission tldraw-server is allowing to remain connected and getting drawing data from S3 storage. If there is no drawing data available, the tldraw-server will create a new document automatically.
55+
56+
## Usage
57+
![Usage tldraw workflow](./assets/Use_TLDRAW.drawio.svg)
58+
59+
### Connection
60+
61+
1. User joins tldraw board.
62+
2. Tldraw-client connects to one of the tldraw-server pods and tries to establish websocket connection.
63+
3. Tldraw-server calls schulcloud-server via HTTP requests to check user permissions. If everything is fine, the websocket connection is established.
64+
4. Tldraw-server gets stored tldraw board data from S3 storage and sends it via websocket to connected user.
65+
5. Tldraw-server starts subscribing to Redis PUBSUB channel corresponding to tldraw board name to listen to changes from other pods.
66+
67+
### Sending updates/storing data
68+
69+
1. Tldraw-client sends user's drawing changes to the tldraw-server via websocket connection.
70+
2. Tldraw-server stores the board update in the valkey db - basically creates a diff between what's already stored and what's being updated.
71+
3. Tldraw-server pushes the update to the boards Redis channel so that connected clients on different pods have synchronized board data.
72+
4. Other pods subscribing to Redis channel send updates to their connected clients via websocket whenever they see a new message on Redis channel.
73+
5. Finally the worker will run and persist the current state of the drawing data by applying all currently available updates from valkey on top of the stored drawing data and update the S3 storage accordingly.
74+
75+
## Delete
76+
![Delete tldraw workflow](./assets/Delete_TLDRAW.drawio.svg)
77+
78+
1. User from schulcloud app in ColumnBoard deletes whiteboard (tldraw) instance form Card.
79+
2. Schulcloud-server is removing representation data in schulcloud-database - BoardNodes collection.
80+
3. Schulcloud-server is calling tldraw-server to delete all data that has given id.
81+
4. Tldraw-server sends a delete action via websocket to inform connected clients about deletion. Clients redirect away from Tldraw-board to ensure that no new messages are added to valkey database.
82+
5. Finally the worker will run, clear all updates and data from the valkey db and delete the drawing data from the S3 storage.
83+
84+
## Assets
85+
### files upload
86+
87+
Images/GIFs can be uploaded into tldraw whiteboard by every user with access to the board. We use SVS FileStorageService to physically store uploaded assets while tldraw only holds URL to a resource.
88+
89+
The files are uploaded by calling schulcloud-api's fileController upload endpoint. This is possible because tldraw is represented as a boardnode called drawing-element. Mongo id of this drawing-element is a roomId used in URL param when connecting to a specific board.
90+
91+
### files deletion
92+
93+
The deletion of files is handled directly by the tldraw-client itself. On deletion in the UI, the client sends a delete request to the file storage. While awaiting the answer from file storage the editing of the Tldraw-board is blocked to prevent race conditions to the file storage.

0 commit comments

Comments
 (0)