The basics
This page introduces the front-end tools one by one, for someone who has never used them.
JavaScript and Node.js
JavaScript is the language of the web. It runs in the browser, but also on a server thanks to Node.js. Here, the front-end code runs mostly on the server: Node.js builds the pages.
npm installs the libraries listed in package.json. npm ci installs exactly the versions written in package-lock.json: that is what we use in CI and in Docker, to get the same versions everywhere.
React: components
splits the interface into components: functions that receive data (the props) and return HTML (written in JSX).function Hello({ name }) {
return <p>Hello {name}</p>
}In the project, ProductList receives the product list and returns an HTML table.
Next.js: the framework around it
adds to React everything a real site needs:| What Next.js handles | How, in the project |
|---|---|
| Pages | A folder in app/ = an address. app/page.js = / |
| Server routes | app/api/health/route.js answers GET /api/health |
page.js is an async function that calls the API before sending the HTML | |
| Forms | The in app/actions.js |
| Production build | next build, in mode |
Server components and client components
By default, a Next.js component is a server component: it runs on the server, never in the browser. It can therefore call the API and read .
A file starting with 'use client' holds a client component: it is also sent to the browser, so it can react to clicks and typing. In the project, only ProductForm.js is one, because it shows an "Ajout…" (adding) state while sending.
Server Actions
A file starting with 'use server' holds Server Actions. You pass them to a form (<form action={addProduct}>): when the user submits, the browser sends the form and the function runs on the server. No need to write an API route by hand.
Jest and Testing Library: tests
runs the__tests__/*.test.js files. Testing Library renders a component in a fake browser (jsdom) and lets you look for a text or a button the way a user would.Tests never talk to the real API: fetch or modules are replaced by .
ESLint: linting
ESLint reads the code without running it and reports errors and bad practices. The project uses the official Next.js rules (eslint-config-next).
Docker
The front end ships in a . There are two recipes: Dockerfile.dev and Dockerfile.prod. Their differences are in Configuration, tests, build, and Docker itself is explained in Docker, Compose and Swarm.