|
| 1 | +--- |
| 2 | +name: create-example-app-with-integration |
| 3 | +description: >- |
| 4 | + This skill is used to create an example application for a web framework |
| 5 | + integration package and to test it with `mise test:examples`. |
| 6 | +argument-hint: "Provide the name of the web framework to create an example for." |
| 7 | +--- |
| 8 | + |
| 9 | +<!-- deno-fmt-ignore-file --> |
| 10 | + |
| 11 | +Creating an example for an integration package |
| 12 | +============================================== |
| 13 | + |
| 14 | +Follow these steps in order to create the example application and verify |
| 15 | +it works. |
| 16 | + |
| 17 | +1. Set up the example project |
| 18 | +2. Implement the example app |
| 19 | +3. Test the example with `mise test:examples` |
| 20 | +4. Lint, format, and final checks |
| 21 | + |
| 22 | + |
| 23 | +Reference documents |
| 24 | +------------------- |
| 25 | + |
| 26 | +Two reference documents describe what the example must do and how it must |
| 27 | +look. Both are references only — do not create these files in the actual |
| 28 | +generated example app. |
| 29 | + |
| 30 | +### <ARCHITECTURE.md> |
| 31 | + |
| 32 | +Defines the example's functional behavior. Consult it for: |
| 33 | + |
| 34 | + - **Middleware integration**: How to register the Fedify middleware so it |
| 35 | + intercepts ActivityPub requests before application routes. |
| 36 | + - **Reverse proxy support**: When and how to apply |
| 37 | + `getXForwardedRequest` from `x-forwarded-fetch`. |
| 38 | + - **Routing**: The complete list of routes (`GET /`, `GET /users/…`, |
| 39 | + `POST /post`, `POST /follow`, `POST /unfollow`, `GET /events`, etc.) |
| 40 | + with their expected request/response behavior. |
| 41 | + - **Server-sent events**: How the `/events` endpoint keeps an open SSE |
| 42 | + connection and broadcasts changes to the client. |
| 43 | + - **Server-side data access**: How to use Fedify's `RequestContext` to |
| 44 | + bridge between the framework routing layer and the federation layer. |
| 45 | + - **Federation** and **Storing**: Which source files to set up |
| 46 | + (`src/federation.ts`, `src/store.ts`) and the template files they are |
| 47 | + based on (<example/src/federation.ts>, <example/src/store.ts>). |
| 48 | + - **Logging**: How to use `@logtape/logtape` and `src/logging.ts`. |
| 49 | + |
| 50 | +### <DESIGN.md> |
| 51 | + |
| 52 | +Defines the example's visual presentation. Consult it for: |
| 53 | + |
| 54 | + - **Visual theme & atmosphere**: Light/dark theme with |
| 55 | + `prefers-color-scheme` detection. |
| 56 | + - **Color palette & roles**: Surface, accent, neutral, and shadow tokens. |
| 57 | + - **Typography rules**: Font family, size hierarchy, and weight |
| 58 | + principles. |
| 59 | + - **Component stylings**: Profile header, avatar, cards, search input, |
| 60 | + compose form, buttons, back link, and Fedify badge. |
| 61 | + - **Layout principles**: Spacing, containers, grid, and whitespace. |
| 62 | + - **Responsive behavior**: Single breakpoint at `768px` and mobile |
| 63 | + adaptations. |
| 64 | + - **Static assets**: Files to serve from `public/` (<example/public/\*>). |
| 65 | + - **Page structure**: Detailed layout of the home page, actor profile |
| 66 | + page, and post detail page. |
| 67 | + |
| 68 | + |
| 69 | +Set up the example project |
| 70 | +-------------------------- |
| 71 | + |
| 72 | +Create an `examples/framework/` app and write an example for the new |
| 73 | +package. Unless the framework itself prevents it, support both Deno and |
| 74 | +Node.js environments. If Deno is supported, add a *deno.json* based on |
| 75 | +<example/deno.json>; if Node.js is supported, add *package.json* based on |
| 76 | +<example/package.jsonc> and *tsdown.config.ts*. Depending on the supported |
| 77 | +environments, add the example path to the `workspace` field in |
| 78 | +the root *deno.json* and to the `packages` field in |
| 79 | +*pnpm-workspace.yaml*. |
| 80 | + |
| 81 | +If the framework is backend-only and needs a frontend framework, and there |
| 82 | +is no natural pairing like solidstart-solid, use Hono. |
| 83 | + |
| 84 | +Copy the template files from <example/\*> as-is and modify as needed. |
| 85 | + |
| 86 | +If the framework does not have a prescribed entry point, use `src/main.ts` |
| 87 | +as the application entry point. Define and export the framework app in |
| 88 | +`src/app.ts`, then import and run it from the entry file. Import |
| 89 | +`src/logging.ts` in the entry file to initialize `@logtape/logtape`. |
| 90 | +When logging is needed, use the `getLogger` function from `@logtape/logtape` |
| 91 | +to create a logger. |
| 92 | + |
| 93 | + |
| 94 | +Implement the example app |
| 95 | +------------------------- |
| 96 | + |
| 97 | +Follow the specifications in <ARCHITECTURE.md> and <DESIGN.md> to |
| 98 | +implement the example. In particular: |
| 99 | + |
| 100 | + - Register the Fedify middleware in `src/app.ts` per the “Middleware |
| 101 | + integration” and “Reverse proxy support” sections of |
| 102 | + <ARCHITECTURE.md>. |
| 103 | + - Set up federation logic in `src/federation.ts` based on |
| 104 | + <example/src/federation.ts>. Set up in-memory stores in `src/store.ts` |
| 105 | + based on <example/src/store.ts>. |
| 106 | + - Implement all routes listed in the “Routing” section of |
| 107 | + <ARCHITECTURE.md>, using `RequestContext` as described in the |
| 108 | + “Server-side data access” section. |
| 109 | + - Render HTML pages according to <DESIGN.md>. Serve static assets from |
| 110 | + the `public/` directory (copy from <example/public/\*>). |
| 111 | + - Implement the SSE endpoint per the “Server-sent events” section of |
| 112 | + <ARCHITECTURE.md>. |
| 113 | + |
| 114 | + |
| 115 | +Test the example with `mise test:examples` |
| 116 | +------------------------------------------ |
| 117 | + |
| 118 | +Register the new example in `examples/test-examples/mod.ts`. Read the |
| 119 | +comments above the example registry arrays in that file to determine |
| 120 | +which array is appropriate and what fields are required. Follow the |
| 121 | +patterns of existing entries. |
| 122 | + |
| 123 | +Before running the tests, ensure that the tunneling service is usable. |
| 124 | +The tests use the tunneling service `pinggy.io` to make the example app |
| 125 | +accessible to the test suite. If the tunneling service is not usable, |
| 126 | +the tests may never finish or may fail due to a connection error. |
| 127 | + |
| 128 | +While developing the example, run only the new example to iterate |
| 129 | +quickly: |
| 130 | + |
| 131 | +~~~~ bash |
| 132 | +mise test:examples framework |
| 133 | +~~~~ |
| 134 | + |
| 135 | +where `framework` is the `name` field of the registered entry. Pass |
| 136 | +`--debug` for verbose output if the test fails. |
| 137 | + |
| 138 | +After the example is complete, run the full suite once to confirm nothing |
| 139 | +is broken: |
| 140 | + |
| 141 | +~~~~ bash |
| 142 | +mise test:examples |
| 143 | +~~~~ |
| 144 | + |
| 145 | + |
| 146 | +Lint, format, and final checks |
| 147 | +------------------------------ |
| 148 | + |
| 149 | +Add keywords related to the framework in `.hongdown.toml` and `cspell.json` in |
| 150 | +root path. |
| 151 | + |
| 152 | +After implementation, run `mise run fmt && mise check`. |
| 153 | +If there are lint or format errors, fix them and run the command again until |
| 154 | +there are no errors. |
0 commit comments