withastro / storefront

Astro for ecommerce πŸ’°
https://shop.astro.build
MIT License
624 stars 74 forks source link

Astro Storefront (Alpha)

Your storefront deserves best-in-class performance without the learning curve.

Astro has spent years building the right foundation for content-driven websites, and ecommerce is naturally the next frontier. This repository showcases the top features that our community uses to ship with confidence:

Astro Storefront powers shop.astro.build today, and our opinionated choice of services and libraries reflects that. We expect this repository to be the start of a new platform to meet your storefront's needs.

Project structure

The primary project directories are outlined below:

β”œβ”€β”€ public/
β”œβ”€β”€ src/
β”‚   └── actions/
β”‚   └── components/
β”‚       └── ui/
β”‚   └── features/
β”‚   └── pages/
└── package.json

actions/ contains backend functions called from the client to manage a customer's cart. These are called client-side and backed by optimistic updates.

components/ui/ contains reusable components for common UI elements, including Buttons, Drawers, and Inputs. These are tested to meet modern accessibility guidelines.

features/ contains domain-specific components and state management, organized by common ecommerce concepts:

pages/ contains file-based routes for your storefront.

Services

This repository connects to related services to power payments, emails, and map embeds. Visit the astro.config.ts file for an overview of all environment variables and access permissions required for each.

You are welcome to change or entirely remove any of these services to meet your needs.

Storefront API

shop.astro.build uses a custom API to manage products and fulfill orders.

This client isn't available for public use today, though we've provided a "mock" version of all API functions under src/lib/client.mock.ts. We recommend using this file as a way to standardize requests for your ecommerce provider of choice.

To use the mock API, update the tsconfig.json entry for the storefront:client module:

{
    "compilerOptions": {
        "paths": {
            "~/*": ["./src/*"],
-           "storefront:client": ["./src/lib/client.ts"]
+           "storefront:client": ["./src/lib/client.mock.ts"]
        },
    }
}

Stripe

The Stripe API is used to accept payment and manage the checkout flow.

Environment variables

Loops

Loops.so is an email sending service used to send a confirmation email to the customer after checking out successfully.

Environment variables

Google Maps

The Google Maps Platform is used to embed a map with the customer's shipping address on the order details page.

Environment variables

Commands

This project uses pnpm to manage dependencies. Be sure to install this tool, then run startup commands from your terminal:

Command Action
pnpm install Installs dependencies
pnpm dev Starts local dev server
pnpm build Build your production site to ./dist/
pnpm astro ... Run CLI commands like astro add, astro check
pnpm astro --help Get help using the Astro CLI