Skip to content

codevibesmatter/AstroFlare

Repository files navigation

🚀 AstroFlare

Deploy to Cloudflare Pages Built with Astro Powered by Cloudflare Workers

A modern, full-stack web application template built with Astro and Cloudflare Workers. Features authentication, e-commerce capabilities, content management, and lightning-fast performance at the edge.

✨ Features

🎯 Core Functionality

  • Modern SSR Framework - Built with Astro 5+ for optimal performance
  • Edge Computing - Deployed on Cloudflare Workers for global performance
  • Full-Stack Ready - Complete backend with database and authentication
  • E-commerce Integration - Stripe payments and shopping cart functionality
  • Content Management - Admin panel for managing blog, portfolio, and products
  • SEO Optimized - Built-in sitemap, structured data, and meta tags

🔐 Authentication & Security

  • Better Auth - Modern authentication with session management
  • Protected Routes - Admin dashboard with role-based access
  • Secure Database - Cloudflare D1 with Drizzle ORM
  • Environment Isolation - Separate configs for dev, staging, and production

🛍️ E-commerce Features

  • Stripe Integration - Complete payment processing
  • Shopping Cart - Client-side cart with React Context
  • Product Management - Admin interface for product CRUD
  • Order Tracking - Order management and webhook handling
  • Responsive Design - Mobile-first e-commerce interface

📝 Content Management

  • Blog System - Markdown-based blog with admin interface
  • Portfolio Showcase - Project galleries and case studies
  • Dynamic Content - Easy content creation and management
  • Image Optimization - Automatic image processing and optimization

🎨 Developer Experience

  • TypeScript - Full type safety across the stack
  • React Components - Interactive components with TypeScript
  • Database Migrations - Version-controlled schema changes
  • Hot Module Reload - Fast development with instant updates
  • CSS Modules - Scoped styling for components

📁 Project Structure

AstroFlare/
├── src/
│   ├── components/          # React components
│   │   ├── cart/           # Shopping cart components
│   │   ├── ContactForm.tsx # Contact form component
│   │   └── Gallery.tsx     # Image gallery component
│   ├── content/            # Content collections
│   │   ├── blog/          # Blog posts (Markdown)
│   │   ├── portfolio/     # Portfolio items
│   │   ├── products/      # Product catalog
│   │   └── config.ts      # Content configuration
│   ├── contexts/          # React contexts
│   │   └── CartContext.tsx # Shopping cart state
│   ├── db/               # Database configuration
│   │   ├── schema.ts     # Drizzle schema definitions
│   │   └── index.ts      # Database connection
│   ├── layouts/          # Astro layouts
│   │   ├── BaseLayout.astro
│   │   ├── AuthLayout.astro
│   │   └── AdminLayout.astro
│   ├── lib/              # Utility libraries
│   │   ├── auth.ts       # Authentication configuration
│   │   └── auth-utils.ts # Auth helper functions
│   ├── pages/            # Page routes
│   │   ├── api/          # API endpoints
│   │   ├── admin/        # Admin panel pages
│   │   ├── blog/         # Blog pages
│   │   ├── portfolio/    # Portfolio pages
│   │   ├── products/     # Product pages
│   │   └── index.astro   # Homepage
│   ├── types/            # TypeScript definitions
│   └── utils/            # Utility functions
├── public/               # Static assets
├── drizzle/             # Database migrations
├── scripts/             # Build and setup scripts
├── astro.config.mjs     # Astro configuration
├── drizzle.config.ts    # Database configuration
├── wrangler.toml        # Cloudflare Workers config
└── package.json

🚀 Quick Start

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm
  • Cloudflare account (for deployment)

Local Development

# Clone the repository
git clone https://github.com/yourusername/AstroFlare.git
cd AstroFlare

# Install dependencies
pnpm install

# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your configuration

# Set up authentication
pnpm run auth:setup

# Start development server
pnpm run dev

Visit http://localhost:4321 to see your site!

Environment Setup

Create a .env.local file with the following variables:

# Database
DATABASE_URL="path/to/local.db"

# Authentication
BETTER_AUTH_SECRET="your-secret-key-here"
BETTER_AUTH_URL="http://localhost:4321"

# Stripe (for e-commerce)
STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_SECRET_KEY="sk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."

# Email (Resend)
RESEND_API_KEY="re_..."

🛠️ Development

Available Scripts

# Development
pnpm run dev              # Start dev server
pnpm run build           # Build for production
pnpm run preview         # Preview production build

# Database
pnpm run db:generate     # Generate migrations
pnpm run db:push         # Push schema to database
pnpm run db:studio       # Open database studio
pnpm run db:migrate      # Run migrations in production

# Authentication
pnpm run auth:setup      # Configure authentication

Database Management

This template uses Drizzle ORM with Cloudflare D1 for the database:

# Create a new migration
pnpm run db:generate

# Apply migrations locally
pnpm run db:push

# View your data in Drizzle Studio
pnpm run db:studio

Adding Content

Blog Posts

Create new blog posts in src/content/blog/:

---
title: "Your Blog Post Title"
description: "Post description"
publishDate: 2024-01-01
author: "Author Name"
image: "/images/blog/post-image.jpg"
tags: ["tag1", "tag2"]
---

Your blog content here...

Products

Add new products in src/content/products/:

---
title: "Product Name"
description: "Product description"
price: 99.99
image: "/images/products/product-image.jpg"
category: "Category"
featured: true
---

Product details and specifications...

Admin Panel

Access the admin panel at /admin/dashboard (requires authentication):

  • Content Management - Create and edit blog posts, portfolio items, and products
  • Order Management - View and process customer orders
  • User Management - Manage user accounts and permissions

🚀 Deployment

Cloudflare Pages

  1. Connect your repository to Cloudflare Pages
  2. Configure build settings:
    • Build command: pnpm run build
    • Build output directory: dist
  3. Set environment variables in Cloudflare dashboard
  4. Create D1 database and run migrations:
    wrangler d1 create astro-auth
    pnpm run db:migrate

Environment Variables

Set these in your Cloudflare Pages dashboard:

DATABASE_URL=your-d1-database-url
BETTER_AUTH_SECRET=your-production-secret
BETTER_AUTH_URL=https://yourdomain.com
STRIPE_PUBLISHABLE_KEY=pk_live_...
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
RESEND_API_KEY=re_...

Custom Domain

Update astro.config.mjs with your domain:

const getSiteUrl = () => {
  if (process.env.CF_PAGES_BRANCH === 'main') {
    return 'https://yourdomain.com'; // Your production domain
  }
  // ... other configurations
};

🧪 Testing

# Run type checking
pnpm run astro check

# Build and test locally
pnpm run build
pnpm run preview

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

📚 Documentation

🛡️ Security

  • All authentication is handled securely with Better Auth
  • Environment variables are properly isolated
  • Database queries use parameterized statements
  • CORS and security headers are configured
  • Regular dependency updates via automated tools

📊 Performance

  • Lighthouse Score: 95+ across all metrics
  • Core Web Vitals: Optimized for excellent user experience
  • Edge Computing: Global CDN with <50ms response times
  • Image Optimization: Automatic image processing and lazy loading
  • Bundle Analysis: Tree-shaken and optimized builds

🔧 Customization

Styling

  • Modify global styles in src/styles/
  • Component-specific styles use CSS Modules
  • Tailwind CSS can be easily integrated

Components

  • All React components are in src/components/
  • Astro components for layouts and static content
  • TypeScript interfaces in src/types/

Database Schema

  • Modify src/db/schema.ts for database changes
  • Generate and apply migrations with Drizzle

📄 License

MIT License - see LICENSE for details.

🙏 Acknowledgments

  • Astro - The web framework for content-driven websites
  • Cloudflare - Edge computing and global infrastructure
  • Better Auth - Modern authentication for the web
  • Drizzle ORM - TypeScript ORM for SQL databases
  • Stripe - Payment processing platform

Built with ❤️ using Astro and Cloudflare Workers

Report Bug · Request Feature · Contribute

About

A modern, full-stack web application template built with Astro and Cloudflare Workers. Features authentication, e-commerce capabilities, content management, and lightning-fast performance at the edge.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors