-
Notifications
You must be signed in to change notification settings - Fork 0
docs: refactor and expand docs #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
952dd62
47fcaf8
8f4fe3e
7cdf722
94591bb
5c07603
a27f04e
6d20041
c1008bb
b783da7
e222955
a7dfa36
9b49300
12fe36e
d0bf1f3
762f5f7
a4efb72
57cb1dc
882cf88
b693501
9abe148
223a575
3424062
96ad1c2
04ef9dc
bf5f157
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,21 @@ | ||
| # Description: Example of .env file | ||
| # Example .env file for local development and tests | ||
|
|
||
| # MongoDB URI | ||
| # MongoDB (optional) | ||
| MONGO_URI=mongodb://localhost:27017/your-database-name | ||
|
|
||
| # Auth Plugin | ||
| # OpenID Connect (used by the auth plugin) | ||
| # AUTH_DISCOVERY_URL should point to the provider's discovery document (/.well-known/openid-configuration) | ||
| AUTH_DISCOVERY_URL=https://login.microsoftonline.com/c917f3e2-9322-4926-9bb3-daca730413ca/v2.0/.well-known/openid-configuration | ||
| AUTH_CLIENT_ID=b4bc4b9a-7162-44c5-bb50-fe935dce1f5a | ||
|
|
||
| # When true, the auth plugin skips remote discovery and verification (useful for local testing) | ||
| AUTH_SKIP=true | ||
|
|
||
| # Optional runtime controls | ||
| NODE_ENV=development | ||
| PORT=3000 | ||
|
|
||
| # Test helpers (optional) | ||
| # Provide these only when running integration tests that require a real token/user. | ||
| TEST_AUTH_TOKEN= | ||
| TEST_AUTH_USER= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: docs:publish | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pages: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| detect-quota: | ||
| # Probe the hosted runner so we can decide whether to use hosted or self-hosted. | ||
| runs-on: ubuntu-slim | ||
| steps: | ||
| - name: Quota probe | ||
| id: quota_probe | ||
| run: | | ||
| echo "probe" | ||
|
|
||
| build-and-publish: | ||
| needs: detect-quota | ||
| # NOTE: do not set `continue-on-error` on detect-quota (see docs) | ||
| runs-on: ${{ needs.detect-quota.result == 'success' && 'ubuntu-slim' || 'self-hosted' }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Use Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 24 | ||
|
|
||
| - name: Enable Corepack | ||
| run: | | ||
| corepack enable | ||
| corepack install | ||
|
|
||
| - name: Enable Node cache | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| cache: yarn | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| yarn install --immutable | ||
|
|
||
| - name: Build project | ||
| run: | | ||
| yarn build | ||
|
|
||
| - name: Generate TypeDoc | ||
| run: | | ||
| yarn docs:typedoc | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: api-docs | ||
| path: docs/api | ||
|
|
||
| - name: Publish to GitHub Pages | ||
| uses: peaceiris/actions-gh-pages@v4 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| publish_dir: ./docs/api | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| name: docs | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
|
Comment on lines
+1
to
+7
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| detect-quota: | ||
| # Probe the hosted runner so we can decide whether to use a hosted | ||
| # runner or fall back to self-hosted. The job should fail if quota is exhausted. | ||
| runs-on: ubuntu-slim | ||
| steps: | ||
| - name: Quota probe | ||
| id: quota_probe | ||
| run: | | ||
| echo "probe" | ||
|
|
||
| build: | ||
| needs: detect-quota | ||
| # NOTE: Do not set `continue-on-error: true` on the `detect-quota` job. | ||
| # If `continue-on-error` is enabled the job result will always be | ||
| # 'success', which defeats detection (we rely on `needs.detect-quota.result`). | ||
| runs-on: ${{ needs.detect-quota.result == 'success' && 'ubuntu-slim' || 'self-hosted' }} | ||
| steps: | ||
polyipseity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Use Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 24 | ||
|
|
||
| - name: Enable Corepack | ||
| run: | | ||
| corepack enable | ||
| corepack install | ||
|
|
||
| - name: Enable Node cache | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| cache: yarn | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| yarn install --immutable | ||
|
|
||
| - name: Build project | ||
| run: | | ||
| yarn build | ||
|
|
||
| - name: Generate TypeDoc | ||
| run: | | ||
| yarn docs:typedoc | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: api-docs | ||
| path: docs/api | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,70 @@ | ||
| # USThing Template API | ||
| # template-api | ||
|
|
||
| The template repository for USThing backend services, powered by Fastify. | ||
| <!-- NOTE: If you use this repository as a template, replace `USThing/template-api` with your own GitHub owner/repo in the badge URLs. --> | ||
|
|
||
| ## Available Scripts | ||
| [](https://github.com/USThing/template-api/actions/workflows/check.yml) [](https://github.com/USThing/template-api/actions/workflows/docs-publish.yml) [](https://github.com/USThing/template-api/actions/workflows/release.yml) [](https://usthing.github.io/template-api/index.html) | ||
|
|
||
| In the project directory, you can run: | ||
| A concise Fastify + TypeScript starter used by USThing backend services. This repository provides a minimal, well-tested scaffold with recommended scripts, linting, and CI configuration. | ||
|
|
||
| ### `yarn run dev` | ||
| ## Prerequisites | ||
|
|
||
| Run the app in development mode; watch the source for changes. | ||
| - Node.js (see `engines` in `package.json`) | ||
| - Yarn via Corepack | ||
|
|
||
| Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
| Enable Corepack (recommended) and the Yarn version used by this repo: | ||
|
|
||
| ### `yarn run compile` | ||
| ```bash | ||
| corepack enable | ||
| # `packageManager` field in `package.json` ensures the correct Yarn version is used | ||
| ``` | ||
|
|
||
| Run the TypeScript compiler to check for type errors. | ||
| ## Quickstart (local) | ||
|
|
||
| ### `yarn run build`, `yarn run start` | ||
| ```bash | ||
| corepack enable | ||
| yarn install | ||
| yarn build | ||
| yarn start | ||
| ``` | ||
|
|
||
| - Build the app for production to the `dist` folder. | ||
| - Start the built app in production mode. | ||
| ## Developer workflow | ||
|
|
||
| ### `yarn run test` | ||
| - Start dev mode (watch + Fastify): `yarn dev` | ||
| - Run tests (TypeScript tests run via `tsx`): `yarn test` | ||
| - Lint and format (auto-fixes): `yarn lint` and `yarn fmt` | ||
|
|
||
| Run the tests. | ||
| ## Automatic API docs | ||
|
|
||
| ### `yarn run lint` | ||
| API docs are generated from source by TypeDoc and published by CI. To generate locally: | ||
|
|
||
| Run the linter and fix any issues. | ||
| ```bash | ||
| yarn docs:typedoc | ||
| ``` | ||
|
|
||
| `lint:check` does not fix the issues. | ||
| Generated docs are placed under `docs/api` (CI publishes these artifacts — do not commit generated files). | ||
|
|
||
| ### `yarn run fmt` | ||
| ## Project layout | ||
|
|
||
| Run the formatter and fix any issues. | ||
| - `src/` — application code (routes, plugins, utils) | ||
| - `src/app.ts` — Fastify app and plugin registration | ||
| - `src/routes/` — route modules | ||
| - `test/` — tests and helpers | ||
| - `docs/` — human-authored guides and docs | ||
| - `.env.example` — example environment variables | ||
|
|
||
| `fmt:check` does not fix the issues. | ||
| ## Environment | ||
|
|
||
| ## Environment Variables | ||
| Tests and some dev helpers reference `TEST_AUTH_TOKEN` / `TEST_AUTH_USER`. See `docs/env-vars.md` for recommended env variables and CI secret usage. Keep secrets out of the repo and use your CI's secret manager. | ||
|
|
||
| For Fastify-level environment variables, please refer to the [fastify-cli documentation](https://github.com/fastify/fastify-cli). | ||
| ## Contributing | ||
|
|
||
| For the application-level environment variables, please refer to the | ||
| `.env.example` file. `yarn run dev` automatically loads a `.env` file if it exists. | ||
| Follow `CONTRIBUTING.md` (commitlint, lint, tests). The project uses Conventional Commits for releases. | ||
|
|
||
| ## CI / CD | ||
| ## Support | ||
|
|
||
| This template supports GitHub Actions for CI / CD. The available workflows are: | ||
| Open an issue on GitHub using the provided templates for bugs or feature requests. | ||
|
|
||
| - Checks / eslint: Run ES Lint to check problems and the format of the code. | ||
| - Checks / commitlint: Run Commitlint to check the format of the commit messages. | ||
| - Checks / tests: Run unit tests of the project. | ||
| - Docker CI / docker: Build the Docker image and push it to the GitHub Container Registry. | ||
| - Release Please / release-please: Automatic releasing. See also [release-please](https://github.com/googleapis/release-please). | ||
| ## Learn more | ||
|
|
||
| ## Learn More | ||
|
|
||
| To learn Fastify, check out the [Fastify documentation](https://fastify.dev/docs/latest/). | ||
| - Fastify: <https://www.fastify.dev/> | ||
| - Docs folder: `docs/` (detailed guides and examples) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||
| # CI workflows | ||||||
|
|
||||||
| The repository uses three primary GitHub Actions workflows in `.github/workflows/`: | ||||||
|
|
||||||
| - `check.yml` — runs on push and pull_request. It probes runner availability (a small `detect-quota` job) and then runs ESLint, commitlint, and tests. Each job uses a hosted-first → self-hosted fallback by selecting `runs-on` based on the probe result. | ||||||
| - `docker.yml` — builds and pushes container images (Buildx). It also probes runner availability and uses a hosted-first fallback. The workflow prepares Docker metadata (tags include sha, branch/ref, and PR tags) and pushes images to `REGISTRY`/`IMAGE_NAME`. | ||||||
| - `release.yml` — runs `googleapis/release-please-action@v4` on pushes to `main`. When a release is created the workflow tags versions and (optionally) builds/pushes images. See `release.yml` for the exact tagging and build steps. | ||||||
|
|
||||||
| ## Key notes | ||||||
|
|
||||||
| - Hosted-first fallback: jobs use a small probe job (`detect-quota`) and set `runs-on` dynamically so CI prefers `ubuntu-latest` but can fall back to `self-hosted` when needed. | ||||||
|
||||||
| - Hosted-first fallback: jobs use a small probe job (`detect-quota`) and set `runs-on` dynamically so CI prefers `ubuntu-latest` but can fall back to `self-hosted` when needed. | |
| - Hosted-first fallback: jobs use a small probe job (`detect-quota`) and set `runs-on` dynamically so CI prefers `ubuntu-slim` but can fall back to `self-hosted` when needed. |
Uh oh!
There was an error while loading. Please reload this page.