Skip to content

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(workflow): track every change with a GitHub issue

spacesdrive687c73d25ae3
diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md
new file mode 100644
index 0000000..83c1c40
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug.md
@@ -0,0 +1,19 @@
+---
+name: Bug
+about: Something does not work as documented
+labels: bug
+---
+
+<!-- One short paragraph: what is broken and where. Never paste tokens, keys or personal data. -->
+
+## Steps to reproduce
+
+1.
+
+## What happened
+
+## What was expected
+
+## Done when
+
+<!-- The fix is verified by: a test, a manual check, a production check. -->
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..6b1ed9f
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: true
+contact_links:
+ - name: Documentation
+ url: https://twiligent.ujjwal.fyi/docs
+ about: Setup, self-hosting and usage guides
diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md
new file mode 100644
index 0000000..4d19d90
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature.md
@@ -0,0 +1,15 @@
+---
+name: Feature or change
+about: New feature, refactor, documentation or tooling work
+labels: enhancement
+---
+
+<!-- One short paragraph: the goal and why it matters. -->
+
+## Tasks
+
+- [ ]
+
+## Done when
+
+<!-- How completion is verified: checks that pass, behaviour that can be seen. -->
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..714c0ce
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,14 @@
+## Summary
+
+<!-- What changed and why, in a few lines. -->
+
+## Issues
+
+Closes #
+
+## Verification
+
+- [ ] `npm run lint`
+- [ ] `npm test`
+- [ ] `npm run build`
+- [ ] Docs updated per the Documentation Maintenance Policy in `CLAUDE.md`
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 455b23e..b872807 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,11 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
+**Issue tracking for every change**
+- Every task is tracked by a GitHub issue that is opened before work starts and closed when it is complete; commits reference it with `Refs #N` or `Closes #N`
+- Issue templates, a pull request template and `docs/workflows/ISSUES.md` describe the lifecycle, labels and `gh` commands
+- `ROADMAP.md` now starts with the project goals and links in-progress items to their issues
+
**Sign in with Google**
- Continue with Google on the sign-in page, using Google's own button and a nonce-checked ID token sent to Supabase; shown only when `VITE_GOOGLE_CLIENT_ID` is set
- Docs page for administrators: branding, audience, scopes, client, Supabase provider and brand verification
diff --git a/README.md b/README.md
index 4e176d5..72341fc 100644
--- a/README.md
+++ b/README.md
@@ -551,7 +551,7 @@ Twiligent is different on each point:
## Contributing
-Contributions are welcome. For significant changes, open an issue first to discuss the approach.
+Contributions are welcome. Every change starts with a GitHub issue: search the [open issues](https://github.com/spacesdrive/twiligent/issues) first, and open one if nothing covers your change. Commits and pull requests reference it (`Refs #N`, `Closes #N`); see `docs/workflows/ISSUES.md`.
1. Fork the repository from [github.com/spacesdrive/twiligent](https://github.com/spacesdrive/twiligent)
2. Create a feature branch
@@ -566,7 +566,7 @@ git checkout -b feature/your-feature-name
git commit -m "feat: add your feature description"
```
-4. Push and open a pull request
+4. Push and open a pull request whose description lists `Closes #N` for the issue
```bash
git push origin feature/your-feature-name
diff --git a/ROADMAP.md b/ROADMAP.md
index 6f52e98..bc2036c 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -1,96 +1,74 @@
# Roadmap
-Planned features, improvements, and known gaps. Items within each section are roughly prioritized - top items first.
+Goals, work in progress, planned features and known gaps. Items within each section are roughly prioritized - top items first.
-Update this file whenever a feature ships (move to CHANGELOG.md) or when priorities change.
+Every item that is being worked on has a GitHub issue (see `docs/workflows/ISSUES.md`). When an issue closes, remove its entry here and record the change in `CHANGELOG.md`. Update this file whenever priorities change.
---
-## In Progress
-
-- **BOM-stripping fix for GitHub Actions publisher** - Hardening `scripts/publish-scheduled.js` against PowerShell-injected BOM characters in secrets
+## Goals
----
+What Twiligent is for, and what every change should move forward.
-## Next Up (High Priority)
+1. **One place for a creator's numbers.** YouTube, Instagram and Reddit analytics on one dashboard, with the same metrics, terms and layout across platforms.
+2. **Publishing that does not miss.** Scheduled Instagram posts go out on time, exactly once, even if one of the two schedulers fails.
+3. **Cheap and simple to self-host.** Runs on the free tiers of Cloudflare, Supabase, Upstash and Cloudinary. Setup is documented step by step at `/docs`, and members of an instance need no setup at all.
+4. **Safe by default.** Secrets stay server-side, every query is scoped to the signed-in user, tokens never reach the browser, and no client can exhaust the shared API quotas.
+5. **Easy to change without breaking.** Typed code, tests that pin behaviour, one shared toolchain, and docs that stay in step with the code.
-### Reddit Integration
+### Measures
-Add Reddit as a connected platform for analytics.
+| Goal | Measure |
+|---|---|
+| One place for the numbers | Every connected platform has an analytics page, an Overview entry and a content library |
+| Publishing that does not miss | No duplicate or skipped scheduled posts; failures show a reason in the queue |
+| Cheap to self-host | A new instance needs no paid plan; setup docs cover every key |
+| Safe by default | RLS on every table; rate limits on every API route; no secret in any response |
+| Easy to change | Type check, lint, tests and build pass on every push to `main` |
-**Approach:** Cookie-based authentication (no OAuth required)
-- User logs into Reddit in a browser popup
-- Session cookies (`token_v2`, `reddit_session`) are captured and stored in `accounts.data`
-- Cookies are auto-refreshed: Reddit rotates `Set-Cookie` on every authenticated response - save the updated cookie on each API call
-- Endpoints to fetch: `GET /user/{username}/submitted.json`, `/user/{username}/about.json`
+---
-**Files to add:**
-- `backend/services/reddit.js` - cookie-based fetch wrapper, token refresh, analytics computation
-- `backend/routes/reddit.js` - analytics routes (analytics, posts, comments)
-- `frontend/src/features/analytics/reddit/RedditAnalytics.jsx` - analytics page
-- `frontend/src/features/accounts/components/RedditConnect.jsx` - login popup + cookie capture
+## In Progress
-**Files to modify:**
-- `backend/server.js` - mount Reddit routes
-- `backend/lib/db.js` - no changes needed (platform='reddit' works with existing schema)
-- `backend/lib/cache.js` - add `getRedditCache`, `setRedditCache`, `deleteRedditCache`
-- `frontend/src/App.jsx` - add `/reddit/:id` route
-- `frontend/src/layout/Sidebar.jsx` - add Reddit nav links
-- `docs/architecture/data-flows/` - add `REDDIT.md`
+- **TypeScript migration** ([#2](https://github.com/spacesdrive/twiligent/issues/2)) - Backend, frontend and the scheduled publisher script rewritten in TypeScript with strict checks, without behaviour changes. Sub-issues: tooling (#3), backend (#4), frontend (#5), publisher script (#6), docs (#7).
+- **API rate limiting** ([#8](https://github.com/spacesdrive/twiligent/issues/8)) - Token bucket, leaking bucket, fixed window, sliding window log and sliding window counter limiters in Redis (atomic Lua scripts) with an in-memory fallback, applied per IP, per user and per expensive route.
---
+## Next Up (High Priority)
+
### Twitter/X Integration
-Add Twitter/X for analytics (read-only via twitterapi.io or official v2 API).
+Add Twitter/X for analytics (read-only via twitterapi.io or the official v2 API).
**Decision pending:** twitterapi.io ($0.00015/tweet, unlimited access) vs Twitter v2 API (free tier: 500k reads/month).
**Approach (twitterapi.io):**
-- User provides their Twitter username or OAuth token
-- Fetch tweets, impressions, engagement via twitterapi.io REST API
+- User provides their Twitter username
+- Fetch tweets, impressions and engagement through the provider's REST API
- No OAuth popup needed for public accounts
-**Files to add:**
-- `backend/services/twitter.js`
-- `backend/routes/twitter.js`
-- `frontend/src/features/analytics/twitter/TwitterAnalytics.jsx`
+Follow `docs/features/NEW_INTEGRATION.md`; the Reddit integration is the closest template.
---
-## Planned (Medium Priority)
-
-### GitHub Integration for Content Publishing
-
-The `settings` table already stores GitHub PAT and repo config. Build the actual feature.
-
-**Scope:**
-- Push published Instagram post data (caption, media URL, timestamp, engagement) to a GitHub repo as JSON/Markdown files
-- Useful for content archiving and portfolio generation
+### Error Monitoring
-**Files to modify:** `backend/routes/settings.js` (already has GET/PUT), `backend/services/` (add `github.js`)
+Failures are only visible in Cloudflare Worker logs and the GitHub Actions run log. Add error reporting (Workers Logs with alerts, or a hosted error tracker) so failed publishes, token refreshes and API quota errors are noticed without opening the logs.
---
-### Bulk Schedule from CSV
-
-Allow users to upload a CSV file to schedule multiple Instagram posts at once.
-
-**Current:** Bulk scheduling UI exists in `UploadContent.jsx` but only via manual row entry.
-**Goal:** CSV upload -> parse -> preview -> schedule all rows
-
----
+## Planned (Medium Priority)
### Analytics Date Range Filtering
-Currently analytics always fetch the most recent N posts/videos.
-Add date range filtering to all analytics views.
+Analytics always use the most recent N posts or videos. Add a date range filter to every analytics view and the Overview.
---
### Webhook Notifications
-Send a webhook (to Slack, Discord, or custom URL) when:
+Send a webhook (to Slack, Discord, or a custom URL) when:
- A scheduled post publishes successfully
- A scheduled post fails
- An Instagram token is nearing expiry (< 7 days)
@@ -99,7 +77,21 @@ Send a webhook (to Slack, Discord, or custom URL) when:
### Export to CSV/PDF
-Add export buttons to analytics pages. Users should be able to download their data.
+Add export buttons to analytics pages so users can download their data.
+
+---
+
+### Bulk Schedule from CSV
+
+Bulk scheduling exists through the upload form (`features/publishing/Bulk*`), one row per file. Add CSV import: upload, parse, preview, then schedule every row.
+
+---
+
+### GitHub Archive for Published Posts
+
+Push published Instagram post data (caption, media URL, timestamp, engagement) to a GitHub repository as JSON or Markdown, for archiving and portfolio sites.
+
+The backend still has `GET` and `PUT /api/settings/github` storing a token and repository in the `settings` table, but the Settings page no longer shows the field because nothing used it. Building this feature means restoring that form and adding `backend/services/github`.
---
@@ -111,11 +103,11 @@ TikTok's API requires a business account and app review. Lower priority until th
### YouTube Publishing
-YouTube's upload API requires OAuth with `youtube.upload` scope. Architecture would mirror Instagram publishing - add a media pipeline with Cloudinary -> YouTube upload -> status polling.
+YouTube's upload API requires OAuth with the `youtube.upload` scope. The architecture would mirror Instagram publishing: Cloudinary, then YouTube upload, then status polling.
### Multi-User Teams
-Currently each Supabase auth user is completely isolated. A team feature would allow multiple users to share the same accounts. Requires a `teams` table, `team_members` join table, and query changes across `lib/db.js`.
+Each Supabase auth user is completely isolated. A team feature would let several users share the same accounts. Requires a `teams` table, a `team_members` join table, and query changes across `lib/db`.
### Mobile App
@@ -125,9 +117,15 @@ React Native app using the same Cloudflare Worker backend.
## Known Issues / Tech Debt
-- ~~Redis cache TTL is never set~~ Done: analytics caches expire after 6 hours.
-- ~~`public/` directory at repo root contains a legacy Express prototype~~ Done: the legacy root dashboard was removed.
-- ~~Root `package.json` and `node_modules/` belong to the legacy prototype~~ Done: the root `package.json` is now the npm workspaces root for `backend/` and `frontend/` with shared dev tooling, and the Express prototype dependencies are gone.
- `wrangler.toml` has no `vars` section for non-secret configuration - any non-sensitive config currently requires a redeploy to change.
-- No error monitoring (Sentry, Cloudflare Analytics, etc.) - failures are only visible in Cloudflare Worker logs.
-- The `scripts/publish-scheduled.js` scheduler has no rate limiting - if 100 posts are due at the same time, it will attempt to publish all 100 concurrently within a single GitHub Actions run.
+- The scheduled publishers (`backend/utils/scheduler` and `scripts/publish-scheduled`) publish due posts one after another in a single run. A large batch due at the same moment can exceed the Worker's or the Actions job's time limit; the rest wait for the next run.
+- CORS allows every origin (`cors()` with no options). Restricting it to `FRONTEND_URL` would block other sites from calling the API with a stolen token.
+- `scripts/publish-scheduled.js` prints emoji in its log output, which breaks the writing standards; it is rewritten in the TypeScript migration (#6).
+- No end-to-end tests; see `docs/workflows/TESTING.md` for the planned Playwright coverage.
+
+### Resolved
+
+- Redis cache TTL was never set - analytics caches now expire after 6 hours.
+- The legacy Express prototype in the root `public/` folder and its root dependencies were removed; the root `package.json` is now the npm workspaces root.
+- Reddit integration shipped (public JSON API, no cookies or OAuth).
+- Secrets with PowerShell-injected BOM characters broke the GitHub Actions publisher - it now strips non-ASCII characters from them.
diff --git a/claude.md b/claude.md
index 52b6365..e2a5e22 100644
--- a/claude.md
+++ b/claude.md
@@ -2,12 +2,27 @@
## Project Identity
-Twiligent is a self-hosted social media analytics and publishing dashboard for creators and teams managing multiple YouTube channels and Instagram accounts. It is a private deployment product - the owner runs their own instance with their own API credentials. There is no SaaS model, no multi-tenancy abstraction, and no billing system.
+Twiligent is a self-hosted social media analytics and publishing dashboard for creators and teams managing multiple YouTube channels, Instagram accounts and Reddit profiles. It is a private deployment product - the owner runs their own instance with their own API credentials. There is no SaaS model, no multi-tenancy abstraction, and no billing system.
- Primary users: Small creator teams, agencies, individual power users
- Primary value: Unified analytics and scheduled Instagram publishing across multiple accounts
-- Current platforms: YouTube (analytics only), Instagram (analytics and publishing)
+- Current platforms: YouTube (analytics only), Instagram (analytics and publishing), Reddit (analytics only)
- GitHub repository: https://github.com/spacesdrive/twiligent
+- Goals and priorities: `ROADMAP.md`
+
+---
+
+## Issue Tracking (Required for Every Task)
+
+Every task is tracked by a GitHub issue, no matter how small: features, fixes, refactors, docs, dependency updates, deployments and repository chores. Read `docs/workflows/ISSUES.md` for the full workflow. The non-negotiable rules:
+
+1. Before writing any code or docs, search the open issues (`gh issue list --state open --search "<keywords>"`). Reuse a matching issue, otherwise open one with `gh issue create`. A task with several parts gets a parent issue with one sub-issue per part.
+2. Every commit references its issue: `Refs #N` in the body while the work continues, `Closes #N` in the commit or pull request that finishes it.
+3. Tick the issue's task list as parts finish, and record decisions, blockers and scope changes as issue comments.
+4. Close the issue as soon as the work is complete: committed and pushed, docs updated, and the checks in `docs/workflows/TESTING.md` passing. If a `Closes #N` commit did not close it on `main`, run `gh issue close N --comment "<what changed and how it was verified>"`.
+5. Never close an issue for unfinished work. When a session ends mid-task, leave the issue open with a comment listing what is done and what remains.
+6. When the user asks for several things at once, open one issue per request before starting the first, so nothing is lost.
+7. Never put secrets, tokens, `.dev.vars` values or personal data in an issue; the repository is public.
---
@@ -38,12 +53,14 @@ scripts/ publish-scheduled.js, run by GitHub Actions with no depend
Before implementing any feature or fix, read these documents in this exact order:
1. This file - project identity, rules, and documentation map
-2. `docs/WRITING_STANDARDS.md` - typography, icons, writing style, UI copy rules
-3. `docs/architecture/OVERVIEW.md` - system topology and request flow
-4. `docs/guidelines/JAVASCRIPT.md` - code standards (always apply)
-5. Relevant architecture doc - backend, frontend, database, or cloudflare
-6. Relevant feature guide - if one exists in `docs/features/`
-7. Relevant engineering guideline - if the task touches a specific layer
+2. `docs/workflows/ISSUES.md` - open or find the GitHub issue for the task before anything else
+3. `docs/WRITING_STANDARDS.md` - typography, icons, writing style, UI copy rules
+4. `docs/architecture/OVERVIEW.md` - system topology and request flow
+5. `docs/guidelines/JAVASCRIPT.md` - code standards (always apply)
+6. Relevant architecture doc - backend, frontend, database, or cloudflare
+7. Relevant feature guide - if one exists in `docs/features/`
+8. Relevant engineering guideline - if the task touches a specific layer
+9. `ROADMAP.md` - if the task is a planned item, link its issue there
For MCP usage, read `docs/mcp/OVERVIEW.md` before using any MCP server.
@@ -102,7 +119,8 @@ docs/
SEQUENTIAL_THINKING.md Complex planning, architecture decisions
PARALLEL_SEARCH.md UX research, best practices, browser compat
workflows/
- FEATURE_DEVELOPMENT.md 25-step feature implementation sequence
+ ISSUES.md GitHub issue lifecycle: open before work, reference in commits, close on completion
+ FEATURE_DEVELOPMENT.md Feature sequence from opening the issue to closing it
TESTING.md Test types, commands, pass criteria
GIT.md Commit format, branch rules, changelog
DEPLOYMENT.md Backend deploy, frontend deploy, verification
@@ -234,6 +252,8 @@ This is not optional for features that touch new UI patterns, new APIs, or new i
## AI Operating Rules
+**Open the issue first.** No task starts without a GitHub issue, and no task is reported as done while its issue is still open. See Issue Tracking above and `docs/workflows/ISSUES.md`.
+
**Always read before writing.** Read every file you will modify. Read all files in the same directory that might be affected. Read sibling files to understand conventions before adding new ones.
**Match the existing pattern.** This project has established conventions for routes, context hooks, db.js queries, cache.js patterns, and api.js methods. Find the nearest existing example and follow it exactly before introducing anything new.
@@ -272,8 +292,12 @@ Commit after every meaningful change. Do not batch unrelated changes into one co
type(scope): short imperative description
Optional body explaining why, not what.
+
+Refs #12
```
+Every commit body ends with the issue reference: `Refs #N` for partial work, `Closes #N` for the commit that completes the issue. Pull requests list `Closes #N` for every issue they finish.
+
Tag releases after changes or patches:
- Bug fixes: patch version (v1.0.1, v1.0.2)
- New features: minor version (v1.1.0)
@@ -289,6 +313,11 @@ When anything changes, update every relevant docs file from the table below. The
| What changed | Files to update |
|---|---|
+| Any task started | GitHub issue opened (or an existing one reused) before the first edit; see `docs/workflows/ISSUES.md` |
+| Any task finished | GitHub issue closed with a summary of what changed and how it was verified; task list ticked; parent issue closed after its last sub-issue |
+| Roadmap item started or finished | `ROADMAP.md` (link the issue when work starts; remove the entry and add it to `CHANGELOG.md` when the issue closes) |
+| Project goals or priorities changed | `ROADMAP.md` (Goals section), this file (Project Identity section) |
+| Issue workflow, labels or templates changed | `docs/workflows/ISSUES.md`, `.github/ISSUE_TEMPLATE/`, `.github/pull_request_template.md`, this file (Issue Tracking section) |
| New route added | `docs/architecture/backend/ROUTES.md`, `docs/architecture/OVERVIEW.md`, `docs/workflows/TESTING.md` (add to manual verification checklist) |
| Route deleted or changed | `docs/architecture/backend/ROUTES.md`, `docs/architecture/OVERVIEW.md` |
| New DB table | `docs/architecture/database/SCHEMA.md`, `docs/architecture/database/SECURITY.md`, `DECISIONS.md`, `CHANGELOG.md` |
diff --git a/docs/workflows/FEATURE_DEVELOPMENT.md b/docs/workflows/FEATURE_DEVELOPMENT.md
index b4da7a5..e438caf 100644
--- a/docs/workflows/FEATURE_DEVELOPMENT.md
+++ b/docs/workflows/FEATURE_DEVELOPMENT.md
@@ -6,6 +6,9 @@ Every feature - large or small - follows this sequence. Steps that don't apply t
## Phase 1: Understand
+**Step 0 - Open the GitHub issue**
+Before anything else, find or open the issue that tracks the work, following `docs/workflows/ISSUES.md`. Every later commit references it.
+
**Step 1 - Read CLAUDE.md**
Confirm you have the project context and know which docs to load.
@@ -157,10 +160,13 @@ Based on what changed (see `claude.md` Documentation Maintenance Policy):
Add an entry under `[Unreleased]` describing what was added, changed, or fixed.
**Step 23 - Update ROADMAP.md**
-If the feature was on the roadmap, move it to the completed list. If it opened new follow-up work, add that.
+If the feature was on the roadmap, remove it from the roadmap (CHANGELOG.md now records it). If it opened new follow-up work, add that.
**Step 24 - Commit**
-Follow the Git workflow in `docs/workflows/GIT.md`.
+Follow the Git workflow in `docs/workflows/GIT.md`. The commit body ends with `Refs #N`, or `Closes #N` on the commit that completes the issue.
**Step 25 - Deploy (if ready)**
Follow `docs/workflows/DEPLOYMENT.md`.
+
+**Step 26 - Close the issue**
+Once the work is pushed and verified, confirm the issue is closed. If `Closes #N` did not close it, run `gh issue close N --comment "..."` with what changed and how it was verified. Open follow-up issues for anything left out.
diff --git a/docs/workflows/GIT.md b/docs/workflows/GIT.md
index 714fdec..c80f695 100644
--- a/docs/workflows/GIT.md
+++ b/docs/workflows/GIT.md
@@ -36,8 +36,19 @@ type(scope): short description in present tense
Optional body explaining WHY, not WHAT. Wrap at 72 characters.
Reference which docs were updated if any.
+
+Refs #12
```
+### Issue reference
+
+Every commit ends with a reference to the GitHub issue that tracks the work (see `docs/workflows/ISSUES.md`):
+
+- `Refs #N` - the commit is part of the work; the issue stays open
+- `Closes #N` - the commit completes the issue; GitHub closes it when the commit reaches `main`
+
+A commit that finishes several issues lists each one: `Closes #3, closes #4`. A commit on a branch that closes an issue only takes effect when it is merged to `main`.
+
### Types
| Type | When to use |
@@ -121,6 +132,8 @@ Users can now upload a CSV file to schedule multiple posts at once.
Each row in the CSV maps to one scheduled_post record.
Docs updated: ROUTES.md, SCHEDULING.md, CHANGELOG.md.
+
+Closes #42
```
---
@@ -170,6 +183,8 @@ git merge feat/reddit-integration
git push origin main
```
+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`.
+
Delete the branch after merging:
```bash
git push origin --delete feat/reddit-integration
@@ -192,6 +207,7 @@ Run the commands from the repository root:
6. Check no secrets or credentials appear in the diff
7. Check no lockfile appears inside `backend/` or `frontend/`; the root `package-lock.json` is the only lockfile
8. Verify CHANGELOG.md is updated if the commit adds a feature or fix
+9. Verify the commit body ends with `Refs #N` or `Closes #N` for the tracking issue
---
@@ -206,6 +222,9 @@ After pushing to `main`, monitor GitHub Actions:
If a deployment workflow fails:
1. Read the failure log at https://github.com/spacesdrive/twiligent/actions
-2. Fix the issue locally
-3. Create a new commit (never amend a published commit)
-4. Push the fix
+2. Open a `bug` issue for the failure, or comment on the issue the push was for
+3. Fix the issue locally
+4. Create a new commit (never amend a published commit) that references the issue
+5. Push the fix
+
+After the push, check that every issue the work finished is closed (`gh issue list --state open`). Close any that a `Closes #N` line did not close, with a comment naming the commit.
diff --git a/docs/workflows/ISSUES.md b/docs/workflows/ISSUES.md
new file mode 100644
index 0000000..16203ab
--- /dev/null
+++ b/docs/workflows/ISSUES.md
@@ -0,0 +1,70 @@
+# Issue Tracking
+
+Every change to this repository is tracked by a GitHub issue at https://github.com/spacesdrive/twiligent/issues. Features, fixes, refactors, documentation, dependency updates and deployments all count. The issue is opened before the work starts and closed when the work is complete.
+
+The `gh` CLI is authenticated as `spacesdrive`; run every command from the repository root.
+
+---
+
+## Lifecycle
+
+1. **Search first.** `gh issue list --state open --search "<keywords>"`. If an open issue already covers the work, use it instead of opening a duplicate.
+2. **Open the issue before writing code.** Title, body and labels follow the format below. A task with several independent parts gets a parent issue plus one sub-issue per part.
+3. **Reference it in every commit.** Put `Refs #N` in the commit body while the work is in progress. Put `Closes #N` in the commit or pull request that finishes it.
+4. **Report progress.** Tick the task list in the issue body as parts finish (`gh issue edit N --body-file <file>`). Record decisions, blockers and scope changes as comments (`gh issue comment N --body "..."`).
+5. **Close it when the work is complete.** Complete means the code is committed and pushed, the docs listed in the Documentation Maintenance Policy are updated, and the checks in `docs/workflows/TESTING.md` pass. GitHub closes the issue automatically when a commit containing `Closes #N` reaches `main`. If it was not closed that way (the work was merged differently, or the issue needed no commit), close it by hand with a summary:
+
+ ```bash
+ gh issue close N --comment "Done in <commit or PR>. <one line on what changed and how it was verified>"
+ ```
+
+6. **Close a parent last.** A parent issue closes only after all its sub-issues are closed.
+7. **Unfinished work stays open.** If a session ends before the work is done, leave the issue open and add a comment with what is finished and what remains. Never close an issue for work that is not done; close it as "not planned" (`gh issue close N --reason "not planned" --comment "..."`) only when the work is abandoned.
+
+---
+
+## Title and Body
+
+- Title: sentence case, imperative, under 72 characters, no type prefix and no trailing period. "Add rate limiting to the API", not "feat: rate limiter".
+- Body: one short paragraph on the problem or goal, then a `- [ ]` task list, then a "Done when" line that says how completion is verified.
+- Bugs also state the steps to reproduce, what happened and what was expected.
+- Never paste secrets, tokens, `.dev.vars` contents, user emails or other personal data into an issue. Issues on this repository are public.
+
+The templates in `.github/ISSUE_TEMPLATE/` give this structure in the GitHub web form.
+
+---
+
+## Labels
+
+| Label | Use for |
+|---|---|
+| `enhancement` | New features and capabilities |
+| `bug` | Behaviour that does not match the docs or user expectations |
+| `documentation` | Docs-only work, or the docs part of a larger change |
+| `security` | Hardening, access control, secrets handling, rate limiting |
+| `typescript` | The TypeScript migration and type-only changes |
+
+Add a new label with `gh label create <name> --color <hex> --description "<text>"` and list it in this table.
+
+---
+
+## Sub-issues
+
+Link a child issue to its parent with the GitHub sub-issues API. It takes the child's numeric `id`, not its number:
+
+```bash
+child_id=$(gh api repos/spacesdrive/twiligent/issues/<child-number> --jq .id)
+gh api -X POST repos/spacesdrive/twiligent/issues/<parent-number>/sub_issues -F sub_issue_id=$child_id
+```
+
+---
+
+## 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.
+
+---
+
+## Roadmap Items
+
+`ROADMAP.md` lists planned work. When work on a roadmap item starts, open an issue for it and link the issue from the roadmap entry. When the issue closes, move the entry to `CHANGELOG.md` and remove it from the roadmap.