I'll explain how these architectural patterns can work together in an ebook reader app, showing how each addresses different aspects of the system design.
Vertical Slice Architecture in an Ebook Reader
Vertical slice architecture organizes code by features rather than technical layers. For an ebook reader, each feature would contain all the code needed from UI to data access:
Feature: Reading Experience
ReadingView (UI for displaying book content)
ReadingViewModel (presentation logic)
GetBookContentQuery (fetches and formats pages)
UpdateReadingProgressCommand (saves current position)
BookContentRepository (data access)
Feature: Library Management
LibraryView (displays book collection)
ImportBookCommand (handles file imports)
DeleteBookCommand (removes books)
LibraryRepository (manages book metadata)
Feature: Annotations
AnnotationView (highlight/note UI)
CreateAnnotationCommand
GetAnnotationsForPageQuery
AnnotationRepository
Each slice is self-contained, making it easy to modify the annotation system without touching the reading engine or library management code.
Domain Driven Design for Core Business Logic
DDD helps model the ebook reader's core concepts and business rules:
Core Domain Entities:
Book (aggregate root): Contains metadata, chapters, and reading state
ReadingSession: Tracks progress, duration, and user behavior
Annotation: Highlights, notes, and bookmarks with position data
UserPreferences: Font settings, themes, reading modes
Value Objects:
BookPosition: Immutable representation of location in book
PageRange: Start and end positions for a displayed page
ReadingStatistics: Words per minute, time spent, etc.
Domain Services:
PaginationService: Calculates page breaks based on screen size and font
SyncService: Coordinates reading progress across devices
FormatConverter: Handles EPUB, PDF, MOBI conversions
Bounded Contexts:
- Reading Context: Everything related to the reading experience
- Library Context: Book organization and metadata
- Social Context: Sharing, reviews, reading groups
Clean Architecture Layers
Clean architecture ensures dependencies flow inward toward the domain:
Domain Layer (innermost):
interface IBookRepository {
Book GetBook(BookId id);
void SaveReadingProgress(BookId id, BookPosition position);
}
class Book {
public BookId Id { get; }
public ChapterList Chapters { get; }
public BookPosition CurrentPosition { get; private set; }
public void UpdatePosition(BookPosition newPosition) {
// Business rule: position must be within book bounds
if (newPosition.IsValid(this.TotalLength)) {
CurrentPosition = newPosition;
}
}
}
Application Layer:
class TurnPageCommand {
private readonly IBookRepository bookRepo;
private readonly IPaginationService paginator;
public BookPosition Execute(BookId bookId, Direction direction) {
var book = bookRepo.GetBook(bookId);
var newPosition = paginator.CalculateNextPosition(
book,
book.CurrentPosition,
direction
);
book.UpdatePosition(newPosition);
bookRepo.SaveReadingProgress(bookId, newPosition);
return newPosition;
}
}
Infrastructure Layer:
class SqliteBookRepository : IBookRepository {
// Implements persistence using SQLite
// Handles EPUB file parsing
// Manages file system storage
}
Presentation Layer:
class ReadingViewModel {
private readonly TurnPageCommand turnPageCommand;
public void OnSwipeLeft() {
var newPosition = turnPageCommand.Execute(
currentBookId,
Direction.Forward
);
UpdateDisplay(newPosition);
}
}
Combining the Patterns
These patterns complement each other well:
-
Use DDD to model the domain - Define your core entities like Book, Annotation, and ReadingSession with their business rules
-
Apply Clean Architecture for dependencies - Ensure your domain models don't depend on UI frameworks or databases
-
Organize with Vertical Slices - Group related use cases together, so the "Add Bookmark" feature contains everything from UI to database code
For example, the "Sync Reading Progress" feature would be:
- A vertical slice containing all sync-related code
- Using domain entities (Book, ReadingProgress) defined through DDD
- Following clean architecture with the sync logic in the application layer, not depending on specific sync providers
This combination gives you a system that's easy to understand (vertical slices), maintains business logic integrity (DDD), and remains testable and flexible (clean architecture).