| name | github-open-source |
| description | Work on Open Source / GitHub pages and API. Use when modifying GitHub profile, repositories, readme, last activities, open-source routes, or GitHub-related hooks and components. |
GitHub / Open Source integration
Guidance for the Open Source feature (GitHub API, routes, hooks, and UI).
Server: client and cache
- Client: lib/github.ts —
GitHubClient class using @octokit/graphql. Config: GITHUB_TOKEN, username from lib/config/personal (personal.social.github). Retries, timeout, and in-memory cache TTL (default 5 min).
- Server-side dedup: All public getters are wrapped in React
cache():
getProfile(), getReadme(), getRepository(repository), getLastActivities().
API routes
- Base path:
app/api/open-source/.
- Routes:
- Convention: Fetchers in hooks should throw on
!res.ok where appropriate so SWR sets isError; profile route may return 200 with data or error payload — align hook fetcher with that.
Client: hooks and SWR
- Main hook: hooks/use-github.ts —
useGithub(). Uses SWR for:
/api/open-source/profile — refresh 10min; updates setGithubProfile in UIProvider.
/api/open-source/last-activities — refresh 5min; throws on !res.ok; updates setLastActivities.
- Shared state: components/providers/ui-provider.tsx —
githubProfile, lastActivities, and setters. Use for components that show profile or activity without refetching.
- Accessibility: Dynamic content (e.g. activity) uses
aria-live="polite" per project a11y standards.
Pages and UI
Types
Adding a new endpoint or section
- Add the method to
GitHubClient in lib/github.ts if it calls GitHub; wrap the public getter in cache().
- Add route under
app/api/open-source/.
- Add or reuse a hook with SWR; throw in fetcher on
!res.ok for critical data and surface isError in UI. Use dynamic wrappers + skeletons for heavy sections.