> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Rooms Collection

`rooms` holds one document per chat room of a project: the project chat, or one review comment thread. Only the chat service writes it, in `services/chat/app/js/Features/Threads/ThreadManager.js`. There is no Mongoose schema. The messages of a room are in the [messages](https://ayakaleaf-pro.mintlify.site/dev/data-model/messages-collection.md) collection.

#### Fields

| Field | Type | Meaning | Source |
| - | - | - | - |
| `_id` | ObjectId | Room id. `messages.room_id` points here. | `ThreadManager.js:57-61` |
| `project_id` | ObjectId | Project the room belongs to. | `ThreadManager.js:43-54` |
| `thread_id` | ObjectId | Only on comment threads: the id of the comment, the same as `id` and `op.t` of the comment in `docs.ranges.comments` (see [docs](https://ayakaleaf-pro.mintlify.site/dev/data-model/docs-collection.md)). Missing on the project chat room. | `ThreadManager.js:38-55`, `services/docstore/app/js/RangeManager.js:54-57` |
| `resolved` | Object | Set when the thread is resolved, removed when it is reopened. A thread without it is open. | `ThreadManager.js:94-123` |
| `resolved.user_id` | String | Id of the user who resolved the thread. Stored as a string, not an ObjectId: the request body is only checked to be a valid id, not converted. | `ThreadManager.js:103`, `services/chat/app/js/Features/Messages/MessageHttpSchemas.js:70` |
| `resolved.ts` | Date | When the thread was resolved. | `ThreadManager.js:104` |

#### Who Writes It

| Code | What it does |
| - | - |
| `ThreadManager.js:31-63` `findOrCreateThread` | Upserts the room. Runs on every send, read, edit and delete of messages (`services/chat/app/js/Features/Messages/MessageHttpController.js:183,204,227,236,245,280,301`), so the first message of a comment creates its thread room, and reading the project chat creates the project chat room. |
| `ThreadManager.js:94-109` `resolveThread` | Sets `resolved`. Called from web by the track-changes module (`services/web/modules/track-changes/app/src/TrackChangesController.mjs:142`), by history restore (`services/web/app/src/Features/History/RestoreManager.mjs:276`) and by the mcp-server module (`services/web/modules/mcp-server/app/src/CommentTools.mjs:159`). |
| `ThreadManager.js:111-123` `reopenThread` | Removes `resolved`. Same callers: `TrackChangesController.mjs:160`, `RestoreManager.mjs:285`, `CommentTools.mjs:183`. |
| `ThreadManager.js:154-172` `duplicateThread` | Inserts a new room with a new `thread_id`, copying `resolved`. Used when a doc is restored from history (`RestoreManager.mjs:233`). |
| `ThreadManager.js:12-29` `cloneThreads` | Copies every thread room of a project to another project, with a new `_id` and the same `thread_id`. Used when a project is copied with its ranges (`services/web/app/src/Features/Project/ProjectDuplicator.mjs:197`). |
| `ThreadManager.js:125-131` `deleteThread` | Deletes one thread room; the controller then deletes its messages (`MessageHttpController.js:167-175`). Called by the track-changes module (`TrackChangesController.mjs:173`). |
| `ThreadManager.js:133-137` `deleteAllThreadsInProject` | Deletes all rooms of a project (`MessageHttpController.js:261-273`). Called when a deleted project expires (`services/web/app/src/Features/Project/ProjectDeleter.mjs:391`). |

#### Who Reads It

| Code | What it does |
| - | - |
| `ThreadManager.js:65-78` `findAllThreadRooms` | Lists the thread rooms of a project with their messages (`MessageHttpController.js:71-81`), for the review panel of the track-changes module (`TrackChangesController.mjs:82`) and the mcp-server module (`CommentTools.mjs:83`). |
| `ThreadManager.js:139-152` `getResolvedThreadIds` | Returns the resolved thread ids. Web adds the ones of a doc to the doc it sends to document-updater (`services/web/app/src/Features/Documents/DocumentController.mjs:69-77`). |
| `ThreadManager.js:174-188` `findThread` | One thread with its messages (`MessageHttpController.js:97-120`). Web uses it to let a reviewer change only threads they started (`services/web/app/src/Features/Authorization/AuthorizationManager.mjs:409`). |
| `ThreadManager.js:190-197` `findThreadsById` | Thread data for given ids, used by history restore (`RestoreManager.mjs:259`). |

#### Indexes

| Name | Keys | Options | Migration |
| - | - | - | - |
| `project_id_1_thread_id_1` | `{ project_id: 1, thread_id: 1 }` | | `tools/migrations/20250206103037_create_rooms_projectId_threadId_index.mjs` |

The older `project_id` index (`20190912145026_create_rooms_indexes.mjs`) was dropped by `20250205145327_drop_rooms_projectId_index.mjs`.

#### Notes

* A project has at most one room without `thread_id`, the project chat. The chat service finds it with `thread_id: { $exists: false }` (`ThreadManager.js:38-45`).
* The resolved state of a comment lives only here. Docstore strips `op.resolved` before it saves ranges (`services/docstore/app/js/RangeManager.js:59-61`).
* After a project copy, the same `thread_id` exists in two projects. Always query by `project_id` and `thread_id` together, as the chat service does.
* Rooms of a deleted project stay until the deleted project expires.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.