|
| 1 | +# Contributing to SubTrackr |
| 2 | + |
| 3 | +Thank you for taking the time to contribute SubTracker. This document covers everything you need to know to contribute to this project |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Development Setup](#development-setup) |
| 10 | +- [Code Style Guidelines](#code-style-guidelines) |
| 11 | +- [Commit Message Conventions](#commit-message-conventions) |
| 12 | +- [Branch Naming Conventions](#branch-naming-conventions) |
| 13 | +- [Pull Request Process](#pull-request-process) |
| 14 | +- [Testing Requirements](#testing-requirements) |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Development Setup |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | + |
| 22 | +| Tool | Version | Purpose | |
| 23 | +|------|---------|---------| |
| 24 | +| Node.js | 20+ | Mobile app development | |
| 25 | +| npm | bundled with Node | Package management | |
| 26 | +| Rust | 1.77+ | Smart contract development | |
| 27 | +| Expo CLI | latest | Running and building the app | |
| 28 | +| Soroban CLI | latest | Deploying/interacting with contracts | |
| 29 | + |
| 30 | +### Mobile App Setup |
| 31 | + |
| 32 | +```bash |
| 33 | +# Install dependencies |
| 34 | +npm install --legacy-peer-deps |
| 35 | + |
| 36 | +# Start the Expo development server |
| 37 | +npx expo start |
| 38 | + |
| 39 | +# Run on Android |
| 40 | +npm run android |
| 41 | + |
| 42 | +# Run on iOS |
| 43 | +npm run ios |
| 44 | +``` |
| 45 | + |
| 46 | +### Smart Contracts Setup |
| 47 | + |
| 48 | +```bash |
| 49 | +# Install the Rust toolchain with required components |
| 50 | +rustup component add rustfmt clippy |
| 51 | + |
| 52 | +# Build contracts |
| 53 | +npm run contracts:build |
| 54 | + |
| 55 | +# Run contract tests |
| 56 | +npm run contracts:test |
| 57 | +``` |
| 58 | + |
| 59 | +### Environment Variables |
| 60 | + |
| 61 | +Create a `.env` file at the project root if needed: |
| 62 | + |
| 63 | +| Variable | Description | |
| 64 | +|----------|-------------| |
| 65 | +| `STELLAR_NETWORK` | `testnet` or `public` | |
| 66 | +| `CONTRACT_ID` | Deployed Soroban subscription contract ID | |
| 67 | +| `WEB3AUTH_CLIENT_ID` | Web3Auth client ID for social login | |
| 68 | + |
| 69 | +### Generating Contract TypeScript Types |
| 70 | + |
| 71 | +After modifying any ABI files in `src/contracts/abis/`, regenerate the TypeScript bindings and commit the result: |
| 72 | + |
| 73 | +```bash |
| 74 | +npm run contracts:codegen |
| 75 | +``` |
| 76 | + |
| 77 | +The CI pipeline checks that committed types match the ABI — always run this before pushing if you changed any ABI. |
| 78 | + |
| 79 | +### Running All CI Checks Locally |
| 80 | + |
| 81 | +```bash |
| 82 | +npm run ci |
| 83 | +``` |
| 84 | + |
| 85 | +This runs lint, type check, tests, contract tests, Rust formatting, and Clippy in sequence. |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Code Style Guidelines |
| 90 | + |
| 91 | +### TypeScript / React Native |
| 92 | + |
| 93 | +Formatting is enforced by **Prettier** and linting by **ESLint**. The configuration is in `.prettierrc` and `.eslintrc.json`. |
| 94 | + |
| 95 | +Key rules: |
| 96 | + |
| 97 | +- **Indentation**: 2 spaces (no tabs) |
| 98 | +- **Quotes**: single quotes (`'`) |
| 99 | +- **Semicolons**: required |
| 100 | +- **Trailing commas**: ES5 style (objects and arrays only) |
| 101 | +- **Print width**: 100 characters |
| 102 | +- **Line endings**: LF |
| 103 | + |
| 104 | +ESLint rules to be aware of: |
| 105 | + |
| 106 | +- `@typescript-eslint/no-unused-vars` — unused variables are errors; prefix intentionally unused params with `_` |
| 107 | +- `@typescript-eslint/no-explicit-any` — `any` types produce a warning; use proper types |
| 108 | +- `no-console` — `console.log` is a warning; only `console.warn` and `console.error` are allowed |
| 109 | + |
| 110 | +**Auto-fix before committing:** |
| 111 | + |
| 112 | +```bash |
| 113 | +npm run lint:fix # fix ESLint issues |
| 114 | +npm run format # apply Prettier formatting |
| 115 | +``` |
| 116 | + |
| 117 | +**Check without modifying:** |
| 118 | + |
| 119 | +```bash |
| 120 | +npm run lint |
| 121 | +npm run format:check |
| 122 | +npm run typecheck |
| 123 | +``` |
| 124 | + |
| 125 | +### Rust (Smart Contracts) |
| 126 | + |
| 127 | +- Follow standard Rust idioms and the output of `cargo fmt` |
| 128 | +- All Clippy warnings (`-D warnings`) must be resolved |
| 129 | +- Keep contract logic in `contracts/src/lib.rs` well-documented |
| 130 | + |
| 131 | +```bash |
| 132 | +npm run contracts:fmt # check formatting |
| 133 | +npm run contracts:clippy # run linter |
| 134 | +``` |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Commit Message Conventions |
| 139 | + |
| 140 | +This project uses **Conventional Commits**. Every commit message must follow this format: |
| 141 | + |
| 142 | +``` |
| 143 | +<type>(<scope>): <short description> |
| 144 | +
|
| 145 | +[optional body] |
| 146 | +
|
| 147 | +[optional footer(s)] |
| 148 | +``` |
| 149 | + |
| 150 | +### Types |
| 151 | + |
| 152 | +| Type | When to use | |
| 153 | +|------|-------------| |
| 154 | +| `feat` | New feature | |
| 155 | +| `fix` | Bug fix | |
| 156 | +| `chore` | Maintenance, dependency updates, tooling | |
| 157 | +| `docs` | Documentation only | |
| 158 | +| `refactor` | Code change that is neither a fix nor a feature | |
| 159 | +| `test` | Adding or updating tests | |
| 160 | +| `style` | Formatting, whitespace — no logic change | |
| 161 | +| `ci` | CI/CD configuration changes | |
| 162 | +| `perf` | Performance improvement | |
| 163 | + |
| 164 | +### Scope (optional but encouraged) |
| 165 | + |
| 166 | +Use the area of the codebase affected: `contracts`, `store`, `screens`, `navigation`, `services`, `hooks`, `ui`, `wallet`, `notifications`. |
| 167 | + |
| 168 | +### Examples |
| 169 | + |
| 170 | +``` |
| 171 | +feat(contracts): add grace period logic to billing cycle |
| 172 | +fix(store): prevent duplicate subscription entries on rehydration |
| 173 | +chore(deps): bump ethers to 5.8.0 |
| 174 | +docs: add environment variable table to README |
| 175 | +test(store): add unit tests for subscriptionStore selectors |
| 176 | +refactor(screens): extract shared form logic into useSubscriptionForm hook |
| 177 | +ci: cache Rust build artifacts in contracts jobs |
| 178 | +``` |
| 179 | + |
| 180 | +### Rules |
| 181 | + |
| 182 | +- Use the imperative mood in the description ("add" not "added" or "adds") |
| 183 | +- Do not capitalize the first letter of the description |
| 184 | +- No period at the end of the description |
| 185 | +- Keep the subject line under 72 characters |
| 186 | +- Reference GitHub issues in the footer: `Closes #123` or `Refs #456` |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +## Branch Naming Conventions |
| 191 | + |
| 192 | +Branches must follow this pattern: |
| 193 | + |
| 194 | +``` |
| 195 | +<type>/<short-description> |
| 196 | +``` |
| 197 | + |
| 198 | +Use the same types as commit messages. The description should be kebab-case. |
| 199 | + |
| 200 | +### Examples |
| 201 | + |
| 202 | +``` |
| 203 | +feat/grace-period-billing |
| 204 | +fix/duplicate-subscription-rehydration |
| 205 | +chore/bump-expo-53 |
| 206 | +docs/soroban-deployment-guide |
| 207 | +test/subscription-store-unit-tests |
| 208 | +refactor/wallet-service-error-handling |
| 209 | +``` |
| 210 | + |
| 211 | +### Protected Branches |
| 212 | + |
| 213 | +| Branch | Purpose | |
| 214 | +|--------|---------| |
| 215 | +| `main` | Production-ready code — all CI must pass, PR required | |
| 216 | +| `dev` / `develop` | Integration branch — CI required | |
| 217 | + |
| 218 | +Never commit directly to `main`. All changes must go through a pull request. |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +## Pull Request Process |
| 223 | + |
| 224 | +### Before Opening a PR |
| 225 | + |
| 226 | +1. Run `npm run ci` locally and fix any failures |
| 227 | +2. Ensure your branch is up to date with `main` |
| 228 | +3. Write or update tests for any changed behaviour |
| 229 | +4. Regenerate contract types if ABIs changed (`npm run contracts:codegen`) |
| 230 | + |
| 231 | +### PR Requirements |
| 232 | + |
| 233 | +All of the following CI jobs must pass before a PR can be merged: |
| 234 | + |
| 235 | +| Check | Command | |
| 236 | +|-------|---------| |
| 237 | +| Prettier format | `npm run format:check` | |
| 238 | +| ESLint | `npm run lint` | |
| 239 | +| TypeScript type check | `npm run typecheck` | |
| 240 | +| Jest tests | `npm test` | |
| 241 | +| Expo build | `npm run build` | |
| 242 | +| Rust formatting | `npm run contracts:fmt` | |
| 243 | +| Rust Clippy | `npm run contracts:clippy` | |
| 244 | +| Rust tests | `npm run contracts:test` | |
| 245 | + |
| 246 | +### PR Checklist |
| 247 | + |
| 248 | +The PR template (`.github/PULL_REQUEST_TEMPLATE.md`) will be pre-filled when you open a PR. Make sure all boxes are checked before requesting review: |
| 249 | + |
| 250 | +- All CI checks pass |
| 251 | +- New code has appropriate TypeScript types |
| 252 | +- No hardcoded secrets or credentials |
| 253 | +- New features have corresponding tests |
| 254 | +- Documentation updated if needed |
| 255 | + |
| 256 | +### Review |
| 257 | + |
| 258 | +- At least **1 approval** is required before merging |
| 259 | +- Address all review comments before re-requesting review |
| 260 | +- Stale reviews are dismissed automatically when new commits are pushed |
| 261 | + |
| 262 | +--- |
| 263 | + |
| 264 | +## Testing Requirements |
| 265 | + |
| 266 | +### TypeScript / React Native Tests |
| 267 | + |
| 268 | +- Tests live alongside source files or in `__tests__` directories |
| 269 | +- Test files must match: `**/*.test.{ts,tsx}` or `**/*.spec.{ts,tsx}` |
| 270 | +- Use the `@/` path alias for imports from `src/` (e.g. `import { foo } from '@/utils/formatting'`) |
| 271 | + |
| 272 | +```bash |
| 273 | +npm test # run all tests |
| 274 | +npm run test:coverage # run with coverage report |
| 275 | +``` |
| 276 | + |
| 277 | +Coverage is collected from all files under `src/**/*.{ts,tsx}`, excluding `.d.ts` and barrel `index.ts` files. |
| 278 | + |
| 279 | +**What to test:** |
| 280 | + |
| 281 | +- State store logic (Zustand actions and selectors) |
| 282 | +- Utility functions (`src/utils/`) |
| 283 | +- Service layer functions where possible |
| 284 | +- New screens should have at least a smoke-render test |
| 285 | + |
| 286 | +### Rust Contract Tests |
| 287 | + |
| 288 | +- Tests live in `contracts/src/lib.rs` using the standard `#[cfg(test)]` module |
| 289 | +- All contract logic must have corresponding tests |
| 290 | + |
| 291 | +```bash |
| 292 | +npm run contracts:test |
| 293 | +# or directly: |
| 294 | +cd contracts && cargo test --verbose |
| 295 | +``` |
| 296 | + |
| 297 | +**What to test:** |
| 298 | + |
| 299 | +- Happy-path contract invocations |
| 300 | +- Edge cases (zero amounts, expired subscriptions, unauthorized callers) |
| 301 | +- Error conditions and expected panics |
| 302 | + |
| 303 | +### General Guidelines |
| 304 | + |
| 305 | +- Do not commit tests that are skipped (`test.skip`, `xit`) without a comment explaining why |
| 306 | +- Mock only what is strictly necessary; prefer testing real behaviour |
| 307 | +- Keep test descriptions specific enough to diagnose failures without reading the test body |
0 commit comments