Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
docs: describe the protected main branch and merging through pull requests
spacesdrive7209e61ca2ec
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 10ae2f0..512811e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -38,6 +38,9 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).### Changed+**Protected main branch**+- `main` only accepts pull requests whose CI check passed on an up-to-date branch, merged with rebase; force pushes and deleting the branch are blocked for everyone (ADR-034)+**Backend request pipeline in layers**- The Worker is organised as middleware, route tables, controllers, services and repositories (`docs/architecture/backend/REQUEST_PIPELINE.md`); every database query is in a repository and every rule in a service- Every failed request answers with one body, `{ success, code, message, requestId }`, and a status that matches the failure: 400 invalid input, 401 sign-in, 404 not found, 409 already added, 429 rate limited, 502 platform error, 503 server not configured, 504 platform timeout, 500 server error. Database and unexpected errors no longer show internal messages; server errors in the app show a request id to quotediff --git a/DECISIONS.md b/DECISIONS.mdindex bc521a4..a5d5ace 100644--- a/DECISIONS.md+++ b/DECISIONS.md@@ -699,3 +699,25 @@ Records every significant architectural decision, the alternatives considered, a- Without Redis there is no count, and Resend's own daily quota (on the free plan) is the cap. A paid Resend plan has no daily quota, so `EMAIL_DAILY_LIMIT` is then the only one.- Supabase calls the hook from its own servers, so the per-IP rate limit cannot tell people apart. The per-address cap, Supabase's email rate limit and optional CAPTCHA protect the daily allowance from one person.- Security notices that hit a cap are skipped instead of failing the change they report.++---++## ADR-034: Protect main with a repository ruleset++**Date:** 2026-10-14+**Status:** Accepted++**Decision:** The ruleset **Protect main** targets the default branch with no bypass actors. It restricts deletion, blocks force pushes, requires linear history, requires a pull request (no approving review, so the owner can merge their own) with rebase or squash merges only, and requires the CI job `Type check, lint, test, build` to pass on a branch that is up to date with `main`.++**Context:** Every push to `main` deploys the Worker and the frontend, but `main` accepted direct pushes, force pushes and deletion, and nothing required CI to pass first. The deploy workflows type-check and test their own app, but not lint, the other app or the Worker bundle.++**Alternatives considered:**+- Classic branch protection rules. Rulesets do the same, can be viewed by anyone with read access, and stack with future rules.+- Requiring one approving review. With one maintainer this would block every merge, since GitHub does not let authors approve their own pull requests.+- An administrator bypass. It would make the rules advisory for the only account that pushes.++**Trade-offs:**+- Small fixes need a branch and a pull request, and wait for CI (about a minute) before they can merge.+- "Up to date" means a pull request opened before another one merged must be rebased (`gh pr update-branch --rebase`) and checked again.+- Rebase merges give commits new hashes, so release tags are created after the merge, on `origin/main`.+- Renaming the CI job requires updating the ruleset in the same change.diff --git a/README.md b/README.mdindex aa6ade8..fe92d41 100644--- a/README.md+++ b/README.md@@ -617,7 +617,7 @@ git commit -m "feat: add your feature description"git push origin feature/your-feature-name```-Please keep pull requests focused: one feature or fix per PR. Avoid unrelated refactors in the same change.+`main` is protected: a pull request merges only after the CI check passes and the branch is up to date, and it is merged with rebase to keep the history linear. Please keep pull requests focused: one feature or fix per PR. Avoid unrelated refactors in the same change.---diff --git a/ROADMAP.md b/ROADMAP.mdindex 1546bef..c7a8f4c 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -30,8 +30,7 @@ What Twiligent is for, and what every change should move forward.## In Progress-1. **Email verification codes** ([#29](https://github.com/spacesdrive/twiligent/issues/29)) - confirm new email accounts with a 6-digit code sent through Resend from a Supabase Send Email hook on the Worker, capped at 100 emails a day, with Google sign-in offered once the day's emails run out.-2. **Backend request pipeline in layers** ([#20](https://github.com/spacesdrive/twiligent/issues/20)) - split the Worker into middleware, route tables, controllers, services and repositories, with a request context (request id, user id, cancellation), security headers, input validation and one error handler.+Nothing at the moment. The next item is picked from Next Up below.---@@ -139,4 +138,7 @@ React Native app using the same Cloudflare Worker backend.- Saving GitHub settings erased the stored token - only the repository is stored now (#13).- Dead code from the migration was removed (#14).- Hidden YouTube like and comment counts pulled averages down, and empty analytics had a different shape (#15).+- Route files mixed HTTP, business rules and queries, errors had three shapes and CORS allowed every origin - the Worker now runs as middleware, route tables, controllers, services and repositories with one error contract (#20).+- Email sign-ups were never confirmed, because Supabase's built-in email service sends only a few emails an hour - accounts are now confirmed with a code sent through Resend, capped at 100 a day (#29).+- `main` had no branch protection - a ruleset now blocks force pushes, deletion and unchecked merges (#35).- Media overlays used hex colours and an undeclared tabs variant (#16).diff --git a/docs/architecture/cloudflare/CI_CD.md b/docs/architecture/cloudflare/CI_CD.mdindex d56f8b6..b1fd95f 100644--- a/docs/architecture/cloudflare/CI_CD.md+++ b/docs/architecture/cloudflare/CI_CD.md@@ -27,6 +27,8 @@ Nothing compiles TypeScript ahead of time: Wrangler and Vite strip the types whi**Required GitHub secrets:** none.+**Required status check.** The repository ruleset **Protect main** requires this job, by its name `Type check, lint, test, build`, to pass on a pull request before it can merge into `main`, with the branch up to date. Renaming the job or the workflow's `name:` breaks that rule, so change the ruleset's required check in the same pull request (Settings, Rules, Rulesets, Protect main). See `docs/workflows/GIT.md` for the other rules.+---### `deploy-backend.yml`diff --git a/docs/workflows/DEPLOYMENT.md b/docs/workflows/DEPLOYMENT.mdindex 8561e84..bdc50c3 100644--- a/docs/workflows/DEPLOYMENT.md+++ b/docs/workflows/DEPLOYMENT.md@@ -2,7 +2,7 @@## Automatic Deployment (Normal Path)-Push to `main` -> GitHub Actions deploys automatically.+A pull request merged into `main` -> GitHub Actions deploys automatically. `main` is protected (`docs/workflows/GIT.md`): it only accepts pull requests whose CI check passed, so merging the pull request is the deploy step.| What changed | Workflow that runs | What it deploys ||---|---|---|diff --git a/docs/workflows/GIT.md b/docs/workflows/GIT.mdindex 67990da..022db92 100644--- a/docs/workflows/GIT.md+++ b/docs/workflows/GIT.md@@ -152,43 +152,58 @@ Tag releases after shipping a meaningful set of changes.### Release process-1. Update `CHANGELOG.md`: move Unreleased section to the new version number with today's date-2. Commit: `release: v1.1.0 - short description of release`-3. Tag: `git tag -a v1.1.0 -m "v1.1.0 - short description"`-4. Push: `git push origin main --tags`+`main` only accepts pull requests (see Branch Strategy), so the release commit goes through one too, and the tag is made on `main` after the merge, because a rebase merge gives the commit a new hash.++1. On a branch, update `CHANGELOG.md`: move the Unreleased section to the new version number with today's date+2. Commit: `release: v1.1.0 - short description of release`, open a pull request and merge it once CI passes+3. Tag the merged commit and push only the tag (tags are not protected)```bash# Example release+git switch -c release/v1.1.0git add CHANGELOG.mdgit commit -m "release: v1.1.0 - Reddit analytics integration"-git tag -a v1.1.0 -m "v1.1.0 - Reddit analytics integration"-git push origin main --tags+git push -u origin release/v1.1.0+gh pr create --fill+# after the pull request is merged+git fetch origin+git tag -a v1.1.0 origin/main -m "v1.1.0 - Reddit analytics integration"+git push origin v1.1.0```---## Branch Strategy-All work goes directly to `main` for small changes and fixes. GitHub Actions deploys automatically on push to `main`.+`main` is protected by the repository ruleset **Protect main** (Settings, Rules, Rulesets). Every change, however small, goes through a branch and a pull request, and GitHub Actions deploys both apps when it lands on `main`.++| Rule | Effect |+|---|---|+| Restrict deletions | `main` cannot be deleted |+| Block force pushes | History on `main` cannot be rewritten |+| Require a pull request before merging | Direct pushes to `main` are refused; no approval is required, so the owner can merge their own pull request |+| Require status checks to pass | The CI job `Type check, lint, test, build` (`.github/workflows/ci.yml`) must pass on the pull request, and the branch must be up to date with `main` |+| Require linear history | Pull requests merge with **Rebase and merge** (preferred, keeps one commit per change with its `Refs #N`) or **Squash and merge**; merge commits are refused |-For larger features that span multiple sessions or commits before they are ready to deploy, use a feature branch:+Nobody bypasses the ruleset, including administrators. Renaming the CI job breaks the status check rule: update the ruleset in the same pull request (see `docs/architecture/cloudflare/CI_CD.md`).```bash-git checkout -b feat/reddit-integration-# work, commit incrementally-git push origin feat/reddit-integration-# merge to main when ready-git checkout main-git merge feat/reddit-integration-git push origin main+git switch -c fix/scheduler-timezone+# work, commit with Refs #N+git push -u origin fix/scheduler-timezone+gh pr create --fill # body lists Closes #N, following .github/pull_request_template.md+gh pr checks --watch # wait for CI+gh pr merge --rebase --delete-branch # once CI passes; this deploys both apps```-A branch can also be merged through a pull request (`gh pr create`); its body lists `Closes #N` for each issue it finishes, following `.github/pull_request_template.md`.+If `main` moved on since the branch was made, the merge is refused until the branch is updated: `gh pr update-branch --rebase`, then wait for CI again.++A pull request can be stacked on another branch when it depends on unmerged work. Set its base to that branch, merge the lower pull request first, then change the upper one's base to `main` (`gh pr edit <n> --base main`) and rebase it before merging.-Delete the branch after merging:+Delete the local branch after merging:```bash-git push origin --delete feat/reddit-integration-git branch -d feat/reddit-integration+git switch main && git pull+git branch -d fix/scheduler-timezone```---diff --git a/docs/workflows/ISSUES.md b/docs/workflows/ISSUES.mdindex 16203ab..fa5f0d2 100644--- a/docs/workflows/ISSUES.md+++ b/docs/workflows/ISSUES.md@@ -61,7 +61,7 @@ gh api -X POST repos/spacesdrive/twiligent/issues/<parent-number>/sub_issues -F## Pull Requests-A change that goes through a branch (see `docs/workflows/GIT.md`) is opened as a pull request. The body lists `Closes #N` for every issue it finishes, so merging closes them. The template in `.github/pull_request_template.md` has the sections.+Every change goes through a branch and a pull request, because `main` is protected and refuses direct pushes (see `docs/workflows/GIT.md`). The body lists `Closes #N` for every issue it finishes, so merging closes them. The template in `.github/pull_request_template.md` has the sections.---