Opal Editor is built as a local-first, zero-backend markdown editor and static site publisher. This guide explains the architectural decisions and core systems.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rbbydotdev/opal/llms.txt
Use this file to discover all available pages before exploring further.
High-Level Architecture
Opal Editor follows a local-first architecture with no server dependencies:Core Technologies
Frontend Framework
- React 19.2.0: UI framework with compiler-based optimizations
- TypeScript 5.9.3: Type-safe development
- Vite 6.3.5: Build tool and dev server (
vite.config.ts:14) - Tanstack Router: File-based routing (
main.tsx:8) - Tanstack Query: Server state management
UI Components
- shadcn/ui: Built on Radix UI primitives
- Tailwind CSS: Utility-first styling
- Lucide React: Icon library
- MDX Editor: WYSIWYG markdown editing
- CodeMirror 6: Source code editing with Vim mode support
Data & Storage
- Dexie 4.0.10: IndexedDB wrapper (
src/data/index.ts:9) - IndexedDB: Primary persistence layer
- OPFS: Origin Private File System for filesystem access
- Lightning FS: In-memory filesystem fallback
Build & Processing
- marked: Markdown parsing and rendering
- gray-matter: Frontmatter parsing
- rehype/remark: Unified ecosystem for content transformation
- Eleventy (in-browser): Static site generation
- Template Engines: Mustache, Nunjucks, Liquid, EJS
Git Integration
- isomorphic-git: Pure JavaScript Git implementation
- Octokit: GitHub API client
Deployment
- Cloudflare SDK: Cloudflare Pages deployment
- Vercel SDK: Vercel deployment
- AWS SDK S3: S3 deployment
- zip.js: Archive creation for deployments
Core Systems
1. Workspace System
TheWorkspace class (src/workspace/Workspace.ts:74) is the central orchestrator:
- File management through virtual disk abstraction
- Git operations via
GitRepo - Image optimization and caching
- Remote authentication for GitHub/deployment services
2. Virtual Filesystem (Disk Abstraction)
Opal uses a unified filesystem abstraction (src/data/disk/Disk.ts:36):
- IndexedDbDisk: Uses
@isomorphic-git/lightning-fsbacked by IndexedDB - OPFSDirMountDisk: Uses Origin Private File System for better performance
- NullDisk: Fallback when no storage is available
TranslateFs: Path translation and routingNamespacedFs: Namespace isolation for multi-workspaceMutexFs: Concurrency controlHideFs: Hide.gitand other special directories
3. Service Worker Architecture
The service worker (src/lib/service-worker/sw-hono.ts:33) uses Hono as a router:
- Intercept and handle file:// requests
- Enable offline functionality
- Process images without server
- Render markdown on-demand
- Export workspaces as encrypted zips
4. Database Schema (Dexie)
The database (src/data/index.ts:12) stores application state:
workspaces: Workspace metadata, disk references, Git configdisks: Virtual disk configurations (type, paths, handles)builds: Build history and artifactsdeployments: Deployment records linked to buildsremoteAuths: OAuth tokens for GitHub, Netlify, Verceldestinations: Deployment targets (Netlify, Vercel, Cloudflare, S3)historyDocs: Document edit history with operational transforms
5. Git Repository System
TheGitRepo class (src/features/git-repo/GitRepo.ts:1) wraps isomorphic-git:
- Full Git operations in the browser
- GitHub integration via OAuth device flow
- Conflict detection and resolution
- Branch management
- Remote sync with CORS proxy support
6. Build System
The build system (src/services/build/) generates static sites:
- Freeform: Direct markdown-to-HTML with template engines
- Eleventy: Full Eleventy 3.0 running in-browser via web worker
- Mustache (
mustache) - Nunjucks (
nunjucks) - Liquid (
liquidjs) - EJS (
eta) - Markdown (
marked+ frontmatter)
7. Editor System
Opal provides multiple editor modes: Markdown Editor (src/editors/markdown/):
- WYSIWYG editing via
@mdxeditor/editor - Toolbar with formatting options
- Image upload and embedding
- Live preview
src/editors/source/):
- CodeMirror 6 with syntax highlighting
- Language support: JS, CSS, HTML, YAML, JSON, Markdown
- Vim mode support
- Template language syntax (Mustache, Liquid, Nunjucks, EJS)
src/editors/history/):
- Tracks document changes in IndexedDB
- Operational transform for conflict resolution
- Diff visualization
Data Flow
File Read Flow
Build & Deploy Flow
Image Upload Flow
File System Architecture
Opal’s filesystem is designed for flexibility and browser compatibility:Storage Options
-
IndexedDB (Default)
- Works everywhere
- Uses
@isomorphic-git/lightning-fs - Good performance for small-to-medium workspaces
-
OPFS Directory Mount (Recommended)
- Best performance
- Uses native filesystem APIs
- Chrome/Edge only (requires
FileSystemDirectoryHandleAPI)
-
Memory (Fallback)
- When IndexedDB is unavailable
- Data lost on page refresh
Virtual Filesystem Layers
EachDisk wraps the base filesystem with transformation layers:
- HideFs: Hide directories from file tree (
.git,.opal) - MutexFs: Prevent concurrent access issues
- NamespacedFs: Isolate workspaces by prepending namespace to paths
- TranslateFs: Map virtual paths to physical paths
Event System
Opal uses a typed event system for cross-component communication:DiskEvents: File create, update, delete, renameWorkspaceEvents: Workspace rename, deleteGitRepoEvents: Commit, push, pull, branch changes
Security Considerations
Data Privacy
- All data stored locally: No server means no data leaves your browser
- Encryption: Workspace export supports AES and ZipCrypto encryption
- OAuth tokens: Stored in IndexedDB, only sent to official APIs
Remote Auth
- GitHub: OAuth device flow
- Netlify/Vercel/Cloudflare: Personal access tokens
- AWS S3: Access key + secret (encrypted in IndexedDB)
Content Security
- DOMPurify for sanitizing rendered HTML
- Service Worker same-origin enforcement
- No eval() or dangerous dynamic code execution
Performance Optimizations
React Compiler
Automatic memoization viababel-plugin-react-compiler eliminates manual useMemo/useCallback.
Code Splitting
Vite automatically splits code by route using dynamic imports.Web Workers
- Build processes run off main thread
- Image conversion in workers
- Git operations non-blocking
Virtual Scrolling
- File tree uses
@tanstack/react-virtual - Large file lists render only visible items
Debounced Operations
- Auto-save debounced to 500ms
- Search debounced to 300ms
- File tree indexing batched
Development Philosophy
Local-First
All features work offline. Remote features (Git, deploy) are optional enhancements.Zero Backend
No server infrastructure means:- No hosting costs
- No server maintenance
- No downtime
- Complete data ownership
Progressive Enhancement
- Core features work in all modern browsers
- OPFS enhances performance where available
- Service workers enable advanced features
Next Steps
Now that you understand the architecture:- Explore the Development Setup to start contributing
- Check the
src/directory structure to find specific implementations - Read inline code comments for detailed logic explanations