0. the idea

A few small companies I talked to didn't want their internal comms living on Google Workspace or a shared personal inbox, but full email infrastructure — mail servers, SPF/DKIM, the works — was overkill for what they actually needed: a private, internal messaging system that felt like the email client everyone already knows how to use.

Mailbox is that — a self-contained inbox system built to feel like Gmail, running on infrastructure the company controls.

1. architecture

Stack:
  • React (TypeScript) frontend, structured around inbox / thread / compose views
  • Node.js + Express REST API
  • MongoDB for messages, threads, and user data
  • JWT-based authentication with per-organization scoping

2. features

What it does:
  • Inbox, sent, drafts, and custom labels
  • Threaded conversations with nested replies, like a real mail client
  • Full-text search across subject and body
  • File attachments
  • Read/unread state that stays in sync across sessions

3. a challenge — threading

Modeling 'a conversation' in a document database isn't as obvious as it sounds. Embed every reply inside the parent message and a long thread becomes one enormous, slow-to-update document. Store every message as a flat, unrelated document and you lose the ordering and reply-to relationships that make a thread readable.

Store each message as its own document with a threadId and a parentMessageId, and keep a lightweight Thread document that just tracks participants, subject, and the latest message timestamp. That gets fast writes on individual messages and a cheap way to sort the inbox by 'most recently active thread' without touching message bodies.

4. the code

const MessageSchema = new Schema({
  threadId: { type: Schema.Types.ObjectId, index: true },
  parentMessageId: { type: Schema.Types.ObjectId, default: null },
  from: String,
  to: [String],
  body: String,
  sentAt: { type: Date, default: Date.now },
});

const ThreadSchema = new Schema({
  subject: String,
  participants: [String],
  lastMessageAt: { type: Date, index: true },
});

5. what i learned

Building something that mimics an interface people already know intimately is a different kind of hard — nobody notices when the keyboard shortcuts, unread-bolding, and hover states behave exactly like Gmail, but everybody notices the one time it doesn't. Most of the polish time went into those small interaction details, not the backend.