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
- Social networkProfiles, follows, posts with media, comments and likes.
- Discussion forumCategories, threads and posts with reactions and moderation reports.
- Chat / messagingDirect and group conversations, messages, attachments and read receipts.
- Dating appProfiles with photos, swipes, mutual matches, messages and blocks.
- Meetup groupsInterest groups with members, events at venues and RSVPs.
- Q&A siteQuestions, answers with votes, accepted answers and tags.
- Reviews & ratingsBusinesses reviewed by users, with photos, helpful votes and owner replies.
- Creator membershipsCreators offering paid tiers, supporters' pledges and members-only posts.
- GamificationPoints ledger, levels, badges and streaks for an engaged community.
- Mentorship programmeProgrammes matching mentors with mentees, sessions and feedback.
- Activity feed (Cassandra)Each user's feed by time bucket, follower lists both ways, and like counters.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.