š Scenario: You are starting a new website project using Astro. Astro helps you build fast websites by organizing your files and components in a clear way.Understanding the basic project structure will help you find and add files easily as your site grows.
šÆ Goal: Build a simple Astro project structure with a main page, a component folder, and a config file.This will help you see how Astro organizes files and how to add new parts to your site.
š What You'll Learn
Create a src/pages folder with a file index.astro containing a simple heading
Create a src/components folder with a file Header.astro containing a header element
Create a astro.config.mjs file with a basic export default configuration
Use correct Astro file extensions and folder names exactly as specified
š” Why This Matters
š Real World
Astro is used to build fast, modern websites by organizing content and components clearly. Understanding the project structure helps developers add features and maintain the site easily.
š¼ Career
Many web development jobs require knowledge of modern frameworks like Astro. Knowing how to set up and navigate the project structure is a key skill for frontend developers.
Progress0 / 4 steps
1
Create the main page file
Create a file called src/pages/index.astro with a simple heading: <h1>Welcome to Astro</h1>
Astro
Hint
Remember, the main page in Astro goes inside src/pages/index.astro.
2
Add a header component
Create a file called src/components/Header.astro with a header element: <header>This is the header</header>
Astro
Hint
Components go inside src/components folder and use the .astro extension.
3
Create the Astro config file
Create a file called astro.config.mjs with this exact content: export default {}
Astro
Hint
The config file is named exactly astro.config.mjs and exports an empty object by default.
4
Complete the project structure overview
Ensure the project has src/pages/index.astro with the heading, src/components/Header.astro with the header, and astro.config.mjs exporting default empty object
Astro
Hint
Check that all files and their contents match exactly as instructed.
Practice
(1/5)
1. In an Astro project, which folder is primarily used to store your source code like components and pages?
easy
A. src/
B. public/
C. assets/
D. dist/
Solution
Step 1: Understand folder roles in Astro
The src/ folder is where you put your source code like components, pages, and styles.
Step 2: Identify the correct folder for code
The public/ folder is for static files like images, not code.
Final Answer:
src/ -> Option A
Quick Check:
Source code folder = src/ [OK]
Hint: Code lives in src/, static files in public/ [OK]
Common Mistakes:
Confusing public/ with src/
Thinking assets/ is default code folder
Assuming dist/ holds source code
2. Which of the following is the correct way to reference a static image stored in the public/ folder inside an Astro component?
easy
A. <img src="../src/images/photo.jpg" />
B. <img src="src/images/photo.jpg" />
C. <img src="/images/photo.jpg" />
D. <img src="./public/images/photo.jpg" />
Solution
Step 1: Understand how public/ files are served
Files in public/ are served from the root URL, so you reference them with a leading slash.
Step 2: Choose the correct path format
Using /images/photo.jpg correctly points to public/images/photo.jpg.
Final Answer:
<img src="/images/photo.jpg" /> -> Option C
Quick Check:
Static files use root-relative paths [OK]
Hint: Static files use root-relative paths starting with '/' [OK]
Common Mistakes:
Using relative paths like 'src/images' for public files
Including 'public/' in the path
Using relative paths that don't work in deployed site
What will be the correct way to display logo.png inside Header.astro?
medium
A. <img src="src/public/logo.png" alt="Logo" />
B. <img src="../public/logo.png" alt="Logo" />
C. <img src="./logo.png" alt="Logo" />
D. <img src="/logo.png" alt="Logo" />
Solution
Step 1: Recall how public/ files are served
Files in public/ are served from the root URL, so you use a root-relative path starting with '/'.
Step 2: Apply correct path in component
Using /logo.png correctly points to the image regardless of component location.
Final Answer:
<img src="/logo.png" alt="Logo" /> -> Option D
Quick Check:
Public files use root-relative paths [OK]
Hint: Always use root-relative paths for public folder files [OK]
Common Mistakes:
Trying to use relative paths to public/ folder
Including 'public' in the path
Using relative paths that break on deployment
4. You see this error when running your Astro project: Cannot find module './public/image.png' What is the likely cause based on Astro's project structure?
medium
A. The src/ folder is missing
B. Trying to import a static file from public/ using a relative import
C. The public/ folder is inside src/
D. The image file is corrupted
Solution
Step 1: Understand how static files are accessed
Static files in public/ are not imported via relative paths in code; they are referenced by URL paths.
Step 2: Identify the error cause
Trying to import a file from public/ using a relative import causes this error.
Final Answer:
Trying to import a static file from public/ using a relative import -> Option B
Quick Check:
Static files are referenced by URL, not imported [OK]
Hint: Never import files from public/; use URL paths [OK]
Common Mistakes:
Importing images or static files as modules
Placing public/ inside src/
Assuming public/ files are bundled like code
5. You want to add a new page to your Astro site at URL /about. Where should you place the new file in the project structure?
hard
A. src/pages/about.astro
B. public/about/index.html
C. src/components/about.astro
D. src/about.astro
Solution
Step 1: Understand Astro's page routing
Files inside src/pages/ map directly to site URLs.
Step 2: Choose correct location for new page
Placing about.astro inside src/pages/ creates the /about route.
Final Answer:
src/pages/about.astro -> Option A
Quick Check:
Pages go in src/pages/ folder [OK]
Hint: Put new pages in src/pages/ for routing [OK]
Common Mistakes:
Placing pages in src/components/
Adding pages directly in src/ without pages folder
Putting pages in public/ folder
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.