nextjs-fastapi-conventions
Skill1 starsChanged 39 days agoMITView on GitHub
Shared conventions for Next.js 16 + FastAPI full-stack projects. Architecture, code quality, testing, styling, and commands. Referenced by nextjs-fastapi-implementor and nextjs-fastapi-reviewer.
In this repository38 other files it gives its agents.
- agent-conductSkill
- bugfixSkill
- code-smellsSkill
- deliverSkill
- final-responseSkill
- frontend-designSkill
- go-conventionsSkill
- go-implementorSkill
- go-reviewerSkill
- go-test-strengthSkill
- implementation-principlesSkill
- nextflow-conventionsSkill
- nextflow-implementorSkill
- nextflow-reviewerSkill
- nextjs-fastapi-implementorSkill
- nextjs-fastapi-reviewerSkill
- orchestratorSkill
- phase-creatorSkill
- phase-reviewerSkill
- prose-principlesSkill
- pr-resolverSkill
- pr-reviewerSkill
- python-conventionsSkill
- python-implementorSkill
- python-reviewerSkill
- spec-authorSkill
- spec-proofreaderSkill
- spec-reviewerSkill
- spec-writerSkill
- subagentsSkill
- swift-conventionsSkill
- swift-implementorSkill
- swift-reviewerSkill
- testing-principlesSkill
- tightenSkill
- unslopSkill
- verificationSkill
- writing-for-agentsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 30
Every FastAPI response is validated on the frontend with Zod:
- Very specific: line 56
Every endpoint declares response_model and returns a Pydantic model.
- Distinctive: line 66
Import grouping: stdlib | third-party | local.
- Very specific: line 74
Import grouping: React/Next.js | third-party | local @/ (components > lib > types).
- Very specific: line 88
Treat Tailwind v4 theme variables as part of the runtime contract, not as ordinary CSS constants.
- Very specific: line 91
If dark mode is driven by next-themes with attribute="class", ensure Tailwind's dark: variant is also class-driven (for example with …
- Very specific: line 96
Use @theme inline only when utilities should inline a referenced value.
- Very specific: line 97
Do not use it for semantic colours that must change at runtime between light and dark themes.
- Very specific: line 103
When debugging Tailwind v4 styling, inspect the generated CSS or browser computed styles before changing specificity.
- Distinctive: line 115
Follow testing-principles for test intent.
- Very specific: line 143
Test every relevant theme/mode through the same mechanism the app uses in production.
- Distinctive: line 146
Avoid injecting fake probe styles into tests for the feature under test.
- Distinctive: line 148
If a visual assertion is hard to express, include a focused screenshot assertion or a small canvas/pixel sampler plus clear thresholds …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Next.js + FastAPI Conventions
Single source of truth for architecture, code quality, and testing in Next.js + FastAPI full-stack projects.
Project Stack
- Frontend: Next.js 16 (App Router) + React 19 + shadcn/ui + Tailwind CSS
v4 (TypeScript, in
frontend/) - Backend: FastAPI + Uvicorn + Pydantic (Python 3.11+, in
backend/)
Architecture
BFF Pattern
The browser NEVER calls FastAPI directly. All backend communication flows through the Next.js server layer:
- Server Actions (
app/actions.ts) handle mutations. Client components call these; they run on the Next.js server and proxy to FastAPI. - API Routes (
app/api/*/route.ts) exist ONLY for external consumers (health checks, webhooks), NOT for frontend use.
Type Safety (Zod Contracts)
Every FastAPI response is validated on the frontend with Zod:
lib/contracts.ts: Zod schemas mirroring Pydantic models.lib/backend-client.ts:backendJson()fetches + validates against Zod.- Contract breaks fail fast with
BackendRequestError.
New endpoint checklist:
- Pydantic response model in
backend/api/schemas.py. - Matching Zod schema in
frontend/lib/contracts.ts. - Contract test in
frontend/tests/contracts.test.ts. backendJson()with schema in Server Action.
Components
- Server Components (default): fetch data, pass as props.
- Client Components (
'use client'): interactivity, browser APIs, hooks.
React 19
useActionState(NOT deprecateduseFormState).- Explicit state types (e.g.
GreetingStateinlib/greeting-state.ts).
Backend Structure
- Lifespan via
@asynccontextmanager(NOT@app.on_event). pydantic-settingsfor typed config from env vars.- Versioned routers under
api/v1/. - Every endpoint declares
response_modeland returns a Pydantic model.
Code Quality
Python
- Async endpoints,
httpx.AsyncClient(notrequests). - Type hints everywhere.
Annotatedfor FastAPI params. - Docstrings on modules, classes, public functions.
HTTPExceptionfor API errors. No swallowed exceptions.- Import grouping: stdlib | third-party | local.
TypeScript
strict: true. Neverany(preferunknown+ narrowing).- Zod for all external data; derive types with
z.infer<>. - Server Actions:
'use server', return typed state objects. - shadcn/ui components from
components/ui/. - Import grouping: React/Next.js | third-party | local
@/(components > lib > types). - Tailwind v4 semantic tokens (
text-foreground,bg-muted), not raw colours.
Styling
- Tailwind utility classes in JSX.
cn()fromlib/utils.tsfor conditional classes. - Semantic tokens from
@theme, not raw colour values. - Mobile-first responsive (
sm:,md:,lg:). - CVA for component variants. Sonner for toasts. next-themes for theming.
Tailwind v4 Runtime Theming
- Treat Tailwind v4 theme variables as part of the runtime contract, not as
ordinary CSS constants. Read the project's actual
globals.css/theme setup before changing visual states. - If dark mode is driven by
next-themeswithattribute="class", ensure Tailwind'sdark:variant is also class-driven (for example with@custom-variant dark (&:where(.dark, .dark *));). Do not assume.darkaffects Tailwind utilities when the compiled CSS still usesprefers-color-scheme. - Use
@theme inlineonly when utilities should inline a referenced value. Do not use it for semantic colours that must change at runtime between light and dark themes; compiled utilities may freeze light-mode literals such as#ffffffor#e2e8f0. - For semantic colours that must respond to theme changes, prefer utilities
that compile to runtime CSS variables, explicit arbitrary values such as
bg-[var(--color-card)], or small custom CSS rules that usevar(...). - When debugging Tailwind v4 styling, inspect the generated CSS or browser
computed styles before changing specificity. Cascade layers,
!important, and@theme inlinecan make source CSS misleading.
File Organisation
- Pages in
app/(App Router). Reusable components incomponents/. - shadcn/ui in
components/ui/(don't edit directly). - Shared utils/types in
lib/. Import via@/.
Testing
- Follow testing-principles for test intent; this section covers stack mechanics.
Backend (pytest)
pytest+pytest-asyncio(auto mode).httpx.AsyncClient+ASGITransportagainst FastAPIapp.- Assert status codes AND JSON payloads.
@pytest.mark.anyiofor async tests.
Frontend (Vitest)
environment: 'node'. Tests infrontend/tests/*.test.ts.- Contract tests:
.parse()and.safeParse()against schemas. describe/itblocks,expect()matchers.
Visual and Perceptual UI Tests
- For styling bugs that users perceive visually (contrast, borders, selection, focus rings, dark mode, animations), prefer real-browser tests with Playwright over jsdom-only tests.
- A test that reads source CSS text, checks for a class name, or asserts only a computed property is not sufficient for a visual regression. It can be useful as a guard, but it does not prove the rendered UI is visible.
- Assert the user-visible result: compare screenshots or sample rendered pixels
from the affected element and its surroundings. For borders and rings, check
frame pixels against the element fill and neighbouring cells/surfaces, not
just
borderTopColoragainst another element's border. - Test every relevant theme/mode through the same mechanism the app uses in
production. If dark mode is class-driven, set the class and verify compiled
CSS responds to it; if it is media-driven, use
page.emulateMedia(). - Avoid injecting fake probe styles into tests for the feature under test. Load the real app stylesheet and fail against the actual cascade.
- If a visual assertion is hard to express, include a focused screenshot assertion or a small canvas/pixel sampler plus clear thresholds derived from visible contrast, not from the implementation details of a chosen token.
Commands
Backend
cd backend && python -m pytest tests/ -v # all tests
cd backend && python -m pytest tests/ -v -k <name> # specific test
cd backend && ruff check --fix . && ruff format . # lint+fix
cd backend && ruff check . && ruff format --check . # lint check onlyFrontend
cd frontend && pnpm test # all tests
cd frontend && pnpm test:watch # watch mode
cd frontend && pnpm lint # lint
cd frontend && pnpm format # formatDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

