How livebook-dev/livebook works
Main Components
• Frontend/Client-side: Represented by the assets directory containing JavaScript, CSS, and CodeMirror integrations. This is where the interactive code editor (with autocompletion, inline documentation, and UI hooks) lives.
• Web Server & Phoenix Components: In the lib/livebook_web directory you have controllers, live views, channels, plugs, and router; these routes are the main interface for requests coming from users.
• Application Core and Business Logic: Found in lib/livebook and subdirectories. This includes the notebook management (cells, markdown, state tracking), runtimes, evaluator modules, and deployment supervisors.
• Runtime & Code Evaluation: Modules in lib/livebook/runtime and lib/livebook/runtime/evaluator. These components are responsible for spawning evaluators, managing attached nodes, and handling code execution.
• File System & Storage: The file system modules (under lib/livebook/file_system, local and S3 implementations) handle notebook storage and possibly integrations with external storage.
• Real-time Collaboration: LiveView components, channels (e.g., js_view_channel) and session management modules define how multiple users can work simultaneously on a notebook.
• External Services Integration: Integration with Kino for rich interactive outputs (e.g., charts, tables), along with support for authentication via various methods (basic_auth, cloudflare, google_iap, tailscale, custom modules).
• Deployment & Packaging Tools: Several directories (rel/app/macos, rel/app/windows, Dockerfile, .github workflows) indicate that the project is packaged as both a Docker image and desktop standalone apps for macOS/Windows. There’s also clustering support noted via environment variables and OTP-based distribution.
Component Relationships and Data Flow
• Live views and channels coordinate real-time interactions (such as collaborative notebook editing) between multiple users.
• Controllers invoke business logic from the core “livebook” modules for notebook state changes, file system actions, and runtimes.
• The runtime layer receives code snippets and dispatches them to evaluator processes (which may run on local or attached nodes) and then streams back results.
• The file system layer (local or S3) persists and loads notebooks. This is used by components in both the web server and runtime layers.
• Deployment packaging components show how the application can be built and deployed in different runtime environments (Docker, standalone desktop apps, and clustering setups).
Architectural Patterns and Principles
• MVC with Phoenix: Clearly split between controllers/views (web logic) and business logic (domain modules in lib/livebook).
• Real-time, event-driven design: Use of LiveView and Phoenix Channels to push and receive updates.
• Supervision Trees: The Elixir/OTP architecture (application, supervisor trees) is used for fault-tolerance and managing evaluator processes.
• Extensibility and Customization: The use of configuration files (config/*) and environment variables allow a highly customizable runtime behavior (e.g., custom runtimes, authentication configuration).
• Packaging and Deployment: Separate build scripts and deployment descriptors (Dockerfiles, rel/ directories, GitHub workflows) document various deployment methods.
Relevant Technologies & Frameworks
• Elixir, Phoenix Framework, and OTP-based applications.
• CodeMirror (for rich code editor support), Kino (for interactive visualizations).
• Docker (for container deployments) and native build scripts for macOS/Windows desktop apps.
• Testing frameworks and protocols (protobuf files in the proto folder) suggest that message-driven or inter-process communication may also be depicted.
Capturing Essential Architectural Elements
• To capture the boundaries between user interaction, business logic, and code execution.
• Supporting development & deployment directories (like rel/, Dockerfile, GitHub workflows) as contextual components, perhaps in an “Infrastructure & Deployment” section.
• How environment variables and the configuration files (under config/) control various runtime behaviors.