Web frameworks · Beginner · 20 min
Start a community library app with Next.js 16
By Padding · Updated 18 Nov 2026
Next.js 16.4 · React 19.3 · Node.js 26 · node:26 image
You will plan a small community library app, create it with Next.js 16.4, and end with a navigable skeleton of a home page, a book list and a page per book, styled with CSS Modules, plus a written data model for the rest of the series.
On this page
This series builds one real app from an empty folder to a running server: a catalogue and lending desk for a small community library. Members browse the books. Librarians sign in, add and edit books, lend them out and take them back. By the last part it stores data in SQLite, checks who is allowed to change what, keeps lending correct when two people click at once, has tests and runs on your own Linux server.
This first part sets the foundations. You write down what the app has to do and what it stores, then create the Next.js 16 project and build the pages a visitor moves between: a home page, a list of books and a page for each book, with a shared header and a page for addresses that do not exist. The books come from a small placeholder module for now. Part 2 swaps that module for a database without touching the pages, which is why the pages only ever call two functions, getBooks() and getBook(id).
You use plain CSS Modules for styling, not Tailwind, so every style is in a file you can read. If you have not used the App Router before, How to Build Your First Next.js 16 App with the App Router covers its building blocks on a small content site. This tutorial assumes Node.js 26 from the Node.js install tutorial.
Step 1 · Create the project
Run create-next-app at an exact version so you get the same files as this tutorial. The flags choose TypeScript, no Tailwind CSS, ESLint, the App Router, a src/ folder, npm and the @/ import alias, and --yes accepts the defaults for anything not given, so the command asks no questions:
cd ~
npx create-next-app@16.4.6 community-library-demo --ts --no-tailwind --eslint --app --src-dir --use-npm --import-alias "@/*" --yes
cd community-library-demoIt downloads and installs the dependencies, which takes a minute or two on a good connection. On metered or prepaid data, expect a few hundred megabytes into node_modules; later parts reuse the same folder, so you download this once.
Look at what you got:
ls
ls src/app
npm ls next react react-domCheck it worked
create-next-app ends with Success! Created community-library-demo. The project root holds package.json, next.config.ts, tsconfig.json, eslint.config.mjs and public/, and src/app holds layout.tsx, page.tsx, page.module.css and globals.css. npm ls shows next@16.4.6 with react and react-dom at 19.3, the versions this template pins. The project also has an AGENTS.md file with notes for AI coding tools. If Git is installed and has your name and email set, the folder is also a Git repository with a first commit. If git status says it is not a repository, run git init in the folder; part 2 uses Git's ignore file to keep the database file out of it.
Step 2 · Write down what the app stores
Before you write pages, decide what the app is about. A short plan in the repository saves arguments with yourself later, and every later part of this series points back to it. Create it as a Markdown file:
mkdir -p docs
cat > docs/data-model.md <<'MD'
# Community library: data model
## Who uses it
- Members: anyone can browse the catalogue and see if a book is on the shelf.
- Librarians: sign in to add and edit books, lend books and record returns.
## What it stores
### books
- id: whole number, assigned by the database
- title: text, required
- author: text, required
- year: whole number, year first published
- isbn: text, optional, unique when present
- addedAt: date and time the library got the copy
### members
- id: whole number
- name: text, required (any script: Yorùbá, Amharic, Arabic and Latin names all work)
- phone: text, optional, the way most members are reached
- joinedAt: date
### loans
- id: whole number
- bookId: the book lent
- memberId: the member who has it
- lentAt: date and time
- dueAt: date, 14 days after lentAt
- returnedAt: date and time, empty while the book is out
### librarians
- Accounts that can sign in. Stored by the sign-in library in part 5.
## Rules
1. A book is available when it has no loan with an empty returnedAt.
2. A book can be out on only one loan at a time.
3. A member can hold at most three books at once.
4. A loan is overdue when today is after dueAt and returnedAt is empty.
5. Only a signed-in librarian can change data. Everyone can read the catalogue.
MDNotice that a book does not have an "available" column. Availability is worked out from the loans, so the two can never disagree. The placeholder data in this part still carries an available flag to make the pages look real; part 2 replaces it with the rule above.
Check it worked
Run cat docs/data-model.md and read it through. It lists four kinds of record (books, members, loans, librarians) and five numbered rules. If your library works differently, for example a two-book limit or a 21-day loan, change the file now: the rules in later parts follow it.
Step 3 · Start the dev server
In your second terminal, inside ~/community-library-demo, start the development server. It stays in the foreground and reloads the page when you save a file:
npm run devThe terminal prints the Next.js version, Local: http://localhost:3000 and Ready. Back in the first terminal, fetch the starter page:
curl -s http://localhost:3000/ | grep -o '<title>[^<]*</title>'Check it worked
The output is <title>Create Next App</title>. Open http://localhost:3000 in a browser and you see the starter page. Leave the server running for the next steps.
Step 4 · Add the root layout, header and global styles
The root layout wraps every page. Replace the starter version with one that sets the site title, loads the global styles and shows a header on every page. The starter layout loads web fonts from Google; this one uses the system font, so pages need no font download, which also helps visitors on slow mobile connections.
Write the global styles first. They set colours and type for the whole site and nothing else:
cat > src/app/globals.css <<'CSS'
:root {
--ink: #16181d;
--muted: #5b616b;
--line: #d9dce1;
--paper: #ffffff;
--shelf: #f1f2f4;
--accent: #1f5c4a;
}
* {
box-sizing: border-box;
}
html {
color: var(--ink);
background: var(--paper);
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.5;
}
body {
margin: 0;
}
a {
color: var(--accent);
}
main {
max-width: 48rem;
margin: 0 auto;
padding: 1.5rem 1rem 3rem;
}
h1 {
font-size: 1.75rem;
line-height: 1.2;
margin: 0 0 0.75rem;
}
CSSThe header is its own component with its own CSS Module. A CSS Module is a .module.css file whose class names are local to the component that imports it, so .nav here can never clash with a .nav anywhere else:
mkdir -p src/components
cat > src/components/site-header.module.css <<'CSS'
.header {
border-bottom: 1px solid var(--line);
background: var(--shelf);
}
.inner {
max-width: 48rem;
margin: 0 auto;
padding: 0.75rem 1rem;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.5rem 1.5rem;
}
.name {
font-weight: 700;
color: var(--ink);
text-decoration: none;
}
.nav {
display: flex;
gap: 1rem;
}
CSS
cat > src/components/site-header.tsx <<'TSX'
import Link from "next/link";
import styles from "./site-header.module.css";
export default function SiteHeader() {
return (
<header className={styles.header}>
<div className={styles.inner}>
<Link href="/" className={styles.name}>
Community Library
</Link>
<nav aria-label="Main" className={styles.nav}>
<Link href="/">Home</Link>
<Link href="/books">Books</Link>
</nav>
</div>
</header>
);
}
TSXNow the layout. The metadata export gives every page a title, and the template adds the library's name after each page's own title:
cat > src/app/layout.tsx <<'TSX'
import type { Metadata } from "next";
import SiteHeader from "@/components/site-header";
import "./globals.css";
export const metadata: Metadata = {
title: { default: "Community Library", template: "%s · Community Library" },
description: "Browse the catalogue of a small community library.",
};
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>
<SiteHeader />
{children}
</body>
</html>
);
}
TSXLayoutProps<"/"> is a type Next.js generates from your routes, so children is typed without you declaring it. The header is a Server Component: it runs on the server and sends HTML, with no JavaScript of its own. Link still makes moves between pages fast, by loading the next page's data without a full reload.
Check it worked
Refresh the browser. A grey bar across the top shows "Community Library" on the left and Home and Books links on the right, above the starter content. From the terminal:
curl -s http://localhost:3000/ | grep -o '<nav aria-label="Main"[^>]*>'This prints the opening nav tag, with a generated class name such as site-header-module__...__nav (the exact name differs on your machine). The generated name is how CSS Modules keep class names local.
Step 5 · Add placeholder books and the book list
Put the books in one module. Every page gets its data through the two functions it exports, and both are async already, so part 2 can make them read from a database and no page has to change:
mkdir -p src/lib
cat > src/lib/books.ts <<'TS'
// Placeholder data for part 1. Part 2 replaces this module's insides
// with database queries and keeps the same two functions.
export type Book = {
id: number;
title: string;
author: string;
year: number;
available: boolean;
};
const books: Book[] = [
{ id: 1, title: "Things Fall Apart", author: "Chinua Achebe", year: 1958, available: true },
{ id: 2, title: "Half of a Yellow Sun", author: "Chimamanda Ngozi Adichie", year: 2006, available: false },
{ id: 3, title: "Weep Not, Child", author: "Ngũgĩ wa Thiong'o", year: 1964, available: true },
{ id: 4, title: "So Long a Letter", author: "Mariama Bâ", year: 1979, available: true },
{ id: 5, title: "A Brief History of Time", author: "Stephen Hawking", year: 1988, available: false },
{ id: 6, title: "The Joys of Motherhood", author: "Buchi Emecheta", year: 1979, available: true },
];
export async function getBooks(): Promise<Book[]> {
return books;
}
export async function getBook(id: string): Promise<Book | undefined> {
return books.find((book) => String(book.id) === id);
}
TSNames such as Ngũgĩ and Bâ are ordinary text in a UTF-8 file. Next.js serves pages as UTF-8, so they show correctly in any browser, and the same holds for member names in Yorùbá, Amharic or Arabic later on.
A folder under src/app is a route, and its page.tsx is the page. The list page lives at /books, with its own CSS Module next to it:
mkdir -p src/app/books
cat > src/app/books/books.module.css <<'CSS'
.list {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 0.75rem;
}
.card {
border: 1px solid var(--line);
border-radius: 0.5rem;
padding: 0.75rem 1rem;
}
.title {
font-weight: 600;
}
.meta {
color: var(--muted);
margin: 0.25rem 0 0;
}
.status {
display: inline-block;
margin-top: 0.5rem;
font-size: 0.875rem;
padding: 0.125rem 0.5rem;
border-radius: 1rem;
background: var(--shelf);
}
CSS
cat > src/app/books/page.tsx <<'TSX'
import type { Metadata } from "next";
import Link from "next/link";
import { getBooks } from "@/lib/books";
import styles from "./books.module.css";
export const metadata: Metadata = { title: "Books" };
export default async function BooksPage() {
const books = await getBooks();
return (
<main>
<h1>Books</h1>
<p>{books.length} books in the catalogue.</p>
<ul className={styles.list}>
{books.map((book) => (
<li key={book.id} className={styles.card}>
<Link href={`/books/${book.id}`} className={styles.title}>
{book.title}
</Link>
<p className={styles.meta}>
{book.author}, {book.year}
</p>
<span className={styles.status}>
{book.available ? "On the shelf" : "On loan"}
</span>
</li>
))}
</ul>
</main>
);
}
TSXThe page is an async Server Component, so it can await its data directly. There is no loading state to write and no data request from the browser.
Check it worked
Click Books in the header. You see "6 books in the catalogue." and six cards, each with a linked title, the author and year, and "On the shelf" or "On loan". From the terminal, count the links to book pages:
curl -s http://localhost:3000/books | grep -o 'href="/books/[0-9]*"' | sort -uThe output is six lines, href="/books/1" to href="/books/6". The links lead to a 404 page for now; the next step adds the pages they point to.
Step 6 · Add a page for each book and a not-found page
A folder name in square brackets is a dynamic segment. src/app/books/[id]/page.tsx answers /books/1, /books/2 and any other value, and receives the value in params. In Next.js 16 params is a promise, so you await it:
mkdir -p "src/app/books/[id]"
cat > "src/app/books/[id]/page.tsx" <<'TSX'
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { getBook, getBooks } from "@/lib/books";
export async function generateStaticParams() {
const books = await getBooks();
return books.map((book) => ({ id: String(book.id) }));
}
export async function generateMetadata({
params,
}: PageProps<"/books/[id]">): Promise<Metadata> {
const { id } = await params;
const book = await getBook(id);
return { title: book ? book.title : "Book not found" };
}
export default async function BookPage({ params }: PageProps<"/books/[id]">) {
const { id } = await params;
const book = await getBook(id);
if (!book) notFound();
return (
<main>
<p>
<Link href="/books">Back to all books</Link>
</p>
<h1>{book.title}</h1>
<dl>
<dt>Author</dt>
<dd>{book.author}</dd>
<dt>First published</dt>
<dd>{book.year}</dd>
<dt>Status</dt>
<dd>{book.available ? "On the shelf" : "On loan"}</dd>
</dl>
</main>
);
}
TSXThree things to notice:
generateStaticParamslists the ids that exist, so the production build can make those pages ahead of time. A new Next.js 16 project has Cache Components switched on innext.config.ts, and with it this function must return at least one id.generateMetadatagives each book page its own title, such as "Weep Not, Child · Community Library".notFound()stops rendering and shows the nearest not-found page when the id matches no book.
Now write that not-found page. A not-found.tsx in src/app covers the whole site, including addresses no route matches:
cat > src/app/not-found.tsx <<'TSX'
import Link from "next/link";
export default function NotFound() {
return (
<main>
<h1>Not on our shelves</h1>
<p>We could not find that page or book.</p>
<p>
<Link href="/books">Browse all books</Link>
</p>
</main>
);
}
TSXCheck it worked
Click "Weep Not, Child" on the list. The page shows the title as its heading, Ngũgĩ wa Thiong'o as the author, 1964, and "On the shelf", and the browser tab reads "Weep Not, Child · Community Library". Then change the address to /books/999. From the terminal:
curl -s http://localhost:3000/books/3 | grep -o '<h1>[^<]*</h1>\|<dd>[0-9]*</dd>'
curl -s http://localhost:3000/books/999 | grep -o 'noindex\|Not on our shelves' | sort -u
curl -s http://localhost:3000/no-such-page | grep -o '<h1>[^<]*</h1>'The first command prints <h1>Weep Not, Child</h1> and <dd>1964</dd>. The last prints <h1>Not on our shelves</h1>. The middle one prints Not on our shelves and noindex: Next.js adds a noindex tag to not-found pages so search engines skip them, and for an unknown book id the not-found content arrives in the streamed page data that the browser renders, so there is no plain <h1> in the HTML for grep to find. The browser shows the same heading either way. The dev server answers that address with HTTP status 404, but the production build you run in the last step answers 200, because with Cache Components the page starts streaming before the id is checked; part 3 comes back to this when the books live in the database.
Step 7 · Replace the home page
The starter home page still shows the Next.js logo. Replace it with a short welcome that reads the catalogue, and replace its CSS Module too:
cat > src/app/page.module.css <<'CSS'
.lead {
font-size: 1.125rem;
color: var(--muted);
margin: 0 0 1.5rem;
}
.stats {
display: flex;
gap: 1rem;
flex-wrap: wrap;
margin: 0 0 1.5rem;
padding: 0;
list-style: none;
}
.stats li {
background: var(--shelf);
border-radius: 0.5rem;
padding: 0.75rem 1rem;
}
.number {
display: block;
font-size: 1.5rem;
font-weight: 700;
}
.button {
display: inline-block;
background: var(--accent);
color: var(--paper);
padding: 0.625rem 1rem;
border-radius: 0.375rem;
text-decoration: none;
}
CSS
cat > src/app/page.tsx <<'TSX'
import Link from "next/link";
import { getBooks } from "@/lib/books";
import styles from "./page.module.css";
export default async function HomePage() {
const books = await getBooks();
const onShelf = books.filter((book) => book.available).length;
return (
<main>
<h1>Community Library</h1>
<p className={styles.lead}>
Find a book, see if it is on the shelf, and ask a librarian to lend it to you.
</p>
<ul className={styles.stats}>
<li>
<span className={styles.number}>{books.length}</span> books
</li>
<li>
<span className={styles.number}>{onShelf}</span> on the shelf
</li>
</ul>
<Link href="/books" className={styles.button}>
Browse books
</Link>
</main>
);
}
TSX
rm -f public/next.svg public/vercel.svg public/file.svg public/globe.svg public/window.svgThe last line removes the starter images, which nothing uses any more.
Check it worked
The home page shows the heading "Community Library", the two counts and a green "Browse books" button that opens the list. From the terminal:
curl -s http://localhost:3000/ | grep -o '<title>[^<]*</title>\|Browse books'The output is <title>Community Library</title> and Browse books. Stop the dev server with Ctrl+C in its terminal.
Step 8 · Lint, build and run the production version
Run the linter, then a production build. The build compiles every page, checks the TypeScript types and decides which pages it can make ahead of time:
npm run lint
npm run buildCheck it worked
npm run lint prints no errors. The build ends with a route table something like this one, with a legend under it explaining the symbols:
Route (app)
┌ ○ /
├ ○ /_not-found
├ ○ /books
└ /books/[id]
├ ◐ /books/[id]
├ ○ /books/1
├ ○ /books/2
└ ◐ [+4 more paths]○ means the page was made at build time. The book pages are listed because of generateStaticParams, and the build makes all six. ◐ is a partial prerender: a shell built ahead of time with the rest streamed at request time, which is how an id that is not in the list gets its page. Start the production server:
npm run startOpen http://localhost:3000 and click through: home, Browse books, a book, Back to all books, then /books/999. Every page has the header, and the move between pages happens without a full page reload.
The production server answers the same pages as the dev server:
curl -s http://localhost:3000/books/1 | grep -o '<h1>[^<]*</h1>'This prints <h1>Things Fall Apart</h1>. Stop the server with Ctrl+C. Keep the ~/community-library-demo folder: part 2 continues in it.
Next steps
- Continue the series: Store the library books in SQLite with Drizzle ORM turns
docs/data-model.mdinto tables and makesgetBooks()read from a database. - After that, List and search books with server components and URL search params adds search and paging to the list page you built here.
- For the App Router building blocks on their own, including client components and route handlers, see How to Build Your First Next.js 16 App with the App Router.
- Read the documentation for your exact Next.js version offline, in
node_modules/next/dist/docsinside the project.
Part of these paths
Related tutorials
- How to Build Your First Next.js 16 App with the App RouterYou will create a Next.js 16 app, add pages, a shared layout, a dynamic route that is built ahead of time, one interactive component and a JSON route, then run a production build and read what Next.js decided to prerender.
- Store the library books in SQLite with Drizzle ORMYou will turn the library's data model into SQLite tables with Drizzle ORM 0.45, create them with drizzle-kit migrations, seed twenty books, and end with a server-only data module that the Next.js pages read the catalogue from.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials