Section 03: Understanding Structure
Now that you've made your first code change, let's understand how the K12worX website is organized. This section explains the App Router, pages, components, and layouts that form the foundation of the codebase.
What You'll Learn
- How Next.js App Router maps folders to URLs
- How pages and routing work
- What components are and how to use them
- How layouts wrap pages with shared UI
- The relationship between files and what you see in the browser
Why This Matters
Understanding the structure is like having a map of a city. Once you know how it's organized, you can:
- Find any file quickly
- Know where to add new features
- Understand how changes affect the site
- Navigate confidently without getting lost
The Big Picture
Our website structure:
website/
├── app/ # Pages and routes
│ ├── layout.tsx # Root layout (wraps everything)
│ ├── page.tsx # Homepage (/)
│ ├── about/
│ │ └── page.tsx # About page (/about)
│ ├── contact/
│ │ └── page.tsx # Contact page (/contact)
│ └── ... # More pages
│
├── components/ # Reusable UI pieces
│ ├── layout/ # Layout components
│ │ ├── Header.tsx
│ │ ├── Navigation.tsx
│ │ ├── Footer.tsx
│ │ ├── DefaultLayout.tsx
│ │ └── ...
│ └── content/ # Content components
│ ├── ContactForm.tsx
│ └── ...
│
└── public/ # Static assets (images, icons)
├── images/
└── icons/
Key principle: File structure determines URL structure!
Estimated Time
3-4 hours (reading and exploring the codebase)
Sections
Read these in order:
Learning Approach
Follow Along in VS Code
As you read each section:
- Open the mentioned files in VS Code
- See the actual code
- Match what you read to what you see
- Experiment with small changes
Use Browser DevTools
Open DevTools (F12) while exploring:
- See how components nest
- Understand the HTML structure
- Match browser elements to code files
Build Mental Models
Think of the codebase as:
- Folders = Sections of a house
- Pages = Rooms
- Components = Furniture (reusable in any room)
- Layouts = House frame (same in every room)
Success Checkpoint
After completing this section, you should be able to:
- Explain how folders become URLs
- Find the file that generates any page
- Identify which layout a page uses
- Understand component composition
- Know where to create a new page
- Recognize the difference between pages and components
Key Vocabulary
| Term | Definition |
|---|---|
| App Router | Next.js routing system based on folders |
| Route | A URL path (like /about or /contact) |
| Page | A file that creates a route (page.tsx) |
| Layout | Wrapper component with shared UI |
| Component | Reusable piece of UI |
| Children | Content passed into a component |
Common Questions
Q: What's the difference between a page and a component?
A:
- Page = Creates a route (URL). Must be named
page.tsx - Component = Reusable UI piece. Can be named anything
Q: Why are some files in app/ and others in components/?
A:
- app/: Files that create routes (pages, layouts)
- components/: Reusable UI pieces used across multiple pages
Q: Can I create pages outside the app/ folder?
A: No! Only files in app/ can create routes.
Next Steps
Ready to understand the App Router? Let's start: