# AGENT.md This document provides an overview of the Next Explorer project, its structure, and its implementation details. ## Project Overview Next Explorer is a web application for exploring the Spectrum Next ecosystem. It is built with Next.js (App Router), React, and TypeScript. It has two main areas: - Registers: parsed from `data/nextreg.txt`, browsable with real-time filtering and deep links. - ZXDB Explorer: a deep, cross‑linked browser for ZXDB entries, releases, labels, magazines, genres, languages, and machine types backed by MySQL using Drizzle ORM. ## Project Structure The project is a Next.js application with the following structure: ``` next-explorer/ ├── eslint.config.mjs ├── next.config.ts ├── package.json ├── pnpm-lock.yaml ├── tsconfig.json ├── data/ │ ├── nextreg.txt │ ├── custom_parsers.txt │ └── wikilinks.txt ├── node_modules/... ├── public/... └── src/ ├── middleware.js ├── app/ │ ├── layout.tsx │ ├── page.module.css │ ├── page.tsx │ └── registers/ │ ├── page.tsx │ ├── RegisterBrowser.tsx │ ├── RegisterDetail.tsx │ └── [hex]/ │ └── page.tsx ├── components/ │ ├── Navbar.tsx │ └── ThemeDropdown.tsx ├── scss/ │ ├── _bootswatch.scss │ ├── _explorer.scss │ ├── _variables.scss │ └── nbn.scss ├── services/ │ └── register.service.ts └── utils/ ├── register_parser.ts └── register_parsers/ ├── reg_default.ts └── reg_f0.ts ``` - **`data/`**: Contains the raw input data for the Spectrum Next explorer. - `nextreg.txt`: Main register definition file. - `custom_parsers.txt`, `wikilinks.txt`: Auxiliary configuration/data used by the parser. - **`src/app/`**: Next.js App Router entrypoint. - `layout.tsx`: Root layout for all routes. - `page.tsx`: Application home page. - `registers/`: Routes and components for the register explorer. - `page.tsx`: Server Component that loads and lists all registers. - `RegisterBrowser.tsx`: Client Component implementing search/filter and listing. - `RegisterDetail.tsx`: Client Component that renders a single register’s details, including modes, notes, and source modal. - `[hex]/page.tsx`: Dynamic route that renders details for a specific register by hex address. - `src/app/zxdb/`: ZXDB Explorer routes and client components. - `page.tsx`: ZXDB hub page linking to entries, releases, labels, etc. - `entries/[id]/page.tsx` + `EntryDetail.tsx`: Entry details (SSR initial data). - `releases/page.tsx` + `ReleasesExplorer.tsx`: Releases search + filters. - `labels/page.tsx`, `labels/[id]/page.tsx` + client: Labels search and detail. - `genres/`, `languages/`, `machinetypes/`: Category hubs and detail pages. - `magazines/`, `issues/`: Magazine and issue browsing. - `src/app/api/zxdb/`: Zod‑validated API routes (Node runtime) for search and category browsing. - `src/server/`: - `env.ts`: Zod env parsing/validation (t3.gg style). Validates `ZXDB_URL` (mysql://). - `server/db.ts`: Drizzle over `mysql2` singleton pool. - `server/schema/zxdb.ts`: Minimal Drizzle models (entries, labels, helper tables, lookups). - `server/repo/zxdb.ts`: Repository queries for search, details, categories, and facets. - **`src/components/`**: Shared UI components such as `Navbar` and `ThemeDropdown`. - **`src/services/register.service.ts`**: Service layer responsible for loading and caching parsed register data. - **`src/utils/register_parser.ts` & `src/utils/register_parsers/`**: Parsing logic for `nextreg.txt`, including mode/bitfield handling and any register-specific parsing extensions. ## Implementation Details Comment what the code does, not what the agent has done. The documentation's purpose is the state of the application today, not a log of actions taken. ### Data Parsing - `getRegisters()` in `src/services/register.service.ts`: - Reads `data/nextreg.txt` from disk. - Uses `parseNextReg()` from `src/utils/register_parser.ts` to convert the raw text into an array of `Register` objects. - Returns the in-memory representation of all registers (and can be extended to cache results across calls). - `parseNextReg()` and related helpers in `register_parser.ts`: - Parse the custom `nextreg.txt` format into structured data: - Register addresses (hex/dec). - Names, notes, and descriptive text. - Per-mode read/write/common bitfield views. - Optional source lines and external links (e.g. wiki URLs). - Delegate special-case parsing to functions in `src/utils/register_parsers/` (e.g. `reg_default.ts`, `reg_f0.ts`) when needed. ### TypeScript Patterns - No explicity any types. - Use `const` for constants. - Use `type` for interfaces. - No `enum`. ### UI / Bootstrap Patterns The project uses the **Bootswatch Pulse** theme (purple primary) with `react-bootstrap` and `react-bootstrap-icons`. - **Always use react-bootstrap components** over raw HTML+className for Bootstrap elements: - `Card`, `Table`, `Badge`, `Button`, `Alert`, `Form.Control`, `Form.Select`, `Form.Check`, `InputGroup`, `Spinner`, `Collapse` etc. - Icons from `react-bootstrap-icons` (e.g. `Search`, `ChevronDown`, `Download`, `BoxArrowUpRight`). - **Match existing patterns** — see `RegisterBrowser.tsx` and `Navbar.tsx` for canonical react-bootstrap usage. - **Shared explorer components** in `src/components/explorer/`: - `ExplorerLayout` — two-column layout (sidebar + content). - `FilterSidebar` — `Card` wrapper with optional "Reset all filters" button. - `FilterSection` — collapsible filter group with label, badge, and `Collapse` animation. - `MultiSelectChips` — chip-toggle selector with optional collapsed summary mode. - `Pagination` — prev/next with page counter and loading spinner. - **Stale-while-revalidate pattern** — show previous results at reduced opacity during loading (`className={loading ? "opacity-50" : ""}`), never blank the screen. - **Empty states** — only show a section/card if it has data. Do not render empty cards with "No X recorded" placeholders; omit them entirely. - **Tables** — use react-bootstrap `