> ## 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.

# Dropbox Projects Collection

`dropboxProjects` maps a project to its folder in one user's Dropbox. A project shared with several Dropbox users has one document per user. It belongs to Dropbox sync: third-party-datastore (`services/third-party-datastore/app/js/StateManager.mjs`) writes it, and the `dropbox` web module (`services/web/modules/dropbox/app/src/DropboxHandler.mjs`) reads it and clears it. There is no Mongoose schema.

#### Fields

| Field | Type | Meaning | Source |
| - | - | - | - |
| `_id` | ObjectId | Set by the driver on insert. | `StateManager.mjs:144` |
| `userId` | ObjectId | The Overleaf user whose Dropbox has the folder. | `StateManager.mjs:145` |
| `projectId` | ObjectId | The project synced into the folder. | `StateManager.mjs:146` |
| `dropboxId` | String | The `id` of the folder in the Dropbox folder metadata. | `StateManager.mjs:147`, `JobProcessor.mjs:82-87`, `PullManager.mjs:138` |
| `pathLower` | String | The path of the folder in Dropbox, lower-cased and without a trailing slash. Project folders are at the top level, one per project, for example `/thesis (1)` when Dropbox numbered it next to another project's `Thesis`. | `StateManager.mjs:14-16,148`, `PullManager.mjs:112-117` |

#### Who Writes It

| Code | What it does |
| - | - |
| `services/third-party-datastore/app/js/StateManager.mjs:137-150` (`setProjectFolder`) | Deletes the user's documents with the same `projectId`, `dropboxId` or `pathLower`, then inserts the new mapping. |
| `services/third-party-datastore/app/js/JobProcessor.mjs:58-91` (`projectFolder`) | Creates the folder in Dropbox and records it, when web asks for the folder of a new project or of a project the user was added to (`createProject`, `:245-251`), or sends a file of a project that has no folder yet (`addEntity`, `:113`). |
| `JobProcessor.mjs:174-203` (`renameProject`) | After a project rename moves the folder, it records the new path, or removes the mapping when the folder is gone (`:190`). |
| `services/third-party-datastore/app/js/PullManager.mjs:119-140` (`resolveProject`) | When a pull finds a folder with no mapping, it records the project that web matched by name. |
| `PullManager.mjs:188-207` (`applyDeletion`) | When a project folder is deleted in Dropbox, it removes the mapping (`StateManager.mjs:152-157`). |
| `StateManager.mjs:186-190` (`removeUserState`), called from `services/third-party-datastore/app/js/QueueWorker.mjs:43` | Deletes all of the user's documents when third-party-datastore unlinks an account it can no longer use. |
| `DropboxHandler.mjs:142-146` (`removeUserState`) | Deletes all of the user's documents on link (`:125`), on unlink (`:183`), and when a deleted user expires (`services/web/modules/dropbox/index.mjs:62-64`). |
| `DropboxHandler.mjs:150-154` (`removeProjectState`) | Deletes the project's documents when a deleted project expires (`index.mjs:54-56`). |

#### Who Reads It

| Code | What it does |
| - | - |
| `StateManager.mjs:130-135` (`getFolderOfProject`) | Finds the folder of a project: `JobProcessor.mjs:59,98,176` and `PullManager.mjs:133`. |
| `StateManager.mjs:123-128` (`getProjectByFolder`) | Finds the project of a folder: `JobProcessor.mjs:65` (name already taken), `PullManager.mjs:120,197`. |
| `StateManager.mjs:160-175` (`getSyncedPaths`) | Lists the folder paths after a cursor reset, so that a folder missing from the listing counts as deleted (`PullManager.mjs:74-85`). |
| `DropboxHandler.mjs:234-250` (`getProjectFolderName`) | Gives the folder name shown in the editor's Dropbox dialog (`services/web/modules/dropbox/app/src/DropboxController.mjs:130`). |

#### Indexes

| Name | Keys | Options | Migration |
| - | - | - | - |
| `_id_` | `_id: 1` | | default |

CE has no other index here. The unique indexes `projectId_userId_1` and `userId_dropboxId_1` come from `tools/migrations/20220815105500_create_dropboxProjects_index.mjs` and `20220817120900_create_dropboxProjects_index.mjs`, which are tagged `saas` only, so CE never runs them.

#### Notes

* Uniqueness comes only from the delete before each insert in `setProjectFolder` (`StateManager.mjs:140-149`). The comment at `StateManager.mjs:3-11` mentions unique indexes; CE does not have them.
* When a project's mapping is removed, its folder stays in Dropbox. An edit there is then read as a new project, as for a folder made in Dropbox (`DropboxHandler.mjs:148-149`).
* A deleted project keeps its mapping until it expires, because it can still be restored (`index.mjs:52-53`).
* The user's Dropbox `list_folder` cursor is not here. It is `users.dropbox.cursor` (`StateManager.mjs:177-184`).


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