Skip to main content

Architecture Overview

Time Capsule is a Progressive Web App that recreates the 1990s Unix CDE (Common Desktop Environment) desktop experience. The architecture follows a modular, event-driven design pattern built on modern web technologies.

System Design

The application follows a layered architecture with clear separation of concerns:

Core Principles

1. Modular Architecture

Each core system is implemented as an independent module with a well-defined interface. This promotes code reusability and maintainability.

2. Event-Driven Communication

Components communicate through custom events dispatched on the window object, promoting loose coupling:

3. Singleton Pattern for Core Systems

Core systems use the singleton pattern to ensure single instances throughout the application lifecycle:

4. Progressive Enhancement

The application provides a functional experience even with limited JavaScript, with enhanced features loading progressively.

Core Components

WindowManager

Handles all window lifecycle operations including creation, positioning, focus management, and z-index ordering. Key Responsibilities:
  • Window registration and lifecycle management
  • Drag and drop functionality
  • Z-index management (base: 10000 for windows, 90000 for modals)
  • Focus management with click and point-to-focus modes
  • Window state persistence (position, maximized state)
  • Workspace management (4 virtual desktops)
  • Mobile-specific centering and constraints
See Window Manager for detailed documentation.

Virtual Filesystem (VFS)

Provides a POSIX-like filesystem abstraction in browser memory with O(1) path lookups. Key Features:
  • Hierarchical folder structure
  • File metadata (size, mtime, owner, permissions)
  • CRUD operations (touch, mkdir, rm, rename, move, copy)
  • Trash functionality
  • Search with recursive option
  • Event notifications on changes
See Virtual Filesystem for detailed documentation.

SettingsManager

Centralized configuration management with persistent storage. Features:
  • Unified settings storage
  • Version-aware cache management
  • Migration from legacy localStorage keys
  • Section-based organization (theme, mouse, keyboard, beep, session, desktop)
  • Window session persistence
See Storage Management for detailed documentation.

AudioManager

Retro audio system using Web Audio API for classic CDE system sounds. Capabilities:
  • Lazy AudioContext initialization (on first user gesture)
  • System beeps with configurable frequency/duration
  • UI feedback sounds (click, error, success)
  • Window operation sounds (open, close, minimize, maximize, shade)
  • Melody playback for startup chimes
  • Volume control

StyleManager

Orchestrates multiple style modules for system customization. Modules:
  • ThemeModule: Color palette management (CDE palettes)
  • FontModule: Font family and sizing controls
  • MouseModule: Cursor settings and acceleration
  • KeyboardModule: Keyboard repeat and shortcuts
  • BeepModule: Audio feedback settings
  • BackdropModule: Wallpaper/backdrop management with XPM parsing
  • WindowModule: Window behavior (focus mode, opaque dragging)
  • ScreenModule: Screen settings
  • StartupModule: Boot sequence customization

Configuration System

Centralized configuration in config.ts provides type-safe access to all system constants:

Data Flow Patterns

Window Creation Flow

Settings Persistence Flow

VFS Operation Flow

Performance Considerations

Z-Index Management

Z-index allocation uses separate counters for different layers:
This ensures modals always appear above regular windows, preventing z-index conflicts.

Memory-Optimized VFS

The VFS uses a flattened Map for O(1) path resolution instead of traversing a tree structure:

Window Position Normalization

Window positions are normalized on viewport resize to ensure they remain accessible:

Error Handling

Graceful degradation is implemented throughout:

Type Safety

Strong TypeScript typing throughout the codebase:

Global Exposure

Core systems are exposed globally for debugging and feature access:

Next Steps

Window Manager

Deep dive into window management implementation

Virtual Filesystem

Learn about the VFS architecture and operations

Storage

Understand persistent data storage with IndexedDB

Development

Start building features for Time Capsule