Overview
The Astro Portfolio v3 project uses a well-organized component architecture that promotes reusability and maintainability. All components are built using Astro’s component syntax, which combines HTML, CSS, and JavaScript in a single file.Components are located in
~/workspace/source/src/components/ and are organized by category: home/, navs/, shared/, and ui/.Component Categories
- Home Components
- UI Components
Home Section Components
These components make up the various sections of the homepage and are located insrc/components/home/.About Component
Renders the about section with content from the content collection.src/components/home/About.astro:1Projects Component
Displays featured projects from the projects content collection.Location:src/components/home/Projects.astro:1Work Experience Component
Shows work history in a timeline format.Location:src/components/home/WorkExperience.astro:1Hero Components
HeroText.astro- Main hero text and CTAHeroImage.astro- Hero section image/illustration
Blog Component
Lists recent blog posts on the homepage.Location:src/components/home/Blogs.astro:1Sidebar Components
Author Sidebar
Displays author information in article pages. Location:src/components/AuthorSidebar.astro:1
Sponsors Sidebar
Shows sponsor information and advertisements. Location:src/components/SponsorsSidebar.astro:1
Side Navigation
Navigation sidebar for the about page. Location:src/components/SideNav.astro:1
Component Patterns
Content Integration
Components frequently integrate with Astro’s Content Collections:Component Composition
Components are designed to be composable:Client-Side Interactivity
Components with client-side behavior use inline<script> tags:
The
astro:after-swap event ensures components work correctly with Astro’s view transitions.Styling Components
Components use Tailwind CSS utility classes for styling:dark:prefix for dark mode stylesretro:prefix for retro theme styles- CSS variables for dynamic theming
Using Components
Import and Use
Index Files
Component groups export their components viaindex.ts files:
Creating New Components
To create a new component:- Choose the appropriate directory based on the component’s purpose
- Create an
.astrofile with a descriptive name - Add to the index file if it’s part of a group
- Follow naming conventions: PascalCase for component files
Best Practices
Component Best Practices
Component Best Practices
- Keep components focused - Each component should have a single responsibility
- Use TypeScript interfaces - Define prop types for better type safety
- Leverage content collections - Fetch content from collections rather than hardcoding
- Make components responsive - Use Tailwind’s responsive prefixes
- Handle page transitions - Use
astro:after-swapfor client-side scripts - Export from index files - Make component groups easier to import
- Use semantic HTML - Ensure accessibility with proper HTML structure
Related Pages
Theming
Learn how the ThemeSwitcher component works
i18n
Understand the LanguageSwitcher implementation
Content Collections
See how components integrate with content
Project Structure
Understand the overall project organization