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

# Contacts Collection

`contacts` remembers which users a user has worked with, so that the share dialog can suggest them. One document per user. `web` owns it, without a Mongoose schema; the code is `services/web/app/src/Features/Contacts/ContactManager.mjs`.

#### Fields

| Field | Type | Meaning | Source |
| - | - | - | - |
| `_id` | ObjectId | Document id, created by the upsert. | `ContactManager.mjs:5-12` |
| `user_id` | ObjectId | The user whose contacts these are. One document per user. | `ContactManager.mjs:6` |
| `contacts` | Object | Map keyed by the contact's user id (as a string). | `ContactManager.mjs:8-9` |
| `contacts.<userId>.n` | Number | How many times the two users were brought together. | `ContactManager.mjs:8` |
| `contacts.<userId>.ts` | Date | When that last happened. | `ContactManager.mjs:9` |

#### Who Writes It

| Code | What it does |
| - | - |
| `ContactManager.mjs:4-13` (`touchContact`), `:23-28` (`addContact`) | Upserts both users' documents: `$inc` on `n`, `$set` of `ts`. |
| `services/web/app/src/Features/Collaborators/CollaboratorsHandler.mjs:155-157` | `addUserIdToProject` calls `addContact` when it is given the adding user: an accepted invite (inviter and invitee, `services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs:199-205`) and an ownership transfer (new and previous owner, `services/web/app/src/Features/Collaborators/OwnershipTransferHandler.mjs:138-144`). Joining through a share link passes no adding user (`services/web/app/src/Features/TokenAccess/TokenAccessController.mjs:386-388`, `:632-634`), so it adds no contact. |

#### Who Reads It

| Code | What it does |
| - | - |
| `ContactManager.mjs:15-21`, `:30-42` | `getContactIds`: sorts by `n`, then by `ts`, both highest first. |
| `services/web/app/src/Features/Contacts/ContactController.mjs:19-59` | `GET /user/contacts` (`services/web/app/src/Features/Contacts/ContactRouter.mjs:22-26`): returns the top 50 as users, without holding accounts, plus what modules add through the `getContacts` hook. |

#### Indexes

| Name | Keys | Options | Migration |
| - | - | - | - |
| `user_id_1` | `{ user_id: 1 }` | unique | `tools/migrations/20190912145001_create_contacts_indexes.mjs` |

#### Notes

* Contacts go both ways: adding B to A's project makes B a contact of A and A a contact of B.
* Nothing removes a contact or the document, not even when a user is deleted.


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