Section 19 of 25
Migrating an existing codebase
Contents
You do not need a rewrite. SLAT is adopted in small pull requests that keep the application working the whole time, in an order that does not block other branches.
19.1. The order
- Measure. Map the modules: lines per module, imports that point upward, files that use
tauri::, number of#[tauri::command],staticwith state, fields of the application state,#[cfg]for operating systems. Write it down in a plan in the repository. These numbers are your baselines. - Invert the upward dependencies. Policies that live in the command layer but are called by lower layers move down to
core/<policy>/. Types that the domain borrows from the entry layer (a line channel, an image type, a message string) move to the slice they belong to. The old path stays as apub useuntil the migration ends. - Split
appandcore. Create the workspace and acorecrate withouttauri. Code that knows Tauri stays inapp; everything else moves withgit mv. This is the most mechanical step. - Split out
store,driversandkit. Only when their code is already clean. When you splitdrivers, move operating-system code intoplatform/, and give the platform check its baseline. - Slice by slice. One slice per pull request: commands into
app/<s>/, logic intocore/<s>/in the fixed layout. Start with the smallest and least shared. kit::Jobs. The cancellation maps leave the application state.- Actors. State from the application state and from
staticvariables moves into actors, one flow per pull request, withupdatetests written first against the current behaviour. - Checks. Each step switches on the check for its rule, with a baseline.
19.2. Rules of migration
- Moves do not change behaviour. A pull request that moves code does not fix logic, and a pull request that fixes logic does not move code. When something breaks, you know which kind of change caused it.
- Facades on old paths.
pub use new::place::*;at the old module path lets code you are not allowed to touch (or do not want to touch yet), and your existing tests, compile unchanged. A facade is removed when nothing imports it. - One heavy build at a time. Several parallel
cargobuilds of a large workspace can freeze a laptop. Migrate in one line. - Run the whole test suite after each step, not after each commit. The suite is your proof that nothing moved in behaviour.
19.3. Layout first, a faster start
If findability is your biggest pain, you can reorder the work: first move files into slice folders inside the single existing crate, with no changes to their contents, and leave facades at the old paths. Git records these as renames, so other open branches still merge cleanly. You get the map (the folder of each feature) in a day or two, and the crate split, the layers inside each slice and the actors follow later on top of a layout that is already readable.
Two things are not free even here. Files that use super:: or pub(super) change their parent module when they move, so a few paths need small mechanical fixes. And moving commands out of a central file changes that file, which conflicts with branches that edit it, so it is better done as a separate second step.
19.4. What usually goes wrong
| Problem | What to do |
|---|---|
| Hundreds of tests import old paths | Facades at the old paths. Do not move the tests in the same pull requests. |
Parallel branches conflict with git mv |
Do the crate splits when the fewest branches are open. Every move is its own pull request. |
pub(crate) items are needed from another crate after the split |
Widen them to pub. After the migration, review what can go back to pub(crate). |
| Compile time grows with the number of crates | At most six to eight crates. One heavy build at a time. Measure with cargo build --timings before and after each split (22.6). |
| A refactor quietly changes behaviour | update tests first, against today's behaviour. Moves and fixes in separate pull requests. |
| A part of the code may not change at all (a critical feature, a frozen area) | It stays where it is and reaches the new layout only through facades. Facades are additive code. |