This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
Forumlify repository guide
Project scope
- This repository is the Forumlify NEXT edition: Next.js 16 App Router, React 19, PostgreSQL, and JavaScript.
- Normal development happens on the
nextbranch and is pushed toorigin/next. Themainbranch is the separate Lite/Express implementation; do not copy behavior from it blindly. - Before changing code, run
git status --short --branch. Preserve unrelated user changes and untracked files. - Do not commit generated or local artifacts such as
.next/,.playwright-cli/, uploaded files, logs, database data, or secrets.
Commands and runtime
- Requires Node.js 20.9 or newer.
- Install dependencies with
npm install. - Start local development with
npm run dev; it listens on0.0.0.0and normally uses port 3000. - Create a production build with
npm run build. - Start a built server with
npm start. - Run tests with
npm test. The test suite expects a running Forumlify instance and PostgreSQL; seetest/README.md. Override the service URL withBASE_URLwhen needed. - Always provide
DATABASE_URLexplicitly when the active PostgreSQL instance is not the defaultlocalhost:5432/forumlify. Inspect existing Docker containers before creating another database or changing ports. - Never delete or recreate a database, volume, or upload directory merely to make a test pass.
Architecture
app/page.jsandapp/HomeClient.jsrender the application shell. Most navigation is SPA-style state managed bycomponents/AppProvider.jsand synchronized to?post=,?user=, and?page=query parameters.app/api/**/route.jscontains the Next.js Route Handlers. Keep authentication and authorization checks on the server even when the UI already hides an action.components/contains client UI. ReuseAppProvider,Toast,Icons, and existing component patterns instead of introducing parallel state or notification systems.app/globals.cssowns the theme, responsive layout, glass/card styling, page transitions, and View Transition pseudo-elements. Check nearby selectors before adding another override.locales/zh.jsonandlocales/en.jsonare the translation sources. User-facing text added or changed in an i18n-enabled area must be updated in both files.lib/api.jsis the browser API wrapper,lib/db.jsowns the PostgreSQL pool, andlib/http-cache.jsprovides ETag/304 helpers for cacheable JSON responses.schema.sqlis shared with the Lite branch. Keep schema changes backward-compatible unless a migration and compatibility plan is explicitly requested.
UI and interaction conventions
- Support both light and dark themes. Verify page backgrounds, cards, modals, settings/admin pages, borders, and text contrast in both modes.
- Do not use browser
alert,confirm, orprompt. UseuseToast()for timed success/warning/error notices andconfirmAction()for decisions requiring user input. - Use SVG icons through
components/Icons.js; do not add emoji as interface icons. The existing empty-message greeting ending in👋is an intentional exception and must remain. - Avoid hard-coded Chinese or English in newly touched UI when a translation key is appropriate. Date formatting must follow the selected language.
- Keep settings and administration layouts responsive: content should use the available right-side width, wrap long text, and must not become wider solely because English is selected.
- Preserve the current navigation bar during page transitions unless a task explicitly requires otherwise.
View Transition rules
components/AppProvider.jsis the single coordination point for cross-page View Transitions. Do not start competing transitions from individual page components.- Shared elements must exist in both the old and new DOM snapshots and must have exactly one matching
view-transition-nameper snapshot. Apply names only to the clicked card or target element to avoid duplicates. - When the destination data is asynchronous, pass a preview object so the destination avatar, title, author, content, or other shared element renders in the first transition frame. Replace it with fetched data without remounting the shared element.
- Elements that exist only on the destination should reveal after shared geometry settles. Elements that exist only on the source should disappear before the destination content is revealed.
- Opening and returning animations should be visible inverses. On return, prefer the original
data-post-idor stored source identity; if the target is unavailable, fall back to a simple fade instead of animating to the wrong element. - Disable the default
.page-slideanimation on pages using a custom shared transition, otherwise the page will slide a second time after the transition completes. - Respect
prefers-reduced-motionand provide an immediate navigation fallback whendocument.startViewTransitionis unavailable. - For animation bugs, inspect intermediate frames and the trajectories of the outer card, lower edge, text, timestamps, badges, and background separately. Do not judge only the first and final screenshots.
API, caching, and security
- Preserve conditional GET behavior for cacheable endpoints. Use
jsonWithEtag()fromlib/http-cache.jswhere appropriate so matchingIf-None-Matchrequests return 304 without a response body. - Do not cache personalized, authenticated, rapidly changing, or mutation responses as public data.
- Never commit real JWT secrets, database credentials, cloud credentials, tokens, private keys, or local
.envfiles. Example values belong only in example configuration. - Validate and sanitize all user-controlled Markdown, uploads, identifiers, and custom content using the existing helpers and route patterns.
Validation and Git
- For ordinary code changes, run
git diff --checkandnpm run buildat minimum. - For API changes, run the focused
node:testcoverage and thennpm testwhen the required database/service is available. - For visual or animation changes, use Playwright against the local development server and check both themes and relevant viewport sizes. Keep Playwright artifacts untracked.
- Stage only files belonging to the task. Use concise commit messages that describe the outcome.
- When asked to push, fetch first if the remote has moved, rebase the scoped commit onto the latest
origin/next, resolve conflicts without discarding remote work, and never force-push unless the user explicitly authorizes it.