4.6 KiB
4.6 KiB
AGENTS.md — Balinyaar Web Client
Agent-oriented guide to the frontend. For human setup/run instructions see README.md.
Stack
- Next.js with the App Router (
src/app/), statically exported (output: 'export'innext.config.mjs→ builds toout/) - React + TypeScript (
strictmode) - Material UI (MUI) for components and theming (Emotion under the hood)
- Jest + Testing Library for unit tests
- ESLint (
eslint-config-next) + Prettier
Commands
| Task | Command |
|---|---|
| Dev server | npm run dev |
| Build | npm run build |
| Lint | npm run lint |
| Type-check | npm run type |
| Format | npm run format |
| Test (watch) | npm test |
| Test (CI) | npm run test:ci |
Always run npm run lint and npm run type after a change. Run npm run test:ci when you touch a component that has a *.test.tsx.
Directory map
src/
├── app/ Routes (App Router). Each folder = a route; page.tsx = the page.
│ ├── layout.tsx Root layout: store + theme providers, global <metadata>
│ ├── page.tsx "/" entry (delegates to home)
│ ├── home/ about/ Content pages
│ ├── auth/login|signup Auth pages (LoginForm is currently a stub)
│ └── me/ Authenticated user page
├── components/
│ ├── common/ Reusable App* primitives (see below) + ErrorBoundary
│ └── UserInfo/ Logged-in user summary
├── hooks/ useIsAuthenticated, useIsMobile, event hooks, useWindowSize
├── layout/ PublicLayout / PrivateLayout + TopBar, SideBar, BottomBar, config
├── store/ Global state: React context + reducer (AppStore, AppReducer)
├── theme/ ThemeProvider, light/dark palettes, colors, MUI-for-Next bridge
└── utils/ storage (local/session), navigation, environment, text, types
Conventions (follow these)
- Imports: use the
@/*alias for anything undersrc/(e.g.import { AppButton } from '@/components'). The alias is defined intsconfig.json. - Barrel files: most folders export through an
index.ts(x). Add new public exports there (e.g. a new common component is re-exported fromsrc/components/common/index.tsx, whichsrc/components/index.tsxre-exports). - Common components live in
src/components/common/<Name>/as a folder containing<Name>.tsx,index.tsx(re-export), and an optional<Name>.test.tsx. Existing ones:AppAlert,AppButton,AppIcon,AppIconButton,AppImage,AppLink,AppLoading. Prefer reusing these over raw MUI where one exists. - Icons: reference icons by string name through
AppIcon. The name→icon map is insrc/components/common/AppIcon/config.ts; add new icons there (custom SVGs go inAppIcon/icons/). - Navigation: sidebar/bottom-bar items are arrays of
LinkToPagedefined insidePublicLayout.tsx/PrivateLayout.tsx. Add a route → add an entry there to surface it in the nav. - Two layouts:
PrivateLayout(after auth) andPublicLayout(before auth);CurrentLayoutpicks between them based on auth state. The app name lives in theTITLE_PRIVATE/TITLE_PUBLICconstants in those files. - Auth is a stub.
src/hooks/auth.tsandsrc/app/auth/login/LoginForm.tsxfake login by writing a placeholder token to session storage (// TODO: AUTH:). When implementing real auth, replace those spots and point requests atNEXT_PUBLIC_API_URL(theserverproject's JWT endpoints). - Theming: use the theme/palette via MUI's
sx/useTheme; don't hardcode colors. Light/dark values are insrc/theme/light.tsanddark.ts; dark-mode toggle flows through the store. - Client vs server components: files needing hooks/browser APIs start with
'use client';(seeLoginForm.tsx). Pages that only render markup can stay server components.
Environment
Browser-exposed config comes from NEXT_PUBLIC_* variables (copy .env.sample → .env). The ones actually read in code: NEXT_PUBLIC_ENV, NEXT_PUBLIC_DEBUG, NEXT_PUBLIC_PUBLIC_URL (see src/config.ts) and NEXT_PUBLIC_VERSION (see src/utils/environment.ts). NEXT_PUBLIC_API_URL is the backend base URL.
Gotchas
- Static export (
output: 'export') means no server-side runtime — no API routes, no SSR-only features,images.unoptimizedis on. - Don't reintroduce the removed demo/showcase route (
src/app/dev) orDemo*components — they were template content.