Components
In the larger context of the project structure, src/layouts/ acts as the master shell and templating wrapper for the Astrofy application.
Instead of repeating foundational HTML markup across every individual page, src/layouts/ houses reusable master templates—primarily BaseLayout.astro—that wrap page content and orchestrate global elements.
-
The Master Wrapper (
BaseLayout.astro) -
Eliminating Boilerplate: Every website requires standard HTML structural tags (
<html>,<head>,<body>, and meta tags).BaseLayout.astrodefines these global tags in a single place so individual pages do not need to rewrite them. - The
Injection Mechanism: Inside BaseLayout.astro, Astro uses a specialplaceholder tag. When a page route in src/pages/(such asindex.astroorcv.astro) wraps its content in<BaseLayout>, Astro shoves that page's specific HTML directly into the<slot />placeholder at compile time to assemble a complete page.
- Orchestration of Global UI Components & View Transitions
src/layouts/BaseLayout.astro acts as the structural glue that pulls together shared components from across the project:
- Persistent UI Elements: It imports and positions global components from
src/components/, such as the persistentSideBar.astro,Header.astro, andFooter.astro. - SPA-like Transitions: It includes Astro's
<ViewTransitions />element to enable smooth, single-page-application style page routing without full browser refreshes.
- Component Communication & Prop Delegation
src/layouts/ serves as the crucial middleman in the component prop chain:
- A page in
src/pages/index.astrodefines which navigation item is active by passing a property (prop) to the layout:<BaseLayout sideBarActiveItemID="home">. BaseLayout.astroreceives this prop and passes it down to the sidebar component:<SideBar sideBarActiveItemID={sideBarActiveItemID} />.- The message is passed down to
SideBarMenu.astro, where client-side JavaScript highlights the matching tab ID (id="home").
- The Global Aesthetic Anchor (DaisyUI Theming)
BaseLayout.astro serves as the centralized anchor for the site's entire color palette and visual theme:
- The data-theme Attribute: DaisyUI attaches its theme engine directly to the root
<html>tag insideBaseLayout.astro(e.g.,data-theme="lofi"). - Site-Wide Palette Swapping: Updating this single string in
BaseLayout.astro(such as changing"lofi"to"dracula","dark", or"business") instantly updates CSS variables for buttons, cards, and text colors across all pages rendered within the layout.
- Role in the Overall Project Directory Hierarchy
src/
├── pages/ <-- Content routes (Passes active state props)
├── layouts/ <-- BaseLayout.astro (Receives props, injects <slot />, anchors theme)
├── components/ <-- Shared UI blocks (Header, Footer, SideBar rendered inside layout)
└── content/ <-- Raw Markdown data (Injected through pages into layout slots)
By separating src/layouts/ from src/pages/ and src/components/, the architecture maintains a clean separation of concerns: pages control routing and data fetching, components define small UI blocks, and layouts provide the outer structural framework and theme state.