Skip to content
Visual explainer 3h to learn 4 steps

Design the app: pages, data model & component tree

Wireframes, a route map and a typed data model ready to build from.

By Invicly Tech, , in Frontend with React & Next.js. About 11 minutes to read.

Topic 35 of 36

In short

Planning before coding saves rework. Sketch each page, list the routes, define a typed data model and plan the component tree so the build follows a clear map.

Explained simply

Before you write code for a real app, spend a few hours designing it on paper. You decide what pages exist, what each one shows, what data you store and how the screens are split into components. Changing a sketch takes seconds; changing finished code takes days.

A wireframe is a rough drawing of a page: boxes for images, lines for text, rectangles for buttons. No colours, no fonts. It answers one question: what is on this page and where? Draw each page on a phone screen first, because small screens force clear choices.

Next you write a route map, a list of every URL in your app, and a data model, the shapes of the records you will save, written as TypeScript types. These two lists tell you which pages need which data.

Finally you plan the component tree: which pieces each page is made of, which ones only display data, and which ones react to clicks and typing. With this map, building becomes filling in boxes you already understand.

Press Play on a diagram to walk through it one step at a time.

FlowDesign before you build
  1. Step 1
    Wireframes

    Rough sketches of every page and state

  2. Step 2
    Route map

    URLs, layouts and which pages need auth

  3. Step 3
    Data model

    TypeScript types and database tables

  4. Step 4
    Component tree

    Server vs client components per page

MapExample: habit tracker routes
app/
  • / (landing)
  • /login
  • /habits
    • HabitList
    • AddHabitForm
  • /habits/[id]
    • HabitStats
    • CheckInCalendar
CompareServer or client component?
Server Component (default)
  • Fetches data directly, can use secrets
  • No JavaScript of its own shipped
  • No useState, useEffect or onClick
  • Pages, lists, layouts, static text
Client Component ("use client")
  • State, effects and event handlers
  • Browser APIs like localStorage
  • Shipped and hydrated in the browser
  • Forms, toggles, menus, charts

In depth

Wireframes that include every state

Most beginner apps look great with perfect demo data and break on everything else. For each page, sketch at least five states. Empty: a new user with no habits needs a friendly message and an obvious first action. Loading: what shows while data arrives, ideally a skeleton the same size as the real content so nothing jumps. Error: a clear message and a way to retry. Success: the normal view. Edge: a very long habit name, 200 items, or a slow phone screen.

Keep wireframes low-fidelity, on paper or in a tool like Excalidraw or Figma, so you focus on structure, not colours. Mark what is interactive (buttons, forms, toggles) and where users go next. Sketch the mobile layout first, then note what changes on wide screens, such as a sidebar that becomes a top menu. Each sketch then becomes a checklist for the build and for your tests.

  • Empty, loading, error, success, edge cases
  • Mobile first, then wide screens
  • Mark every action and where it leads

From route map to App Router folders

Write each URL with what it shows and who may see it: / (public landing), /login (public), /habits (signed in: list and add form), /habits/[id] (signed in, owner only: stats and calendar). Each line maps to a folder with a page.tsx. Square brackets make a dynamic segment; in current Next.js the page receives params as a promise, so you write const { id } = await params.

Plan the special files too. layout.tsx wraps a segment and its children and keeps its state while you navigate inside it. loading.tsx shows instantly while the page's data loads. error.tsx catches errors in that segment and must be a client component. not-found.tsx handles notFound() calls, such as an unknown habit id. Route groups, folders in parentheses like (marketing) and (app), organise routes and give them different layouts without appearing in the URL. Putting all signed-in pages under (app) gives them one shared layout with the navigation.

LayersWhat wraps /habits/[id] (outer to inner)
  1. 1
    app/layout.tsx

    html, body, fonts, global styles

  2. 2
    app/(app)/layout.tsx

    Navigation for signed-in pages

  3. 3
    app/(app)/habits/[id]/loading.tsx

    Skeleton while data loads

  4. 4
    app/(app)/habits/[id]/error.tsx

    Client boundary for errors

  5. 5
    app/(app)/habits/[id]/page.tsx

    Fetches the habit, renders stats

A data model that the database can enforce

List the entities (User, Habit, CheckIn), their fields and how they relate: a user has many habits, a habit has many check-ins. Every user-owned row needs a userId, because every query will filter by it. Give rows a stable id (a UUID is common) and a createdAt timestamp.

Then ask what must always be true, and let the database enforce it: a habit name is not null, a check-in references an existing habit (a foreign key, with cascade delete so removing a habit removes its check-ins), and there is at most one check-in per habit per day (a unique constraint on habitId plus day). Decide how to store dates: a check-in belongs to the user's calendar day, so store the day as YYYY-MM-DD in the user's time zone, not a UTC timestamp that can fall on the wrong day. Finally, generate TypeScript types from the schema with your ORM, and describe form input separately with Zod.

Planning the component tree and the client boundary

In the App Router every component is a Server Component unless its file starts with "use client". Server Components can fetch data directly and send no JavaScript for themselves to the browser. Client Components are needed for state, effects, event handlers and browser APIs. So, for each box in your wireframe, ask: does it respond to clicks or typing? If not, it stays on the server.

Push the client boundary down to the leaves. The habits page (server) fetches the list and renders HabitList (server), which renders a small CheckInButton (client) for each row. Everything imported by a client file also becomes client code, so keep client files small. Props passed from server to client must be serialisable: strings, numbers, plain objects, arrays and dates, but not ordinary functions (server actions are the exception). Mutations go through server actions, so client components call an action instead of fetching an API you have to build yourself.

MapComponent tree for /habits
HabitsPage (server, fetches data)
  • PageHeader (server)
    • Title and count
  • AddHabitForm (client)
    • useActionState
    • Calls createHabit action
  • HabitList (server)
    • HabitRow (server)
    • CheckInButton (client)
  • EmptyState (server)
    • Shown when the list is empty

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Sketch wireframes for each page~45m
  2. 2
    Write a route map~45m
  3. 3
    Define the typed data model~45m
  4. 4
    Plan the component tree~45m

Key points

  • Sketch empty, loading and error states, not just the happy path.
  • Write the data model as TypeScript types before creating tables.
  • Mark which components need interactivity; the rest stay server components.
  • Keep scope small enough to finish, deploy and polish.

Key terms

Tap a card to flip it. 0/4 known

Examples

ts
export type User = { id: string; email: string };

export type Habit = {
  id: string;
  userId: string;
  name: string;
  createdAt: Date;
};

export type CheckIn = {
  id: string;
  habitId: string;
  date: string; // YYYY-MM-DD
};

A typed data model for a habit tracker.

A route map turned into folders

Step 1: list each URL with its access rule. Step 2: put public pages in a (marketing) group and signed-in pages in an (app) group, each with its own layout. Step 3: add loading and error files where data is fetched. Step 4: the folder tree now mirrors the route map exactly, so anyone can find the code for a URL.

text
URL              Access        Shows
/                public        landing, sign-up button
/login           public        sign-in form
/habits          signed in     list, add form, empty state
/habits/[id]     owner only    stats, check-in calendar

app/
  layout.tsx
  (marketing)/page.tsx          -> /
  (marketing)/login/page.tsx    -> /login
  (app)/layout.tsx              nav, session check
  (app)/habits/page.tsx         -> /habits
  (app)/habits/loading.tsx
  (app)/habits/[id]/page.tsx    -> /habits/123
  (app)/habits/[id]/not-found.tsx

The data model as a database schema with constraints

This sketch uses Drizzle ORM with Postgres; Prisma works the same way with a different syntax. Step 1: every habit has a userId. Step 2: check-ins reference habits with cascade delete. Step 3: a unique constraint allows only one check-in per habit per day. Step 4: $inferSelect turns the table into a TypeScript type, so the types and the database never drift apart.

ts
import { date, pgTable, text, timestamp, unique, uuid } from 'drizzle-orm/pg-core';

export const habits = pgTable('habits', {
  id: uuid('id').primaryKey().defaultRandom(),
  userId: text('user_id').notNull(),
  name: text('name').notNull(),
  createdAt: timestamp('created_at').defaultNow().notNull(),
});
export const checkIns = pgTable('check_ins', {
  id: uuid('id').primaryKey().defaultRandom(),
  habitId: uuid('habit_id').notNull().references(() => habits.id, { onDelete: 'cascade' }),
  day: date('day').notNull(), // 'YYYY-MM-DD' in the user's time zone
}, (t) => [unique().on(t.habitId, t.day)]);
export type Habit = typeof habits.$inferSelect;

Quick reference

  • Sketch empty, loading, error, success and edge states for every page
  • One line per URL: path, who may see it, what it shows
  • [id] folders are dynamic segments; await params in the page
  • (group) folders share a layout without changing the URL
  • error.tsx must be a client component; loading.tsx shows during data loads
  • Every user-owned table has a userId; every query filters by it
  • Let the database enforce rules: not null, foreign keys, unique constraints
  • Server Components by default; "use client" only on interactive leaves

Common mistakes

  • Starting to code without deciding which data each page needs.
  • Planning too many features to finish in the time available.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1What does the folder app/(app)/habits/page.tsx map to?

Question 2

2Which component should usually be a Client Component?

Question 3

3How do you guarantee only one check-in per habit per day, even with double clicks?

Question 4

4Why sketch an empty state for the habits page?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Write a route map for a recipe manager: public browsing, a signed-in area to add and edit your own recipes, and a recipe detail page.

  2. Exercise 2medium

    Write TypeScript types for Recipe and Ingredient, and a Zod schema for the create-recipe form input.

  3. Exercise 3hard

    For the recipe detail page, list its components, mark each server or client, and justify the choice.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need Figma to design a web app?
No. Paper, a whiteboard or a free tool like Excalidraw is enough for wireframes. Figma helps when you want detailed visual designs or need to share designs with a team.
How do I decide between Server and Client Components?
Start with Server Components everywhere. Add "use client" only to components that need state, effects, event handlers or browser APIs, and keep those components as small as possible.
Prisma or Drizzle for a Next.js project?
Both are popular TypeScript ORMs with migrations and generated types. Drizzle stays close to SQL and is lightweight; Prisma has its own schema language and a very polished tooling experience. Either is a fine choice for a capstone.
How big should a capstone app be?
Small enough to finish, test and deploy: about three to five pages and one or two core features done well. A polished small app impresses more than a large unfinished one.
ShareXLinkedInWhatsApp