Skip to content

Folder layout ​

web/
├── app/                      # everything Next.js serves
│   ├── layout.js             # the shared HTML frame: "Trinity" header
│   ├── page.js               # the / page: list + form
│   ├── actions.js            # Server Actions: add, delete
│   ├── globals.css           # styles and colours (light and dark)
│   └── api/health/route.js   # GET /api/health
├── components/
│   ├── ProductList.js        # the product table
│   └── ProductForm.js        # the add form (client component)
├── lib/
│   └── products.js           # API calls, and nothing else
├── __tests__/                # one test file per code file
├── Dockerfile.dev            # development image
├── Dockerfile.prod           # production image
├── .gitlab-ci.yml            # web:lint, web:test, web:build jobs
├── .env.example              # expected variables, without real values
├── next.config.mjs           # output: 'standalone'
├── jest.config.mjs           # Jest + coverage reports
└── eslint.config.mjs         # Next.js rules

The layout rule ​

FolderContainsMay call
app/pages, routes and actionscomponents/, lib/
components/display componentsapp/actions.js (for forms)
lib/API access logicfetch, nothing else

Why isolate the API in lib/? If the API address or format changes, only one file needs editing. And tests can replace that single module with a .

Tests ​

FileTests
health.test.jsapp/api/health/route.js
products.test.jslib/products.js
actions.test.jsapp/actions.js
page.test.jsapp/page.js
ProductList.test.jscomponents/ProductList.js
ProductForm.test.jscomponents/ProductForm.js