How Lix Works
Lix is a change control system designed to run in the browser. This page provides an overview of the core architecture and how the different components interact.
Core Architecture
At its core, Lix combines:
- A SQLite database (running in WebAssembly)
- A type-safe SQL query builder (Kysely)
- A plugin system for handling different file formats
- A change detection and tracking system
This architecture allows Lix to provide powerful change control capabilities within the browser environment.
Component Overview
Database Layer
Lix uses a SQLite database running in WebAssembly to store all data. The database schema includes tables for:
- Files
- Changes
- Snapshots
- Versions
- Labels
- Threads (discussions)
- And more...
The database is the source of truth for all data in a Lix application.
SQL Query Interface
All interactions with the Lix database happen through Kysely, a type-safe SQL query builder. This provides:
- Type safety with TypeScript
- SQL-based queries (no new query language to learn)
- Powerful filtering and aggregation capabilities
Plugin System
Plugins in Lix handle specific file formats, providing:
- Change Detection: Understanding what changed between different versions of a file
- Schema Definition: Defining the data model for the file format
- Change Application: Applying changes to files
Different plugins handle different file formats:
Change Detection Flow
When a file is updated in Lix, the following process occurs:
- The file is written to the database
- The file-queue system detects the change
- The appropriate plugin analyzes the old and new versions
- The plugin generates change records describing what changed
- The changes are stored in the database
- The snapshot system groups related changes together
This flow ensures that every modification to a file is tracked and can be queried later.
Usage Flow
The typical flow for using Lix in an application is:
- Initialize Lix: Create or open a Lix file with required plugins
- Insert/Update Files: Add or modify files in the Lix database
- Query Changes: Retrieve information about what changed
- Manage Versions: Create and switch between different versions
- Merge Changes: Combine changes from different versions
All of these operations are performed through the SQL interface, providing a consistent and powerful API for managing changes.
Memory Model
Lix is designed to work in memory by default, but can be synchronized with persistent storage systems:
- In-Memory Mode: All data is stored in memory
- File Persistence: Changes can be serialized to disk
- Remote Sync: Changes can be synchronized with remote servers
This design allows Lix to work in a variety of environments, from fully offline to collaborative online applications.
Next Steps
Now that you understand how Lix works at a high level, you can explore the core concepts in more detail:
- Files - Learn about the primary data containers
- Changes - Understand how changes are tracked
- Versions - See how different states are managed