Project Structure
The boilerplate follows Astro’s standard directory structure:Directory Details
src/pages/ - File-based Routing
src/pages/ - File-based Routing
Astro uses file-based routing. Each
.astro, .md, or .ts file in src/pages/ becomes a route:src/pages/index.astro→/src/pages/ssr.astro→/ssrsrc/pages/isr.astro→/isrsrc/pages/api/revalidate.ts→/api/revalidate
src/components/ - Reusable Components
src/components/ - Reusable Components
Store reusable Astro components here:
Card.astro- Card component for content displayHeader.astro- Site header with navigationFooter.astro- Site footerSEO.astro- SEO meta tags component
@/ path alias:src/layouts/ - Page Templates
src/layouts/ - Page Templates
Layout components wrap your pages with common structure.Main Layout (src/layouts/Layout.astro:1):
src/middleware.ts - Request Middleware
src/middleware.ts - Request Middleware
Middleware runs on every request when
edgeMiddleware: true is configured.Example middleware (src/middleware.ts:1):Middleware runs on Vercel’s Edge Network when
edgeMiddleware: true is set in the adapter config.public/ - Static Assets
public/ - Static Assets
Files in
public/ are served as-is without processing:favicon.svg- Site faviconpico-mark-dark.svg- Dark mode logopico-mark-light.svg- Light mode logoopen-graph.jpg- Social media preview imagepreview.png- Project preview imagemodal.js- Client-side JavaScript
TypeScript Configuration
The project uses TypeScript with path aliases for clean imports:tsconfig.json
Path Aliases
Use@/ to import from the src/ directory:
Package Scripts
Thepackage.json includes these development scripts:
package.json
Script Descriptions
Start the development server at
http://localhost:4321Type-check the project and build for production
This runs
astro check first to catch TypeScript errors before building.Preview the production build locally
Run TypeScript type checking without building
Lint and auto-fix code with ESLint
Format code with Prettier
Run the development server with Vercel’s local environment
Requires the Vercel CLI:
npm i -g vercelLink your local project to a Vercel project
Site Configuration
Store site-wide configuration insrc/data/config.ts:
src/data/config.ts
Custom Domain Setup
In Vercel Dashboard
- Go to your project settings on Vercel
- Navigate to Domains
- Add your custom domain
- Follow Vercel’s instructions to configure DNS
Update Configuration
Update thesite URL in astro.config.mjs:
astro.config.mjs
src/data/config.ts:
src/data/config.ts
Development Workflow
1. Start Development Server
http://localhost:4321
2. Make Changes
Edit files insrc/ - the dev server will hot-reload automatically.
3. Type Checking
4. Lint and Format
5. Build for Production
6. Preview Production Build
7. Deploy to Vercel
Connect your GitHub repository to Vercel for automatic deployments on every push to your main branch.
Environment Variables
Create a.env file in the project root:
.env
Using Environment Variables
Vercel Environment Variables
Add environment variables in your Vercel project settings:- Go to Settings → Environment Variables
- Add your variables for each environment (Production, Preview, Development)
- Redeploy for changes to take effect
Next Steps
Vercel Adapter
Configure the Vercel adapter options
Deployment
Deploy your project to Vercel