The code behind Cotton
Cotton is a family of small apps, each for one thing, over one database that you own. Each app is available on iPhone and Android. This repository holds the source for the apps, the shared core they are built on, the server, and the public website.
Snapshot
62fc9714e0, 2026-11-28. 10713 files. What changed · Every snapshot
Licence
AGPL-3.0-only. Read the licence.
Report a security problem
Write to mukesh@tinfactory.co. Please do not report it in public first.
Get the code
git clone https://code.cottondb.com/cotton.git
- cotton-62fc9714e0.tar.gz
31e20e609cb627e6d8ff66389b1b5a710e83b96c0c49dda8d9ae6431a4b43ec7 - cotton-62fc9714e0.zip
d89874d738198be3c3845e3b0f3e6ccef63f0e1e98494e807099d1005220e341
How to build
Install everything once from the repository root:
pnpm install
To run every package's tests:
pnpm test
Server
Run these from apps/business.
Write the generated assets folder that the Worker serves. The tests also write it, so you can skip this step if you run them first.
pnpm kit
Run the Worker locally with wrangler dev:
pnpm dev
Run the Worker's tests. They run inside the Workers runtime and use no remote services.
pnpm test
Deploy with wrangler deploy, to the Cloudflare account you are logged in to:
pnpm run deploy
Rust core
Build the workspace:
cargo build --manifest-path crates/Cargo.toml --release
Test one crate. Any crate name works in place of cotton-core.
cargo test --manifest-path crates/Cargo.toml -p cotton-core
Run check, clippy with warnings as errors, and every crate's tests in one go:
pnpm rust:verify
iPhone
First build the Rust core as an XCFramework, the packaged form of a library that Xcode links. This command builds it for the simulator only. Drop the flag to build for both device and simulator.
scripts/build-xcframework.sh --simulator-only
Then generate apps/cotton/Cotton.xcodeproj with XcodeGen. The generated project is not checked in.
pnpm ios:project
Open apps/cotton/Cotton.xcodeproj in Xcode, pick an app's scheme (for example books) and a simulator, and run.
To run the iPhone unit tests on a simulator:
pnpm ios:test
Set COTTON_SIM to a simulator's id to choose which one the tests use.
Each app builds in two variants, chosen by the COTTON_FLAVOR environment variable. COTTON_FLAVOR=dev, the default, builds the development variant, which talks to a development server. COTTON_FLAVOR=real builds the release variant.
Android
Build the Rust library first. Run this inside crates/:
cargo ndk -t arm64-v8a -t x86_64 -P 28 build --locked -p cotton-android-jni --profile android-debug
Then copy each libcotton_android_jni.so from the target folder into the Android project:
| From, in the target folder | To |
|---|---|
aarch64-linux-android/android-debug | apps/android/app/src/debug/jniLibs/arm64-v8a |
x86_64-linux-android/android-debug | apps/android/app/src/debug/jniLibs/x86_64 |
The remaining commands run from apps/android. This one builds a single app against the development server as a debug build:
./gradlew :app:assembleBooksDevDebug
The pattern for other builds is :app:assemble<App><Live|Dev><Debug|Release>.
To run the unit tests:
./gradlew :shell:testDebugUnitTest :writing:testDebugUnitTest :app:testBooksDevDebugUnitTest