# Modules per team

Large apps have many teams on one release train: one team's bug blocks everyone, and rolling back a
release rolls back everyone's work.

With modules, each team's part of the app (payments, search, loyalty…) **ships, rolls out, is guarded
and rolls back on its own**:

> payments v7 · rolling out 10% → 50%, guarded · search v18 · live · loyalty v3 · stopped by guard (12
> failures), devices back on loyalty v2. Nothing else was touched.

This works with [Re.Pack](https://re-pack.dev), Callstack's bundler for React Native, which splits an
app into chunks and federated modules. Healkite hosts each module's versions and tells every device
which version to load.

**Status: early.** The server, CLI and SDK parts are built and tested, but not yet against a production
Re.Pack app. Try it on a test channel first, and tell us how it goes.

## 1. Load modules through Healkite

```ts
import { ScriptManager } from "@callstack/repack/client";
import Healkite from "react-native-healkite";

Healkite.modules.attach(ScriptManager.shared);
```

The resolver answers only for scripts Healkite has a module for; others go to your existing resolvers.

## 2. Release a module

Build the module with Re.Pack, then publish its output folder:

```sh
npx healkite module release payments \
  --dir build/outputs/android/remotes/payments \
  -c production-… -p android -r 3.0 --guarded
```

Every file in the folder is uploaded (content-addressed, so unchanged files aren't sent twice) except
source maps. `--rollout 20` sets a fixed percentage instead of the guard.

## How devices choose a version

- One small manifest per channel, platform and app version lists, for each module, the current version,
  the one before it, and the rollout percentage.
- Devices in the rollout load the current version; the others keep the previous one.
- If a version fails to load on a device, or its code throws, that device switches to the previous
  version of **that module** and reports the failure.

## The guard

A guarded module release goes 1% → 10% → 50% → 100%, widening after 30 minutes and 20 loads on each
step. It stops (and devices return to the previous version) at 10 failures, or above a 2% failure rate.
Failures are load errors plus uncaught errors whose stack runs through the module's scripts.

In the dashboard, **Modules** shows every module with its versions; turn a version off, back on, or
change its rollout.

## Limits

- Modules must be built for the store build's native code, like any OTA update.
- The module manifest is signed by the server, but the SDK doesn't check that signature yet. Each
  script is fetched by its content hash.
- Module scripts aren't removed automatically when old versions are no longer used.
