Templates/Social & community

Chat app (Firestore) database schema

Users, rooms with their members, and messages as a subcollection of each room.

3 collections, 1 references

Opens as a new diagram you can change. Free.

Collections

users

One document per signed-in user, keyed by their auth uid.

  • idstring not null
  • displayNamestring not null
  • photoUrlstring
  • lastSeentimestamp not null

rooms

A conversation; members are listed so rules can check them.

  • idstring not null
  • namestring not null
  • memberIdsarray not null
  • lastMessagemap
  • lastMessage.textstring
  • lastMessage.sentAttimestamp
  • updatedAttimestamp not null

rooms/messages

Messages under their room, read in pages by time.

  • idstring not null
  • authorId> usersstring not null
  • textstring not null
  • sentAttimestamp not null
  • editedAttimestamp

As firestore.indexes.json

The diagram also exports firestore.rules skeleton, TypeScript types and converters, Zod schemas, Sample documents (JSON).

{
  "indexes": [
    {
      "collectionGroup": "rooms",
      "queryScope": "COLLECTION",
      "fields": [
        {
          "fieldPath": "memberIds",
          "arrayConfig": "CONTAINS"
        },
        {
          "fieldPath": "updatedAt",
          "order": "DESCENDING"
        }
      ]
    },
    {
      "collectionGroup": "messages",
      "queryScope": "COLLECTION_GROUP",
      "fields": [
        {
          "fieldPath": "authorId",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "sentAt",
          "order": "DESCENDING"
        }
      ]
    }
  ],
  "fieldOverrides": []
}

More Social & community templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.