Bird
Raised Fist0
NextJSframework~20 mins

Project structure overview in NextJS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Next.js Project Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the purpose of the app directory in Next.js 14?
In Next.js 14, what is the main role of the app directory in a project?
AIt holds configuration files like <code>next.config.js</code> and environment variables.
BIt contains server components and routes that define the app's UI and navigation.
CIt stores static assets like images and fonts for the project.
DIt is used only for API routes and backend logic.
Attempts:
2 left
💡 Hint
Think about where you define pages and layouts in Next.js 14.
❓ component_behavior
intermediate
2:00remaining
What happens if you place a page file outside the app directory?
In a Next.js 14 project, what will happen if you create a page file like page.tsx outside the app directory?
AThe page will not be recognized and will not be part of the routing system.
BThe page will work normally and be accessible via URL.
CNext.js will throw a build error preventing the app from running.
DThe page will be treated as an API route.
Attempts:
2 left
💡 Hint
Where does Next.js expect page files in the new app router?
📝 Syntax
advanced
2:00remaining
Identify the correct file to define a layout for all pages in Next.js 14
Which file should you create inside the app directory to define a layout that wraps all pages in your Next.js 14 app?
A<code>page.tsx</code>
B<code>app.tsx</code>
C<code>layout.tsx</code>
D<code>root.tsx</code>
Attempts:
2 left
💡 Hint
Layouts wrap pages and share UI like headers or footers.
🔧 Debug
advanced
2:00remaining
Why does this Next.js 14 project fail to load the homepage?
Given this project structure: - app/ - layout.tsx - home.tsx Why does the homepage not load at the root URL?
ABecause the homepage file must be named <code>page.tsx</code>, not <code>home.tsx</code>.
BBecause <code>layout.tsx</code> is missing a default export.
CBecause the <code>app</code> directory must be named <code>pages</code>.
DBecause the <code>home.tsx</code> file must be inside a folder named <code>home</code>.
Attempts:
2 left
💡 Hint
Next.js uses specific file names for routing.
❓ lifecycle
expert
3:00remaining
How does Next.js 14 handle server and client components in the app directory?
In Next.js 14, how does the framework decide which components in the app directory run on the server versus the client?
ANext.js runs all components on both server and client automatically without distinction.
BAll components run on the client unless wrapped in a special <code>ServerComponent</code> tag.
CComponents run on the server or client based on their file extension: <code>.server.tsx</code> or <code>.client.tsx</code>.
DBy default, components are server components unless marked with <code>'use client'</code> at the top to run on the client.
Attempts:
2 left
💡 Hint
Look for a special directive string at the top of files.

Practice

(1/5)
1. What is the main purpose of the app/ folder in a Next.js project?
easy
A. To organize pages, layouts, and API routes
B. To store static files like images and fonts
C. To hold configuration files like next.config.js
D. To keep test files and mocks

Solution

  1. Step 1: Understand the role of app/ folder

    The app/ folder is designed to organize the main parts of the app such as pages, layouts, and API routes.
  2. Step 2: Compare with other folders

    The public/ folder holds static files, and config files are outside app/. So, app/ is for app structure.
  3. Final Answer:

    To organize pages, layouts, and API routes -> Option A
  4. Quick Check:

    app/ folder = organize pages/layouts/API [OK]
Hint: Remember: app/ is your app's main structure folder [OK]
Common Mistakes:
  • Confusing app/ with public/
  • Thinking config files go inside app/
  • Assuming app/ holds only pages, ignoring layouts and APIs
2. Which folder should you place an image file in a Next.js project to serve it statically?
easy
A. app/
B. api/
C. components/
D. public/

Solution

  1. Step 1: Identify static file storage

    Static files like images should be placed in the public/ folder so they can be served directly.
  2. Step 2: Exclude other folders

    app/ is for pages/layouts, components/ is for React components, and api/ is for backend routes, so none are for static files.
  3. Final Answer:

    public/ -> Option D
  4. Quick Check:

    Static files = public/ folder [OK]
Hint: Static files go in public/ folder, not app/ [OK]
Common Mistakes:
  • Putting images inside app/ folder
  • Confusing components/ with static file storage
  • Trying to serve images from api/ folder
3. Given this Next.js project structure:
app/
  layout.js
  page.js
public/
  logo.png

Which statement is true about accessing logo.png in the browser?
medium
A. You can access it at /logo.png
B. You must import it in page.js to use it
C. It is not accessible because it's inside public/
D. You can access it at /app/logo.png

Solution

  1. Step 1: Understand public/ folder behavior

    Files in public/ are served at the root URL path, so logo.png is accessible at /logo.png.
  2. Step 2: Check other options

    Importing is optional for static files; app/ folder files are not served as static assets, so /app/logo.png is invalid.
  3. Final Answer:

    You can access it at /logo.png -> Option A
  4. Quick Check:

    public/ files = root URL access [OK]
Hint: Static files in public/ map to root URL path [OK]
Common Mistakes:
  • Thinking you must import static files to access them
  • Trying to access static files via /app/ path
  • Assuming public/ files are not accessible
4. You see this error in your Next.js app: "Module not found: Can't resolve './logo.png'". Your project has logo.png inside public/. What is the likely cause?
medium
A. You placed logo.png inside app/ instead of public/
B. You tried to import logo.png from public/ using a relative path
C. The logo.png file is missing from public/
D. Next.js does not support PNG images

Solution

  1. Step 1: Understand how to use files in public/

    Files in public/ are accessed via URL paths, not imported with relative paths in code.
  2. Step 2: Identify the error cause

    Trying to import logo.png with a relative path causes "Module not found" error because public/ files are not part of the module system.
  3. Final Answer:

    You tried to import logo.png from public/ using a relative path -> Option B
  4. Quick Check:

    Importing public/ files = error [OK]
Hint: Don't import public/ files; use URL paths instead [OK]
Common Mistakes:
  • Importing static files from public/ folder
  • Assuming public/ files are part of module imports
  • Thinking Next.js can't serve PNG images
5. You want to create a new page with a custom layout in your Next.js app. Where should you place the layout and page files to follow the recommended project structure?
hard
A. Place both files inside components/ folder
B. Put layout.js in public/ and page.js in app/
C. Place both layout.js and page.js inside a new folder under app/
D. Put page.js in app/ and layout.js in api/

Solution

  1. Step 1: Recall Next.js app folder structure

    In Next.js, pages and their layouts are organized inside folders under app/ to group related files.
  2. Step 2: Exclude incorrect placements

    public/ is for static files, components/ is for reusable UI parts, and api/ is for backend routes, so these are not correct for layouts/pages.
  3. Final Answer:

    Place both layout.js and page.js inside a new folder under app/ -> Option C
  4. Quick Check:

    Layouts and pages live together under app/ [OK]
Hint: Keep layouts and pages together inside app/ folders [OK]
Common Mistakes:
  • Putting layouts in public/ or api/
  • Separating layout and page files into unrelated folders
  • Confusing components/ with page structure
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard