Skip to content

Commit b56f577

Browse files
authored
add AGENTS.md file (#2271)
1 parent ed1e193 commit b56f577

1 file changed

Lines changed: 149 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# AGENTS.md
2+
3+
## Project overview
4+
5+
- This repo powers **React Native Directory**, a Next.js Pages Router app that renders a React Native Web / Expo UI and serves JSON endpoints from `pages/api/`.
6+
- Keep `README.md` as the source of truth for contributor-facing dataset rules and `API.md` as the source of truth for the public API.
7+
- Runtime data is generated from `react-native-libraries.json` into `assets/data.json` and `assets/check-data.json`.
8+
9+
## Architecture map
10+
11+
- `pages/` contains route entrypoints. These files are intentionally thin and usually fetch data, then hand props to scene components.
12+
- Examples: `pages/index.tsx`, `pages/packages.tsx`, `pages/popular.tsx`, `pages/trending.tsx`
13+
- Package detail routes live under `pages/package/[name]/...` and `pages/package/[name]/[scopedName]/...`
14+
- `scenes/` contains page-level UI composition such as `HomeScene.tsx`, `PackageOverviewScene.tsx`, `PackageScoreScene.tsx`, and `PackageVersionsScene.tsx`.
15+
- `components/` contains reusable UI pieces. `components/Libraries.tsx` dynamically imports `~/components/Library` for list rendering.
16+
- `pages/api/` exposes the public JSON API documented in `API.md` and reads generated assets directly:
17+
- `pages/api/libraries/index.ts`
18+
- `pages/api/libraries/check.ts`
19+
- `pages/api/libraries/statistic.ts`
20+
- `pages/api/library/index.ts`
21+
- `pages/api/proxy/npm-stat.ts`
22+
- `scripts/` contains dataset refresh, validation, cleanup, and LLM export jobs.
23+
- `util/` contains shared query parsing, search/filter logic, sorting, cache constants, SSR helpers, and Tailwind setup.
24+
25+
## App conventions
26+
27+
- This repo uses the **Pages Router**, not the App Router. Add new pages under `pages/` and follow existing patterns like `getInitialProps` on listing pages and `getServerSideProps` on package detail pages.
28+
- Keep page files thin. Put page layout in `scenes/` and shared UI in `components/`.
29+
- Styling is primarily done with `twrnc` via `tw` from `util/tailwind.ts` and React Native style props, not CSS modules.
30+
- Example: `components/Search.tsx` and `scenes/HomeScene.tsx`
31+
- Use the `~/*` path alias from `tsconfig.json` for internal imports.
32+
- Follow the lint-enforced TypeScript style already used across the repo:
33+
- prefer function declarations over function expressions where practical
34+
- use inline type imports such as `import { type NextPageContext } from 'next';`
35+
- keep imports grouped/sorted in the existing style
36+
37+
## Data fetching and caching conventions
38+
39+
- Internal server-side fetches should go through `ssrFetch` from `util/SSRFetch.ts` unless a page needs custom header forwarding.
40+
- If a page must preserve bookmark filtering on the server, forward cookies like `pages/packages.tsx` does.
41+
- Use cache helpers from `util/Constants.ts` for external fetches:
42+
- `NEXT_1H_CACHE_HEADER` for internal API fetches
43+
- `NEXT_10M_CACHE_HEADER` for npm / proxy fetches
44+
- `getApiUrl` builds absolute API URLs during SSR and relative `/api/...` URLs in the browser. Reuse it instead of hardcoding hosts.
45+
46+
## Search, filters, and query changes
47+
48+
- Query params are defined centrally in `types/index.ts` (`Query`, `QueryOrder`).
49+
- Filtering behavior lives in `util/search.ts`.
50+
- Filter button definitions and labels live in `components/Filters/helpers.ts`.
51+
- Query normalization is intentionally minimal in `util/parseQueryParams.ts`.
52+
- If you add, remove, or rename a filter or sort option, update the relevant set together:
53+
- `types/index.ts`
54+
- `components/Filters/helpers.ts`
55+
- `util/search.ts`
56+
- `pages/api/libraries/index.ts`
57+
- `API.md` when the public API changes
58+
59+
## Bookmarks behavior
60+
61+
- Bookmarks are cookie-backed via `context/BookmarksContext.tsx` using the `rnd_bookmarks` cookie.
62+
- `/api/libraries` supports a `bookmarks` filter and disables public caching for those responses.
63+
- Do not remove cookie forwarding or public/private cache behavior around bookmarks unless you update both the UI and API flow intentionally.
64+
65+
## Dataset workflow
66+
67+
- The only hand-edited dataset file is `react-native-libraries.json`.
68+
- Add new library entries **at the end of the file**; the README documents that this order is used for “Recently added”.
69+
- Allowed entry keys are enforced in `util/Constants.ts` (`VALID_ENTRY_KEYS`).
70+
- Validation scripts also enforce:
71+
- GitHub URL shape and duplicates via `scripts/validate-libraries.ts`
72+
- npm/GitHub/package-name consistency for new or changed entries via `scripts/validate-new-entries.ts`
73+
- `scripts/cleanup-libraries-json.ts` removes invalid keys, redundant `npmPkg`, empty arrays, and most `false` values. `lint-staged` runs this automatically for `react-native-libraries.json`.
74+
75+
## Generated files
76+
77+
- Do **not** hand-edit these generated files:
78+
- `assets/data.json`
79+
- `assets/check-data.json`
80+
- `public/llms.txt`
81+
- `public/llms-full.txt`
82+
- They are produced by:
83+
- `bun data:update` / `bun data:update-missing`
84+
- `bun llms:generate`
85+
- `scripts/generate-llms.ts` pulls content from `README.md`, `API.md`, and `assets/data.json`, so API or contributor-doc changes can require regenerating the LLM exports.
86+
87+
## Common commands
88+
89+
- Install dependencies:
90+
91+
```sh
92+
bun install
93+
```
94+
95+
- Start local dev server:
96+
97+
```sh
98+
bun start
99+
```
100+
101+
- Lint and format check:
102+
103+
```sh
104+
bun lint
105+
```
106+
107+
- Auto-fix lint/format issues:
108+
109+
```sh
110+
bun lint:fix
111+
```
112+
113+
- Dataset checks:
114+
115+
```sh
116+
bun data:test
117+
bun data:validate
118+
bun ci:validate
119+
bun libraries:check
120+
```
121+
122+
- Dataset maintenance:
123+
124+
```sh
125+
bun data:update
126+
bun data:update-missing
127+
bun libraries:cleanup
128+
bun libraries:recalculate
129+
bun llms:generate
130+
```
131+
132+
- Production-style preview without refreshing data:
133+
134+
```sh
135+
bun preview
136+
```
137+
138+
## Environment and build notes
139+
140+
- `.env.example` documents `GITHUB_TOKEN` and `ANALYZE`.
141+
- `bun build` runs `bun data:update && bun llms:generate && next build --webpack`, so builds that refresh data need a valid `GITHUB_TOKEN`.
142+
- `vercel.json` injects `GITHUB_TOKEN` for hosted builds.
143+
- `scripts/build-and-score-data.ts` contains debugging toggles such as `ONLY_WRITE_LOCAL_DATA_FILE`; treat those as local debugging switches, not user-facing configuration.
144+
145+
## When docs must be updated
146+
147+
- Update `API.md` whenever a public endpoint, request parameter, response shape, or caching rule changes.
148+
- Update `README.md` when contributor-facing dataset fields or submission rules change.
149+
- Regenerate `public/llms.txt` and `public/llms-full.txt` after changing `scripts/generate-llms.ts` or content it consumes.

0 commit comments

Comments
 (0)