Static Email Application

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-23

Problem Statement

Design a Static Email Application that allows users to compose, send, receive, view, and manage emails within a controlled environment (e.g., internal company app or offline prototype).


The system should model the core components of an email system — users, messages, inboxes, and folders — while focusing on clean object-oriented design and extensibility.


🔹 Problem Context


Unlike a full-fledged live email system (like Gmail), a static email application focuses on modeling the structure and flow of emails without actual network communication (SMTP/IMAP).


It should simulate:


•Sending and receiving messages between users.
•Managing inbox, sent, and draft folders.
•Supporting operations like read/unread, delete, and search.


This is a common LLD question to assess your object-oriented modeling, relationships, and use of design patterns.


✅ Functional Requirements


User Management

•Users can register and have unique email IDs.
•Each user can have:
•Inbox
•Sent folder
•Drafts folder
•Trash folder

Email Composition

•Users can compose an email with:
•Subject
•Body
•Sender
•One or more recipients (To, CC, BCC optional)
•Attachments (optional, can be abstracted as file names)

Email Actions

•Send Email: Moves email from sender’s “Drafts” to “Sent” and adds a copy to recipients’ “Inbox”.
•Delete Email: Moves email to “Trash”.
•Mark as Read/Unread: Change status of an email.
•Search Emails: Filter by subject, sender, or keywords.
1.Folders & Organization
•Users can view emails in different folders (Inbox, Sent, Drafts, Trash).
•Allow moving or archiving emails between folders.

Email Status & Metadata

•Each email should store:
•ID, sender, recipients, subject, body, timestamp
•Status (Read/Unread, Deleted)


⚙️ Non-Functional Requirements


Aspect with Description


Simplicity

Should be easy to understand and extend for new features.


Extensibility

Support adding features like archiving, tagging, or spam filtering later.


Maintainability

Clean separation of classes for users, emails, and folders.


Performance

Efficient lookup and search of emails for a user.


Persistence (Optional)

Can simulate database with in-memory storage.


🧩 Core Classes and Responsibilities


Class and Responsibility


User

Represents an email user with a name, email ID, and folders (Inbox, Sent, etc.).


Email

Represents a single email with sender, recipients, subject, body, timestamp, and status.


Folder

Stores and manages a collection of emails (Inbox, Sent, Drafts, Trash).


EmailService

Handles core operations like sending, receiving, deleting, and searching emails.


Attachment (optional)

Represents an attachment in an email.


EmailStatus (enum)

Defines states like READ, UNREAD, DELETED, ARCHIVED.


SearchService (optional)

Provides search and filtering functionality.


🧠 Key Design Considerations


•Use Composition to model the relationship between User and Folder.
•Use Encapsulation to hide folder details from direct manipulation.
•Apply Factory Pattern if creating email objects with complex metadata.
•Use Singleton Pattern for the EmailService managing all send/receive operations.
•Use Enum for email statuses and folder types.


💻 Example Scenario


1.User A creates an email to User B with a subject and body.
2.When User A clicks “Send”:
•The email moves from Drafts → Sent folder for User A.
•A copy is added to User B’s Inbox.
3.User B opens and reads the email → status changes to READ.
4.User B deletes the email → moved to Trash.
5.Later, User B can search their inbox for specific keywords.


🧾 Extension Ideas


•Add threaded conversations (emails grouped by subject or message chain).
•Implement tags/labels for categorizing emails.
•Add spam detection or priority inbox logic.
•Integrate with a template engine for composing emails.


💬 Interview Prompt Summary

Design a Static Email Application that allows users to compose, send, receive, and organize emails into folders.
Focus on object-oriented modeling, class design, and relationships (User–Email–Folder).
You should handle operations like sending, deleting, marking read/unread, and searching emails.


Solution

Comments