Tutorial: build an Astro website
From an empty folder to a deployed website your client can edit. You'll build a homepage, service pages, SEO tags and a contact form.
Open with AI
In this tutorial you build a small business website with Astro and AtMyApp. By the end you will have:
- a homepage whose headline, introduction and image your client edits,
- a services list with one generated page per service,
- page titles, descriptions and social images managed from the dashboard,
- a contact form that needs no backend,
- a deployment that rebuilds when your client publishes.
It takes about 30 minutes. You need Node.js 22.14 or newer and an AtMyApp account. AtMyApp stores the code for you, so a GitHub account is optional.
npm create atmyapp@latest scaffolds an Astro + Tailwind site that is already wired to AtMyApp. This tutorial builds the same pieces one at a time, so you understand each of them.
1. Create a project and copy its keys
Section titled “1. Create a project and copy its keys”-
Sign in at app.atmyapp.com and create a project for this website.
-
Open Settings → API keys and create a key. Copy two values:
- the Project API URL:
https://edge.atmyapp.com/v0/projects/<project-id> - the API key
Both are public. They let a website read published content and send forms.
- the Project API URL:
-
Open Settings → CLI keys, create a key, and copy the
atmyapp use …command shown there. A CLI key can change your schema, so keep it private.
See Keys and URLs if you’re unsure which value goes where.
2. Create the Astro site
Section titled “2. Create the Astro site”-
Create a minimal Astro project and install the AtMyApp packages:
Terminal window npm create astro@latest my-site -- --template minimal --yescd my-sitenpm install @atmyapp/astro @atmyapp/core @atmyapp/structurenpm install --save-dev @atmyapp/cliTerminal window pnpm create astro@latest my-site --template minimal --yescd my-sitepnpm add @atmyapp/astro @atmyapp/core @atmyapp/structurepnpm add --save-dev @atmyapp/cliTerminal window yarn create astro my-site --template minimal --yescd my-siteyarn add @atmyapp/astro @atmyapp/core @atmyapp/structureyarn add --dev @atmyapp/cli -
Add the website keys to a
.envfile in the project root:.env ATMYAPP_API_URL=https://edge.atmyapp.com/v0/projects/<project-id>ATMYAPP_API_KEY=<api-key> -
Register the integration and set your production address in
astro.config.mjs:astro.config.mjs import { defineConfig } from "astro/config";import atmyapp from "@atmyapp/astro";export default defineConfig({site: "https://www.example.com",integrations: [atmyapp()],});siteis used for canonical links and form redirects. Use the real domain, even before it’s live. -
Connect the CLI by pasting the command you copied from Settings → CLI keys:
Terminal window npx atmyapp use --url https://api.atmyapp.com/v0/projects/<project-id> --token <cli-key>The CLI checks the key, saves it to
.ama/session.json, and adds that file to.gitignore.
3. Describe the editable content
Section titled “3. Describe the editable content”Create atmyapp.schema.ts in the project root. It lists everything your client can edit:
import { defineCollection, defineDocument, defineSchema, defineSubmission, s,} from "@atmyapp/structure";
export default defineSchema({ definitions: { home: defineDocument({ description: "The homepage.", fields: { headline: s.string({ max: 80, description: "Large heading at the top of the homepage.", }), intro: s.longText({ description: "One or two sentences under the headline." }), hero: s.image({ optional: true, description: "Wide photo beside the headline." }), }, }), services: defineCollection({ description: "Services we offer. Each one gets its own page.", fields: { title: s.string({ max: 60 }), slug: s.slug({ source: "title" }), summary: s.string({ max: 160, description: "Shown on the homepage card." }), details: s.longText({ description: "Shown on the service's own page." }), }, }), }, submissions: { contact: defineSubmission({ description: "Contact form on /contact.", fields: { name: s.string({ max: 100 }), email: s.email(), message: s.longText({ min: 10, max: 5000 }), }, }), },});A few things to notice:
homeis a document: one set of fields.servicesis a collection: many entries with the same fields.descriptiontext is shown to your client and to the AI assistant. Say where the text appears.maxlengths protect your layout. AtMyApp refuses content that breaks them.s.slug()generates a URL-safe identifier from the title, and keeps it stable afterwards.
Now upload the schema:
npx atmyapp migrate --dry-run # compile and check it locallynpx atmyapp migrate # upload it to the projectmigrate shows a plan of what changes in the project and asks before it touches existing content. Your project is empty, so it applies straight away. The contact form now exists too.
4. Add the first content
Section titled “4. Add the first content”Your website reads published content, so publish something before you render it.
-
In the dashboard, open Content → Home. Fill in the headline and introduction, and optionally upload an image.
-
Open Content → Services and add two or three entries.
-
Open Settings → Website settings. Enter the website name and a default description. These feed the page titles and social tags in the next step.
-
Click Review & publish and publish everything.
5. Add a layout with managed SEO tags
Section titled “5. Add a layout with managed SEO tags”Create a layout that every page uses. AtMyAppHead renders the title, description, canonical link, social tags and icons from Website settings, with per-page overrides.
---import AtMyAppHead from "@atmyapp/astro/components";
interface Props { title?: string; description?: string; image?: string;}const { title, description, image } = Astro.props;---
<html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <AtMyAppHead title={title} description={description} image={image} /> </head> <body> <header><a href="/">Home</a> · <a href="/contact/">Contact</a></header> <main><slot /></main> </body></html>Leave <title> and description tags out of your layout: AtMyAppHead owns them. If the website name is “Altana”, title="Services" renders Services · Altana. More in Metadata and SEO.
6. Render the homepage
Section titled “6. Render the homepage”Replace src/pages/index.astro:
---import { getAtMyApp } from "@atmyapp/astro/server";import schema from "../../atmyapp.schema";import BaseLayout from "../layouts/BaseLayout.astro";
const ama = getAtMyApp(Astro, { schema });const home = await ama.storage.getValue("home");const services = await ama.collections.list("services");---
<BaseLayout> <h1>{home.headline}</h1> <p>{home.intro}</p> {home.hero && <img src={home.hero.url} alt="" width="1200" />}
<h2>Services</h2> <ul> { services.map((service) => ( <li> <a href={`/services/${service.slug}/`}>{service.title}</a> <p>{service.summary}</p> </li> )) } </ul></BaseLayout>Start the dev server with npm run dev and open the page. You should see your published headline and services.
getAtMyApp(Astro, { schema })returns a client configured from your.env. Passing the schema makes every read typed: tryhome.in your editor.getValue("home")returns the document’s fields.collections.list("services")returns an array of entries, newest first.- Image fields arrive as an object with a
url.
Check that you published it, and that ATMYAPP_API_URL is the edge URL with the /v0/projects/<id> path. Errors stop the page by default, so you see the reason instead of an empty page. See Troubleshooting.
7. Generate a page per service
Section titled “7. Generate a page per service”Create src/pages/services/[slug].astro:
---import { getAtMyApp } from "@atmyapp/astro/server";import { CollectionsFilter as F } from "@atmyapp/core";import schema from "../../../atmyapp.schema";import BaseLayout from "../../layouts/BaseLayout.astro";
// Runs during static builds: one page per published service.export async function getStaticPaths() { const services = await getAtMyApp({ schema }).collections.list("services"); return services.map((service) => ({ params: { slug: service.slug } }));}
const ama = getAtMyApp(Astro, { schema });const service = await ama.collections.first("services", { filter: F.eq("slug", Astro.params.slug!),});if (!service) return new Response("Not found", { status: 404 });---
<BaseLayout title={service.title} description={service.summary}> <h1>{service.title}</h1> <p>{service.details}</p></BaseLayout>Why both parts? Production builds are static, so Astro needs getStaticPaths() to know which pages to generate. During development and in previews the site renders per request, so the page looks the service up by its slug. The same file works in both modes. Modes and previews explains this in detail.
getStaticPaths() has no Astro object, so it calls getAtMyApp({ schema }) without one. That form works only in static builds. In astro dev you’ll see the warning getStaticPaths() ignored in dynamic page; that’s expected.
8. Add the contact form
Section titled “8. Add the contact form”Create src/pages/contact.astro:
---import AtMyAppForm from "@atmyapp/astro/form";import BaseLayout from "../layouts/BaseLayout.astro";---
<BaseLayout title="Contact"> <h1>Get in touch</h1> <AtMyAppForm submission="contact" enhance> <label>Name <input name="name" required /></label> <small data-atmyapp-error="name"></small>
<label>Email <input name="email" type="email" required /></label> <small data-atmyapp-error="email"></small>
<label>Message <textarea name="message" required minlength="10"></textarea></label> <small data-atmyapp-error="message"></small>
<button type="submit">Send</button> </AtMyAppForm></BaseLayout>The form posts straight to AtMyApp, so it works on a static site. The input names match the fields in your schema. With enhance, the form sends without reloading, shows errors next to the fields, and shows a thank-you message. Without JavaScript it still works as a normal HTML form. A hidden spam trap is added for you.
To send visitors to your own thank-you page instead, add returnTo="/thank-you/". It resolves against site, so it points at your production domain.
Send yourself a message. To watch it arrive, run this in a second terminal:
npx atmyapp submissions tail contactMessages sent from localhost are stored as local development, so they never reach your client’s inbox or notifications. More in Astro forms.
9. Build it
Section titled “9. Build it”npm run buildThe build fetches all content and writes plain HTML to dist/. A failed read fails the build, so a broken connection never ships an empty page. Your project now looks like this:
Directory.ama/
- session.json (private, ignored by git)
Directorysrc/
Directorylayouts/
- BaseLayout.astro
Directorypages/
- index.astro
- contact.astro
Directoryservices/
- [slug].astro
- .env
- astro.config.mjs
- atmyapp.schema.ts
- package.json
Commit everything except .env and .ama/session.json. You push it to AtMyApp in the next step (or to a GitHub repository, if you prefer).
10. Deploy with AtMyApp hosting
Section titled “10. Deploy with AtMyApp hosting”-
In the project’s Setup, keep Store the code in AtMyApp and choose Empty repository. Then push your code:
Terminal window npx atmyapp code setup-git websitegit push atmyapp mainUsing GitHub instead? Choose Connect GitHub and pick the repository. See Store code in AtMyApp.
-
Use
npm run buildas the build command anddistas the output directory. -
Start the first build. AtMyApp provides
ATMYAPP_API_URLandATMYAPP_API_KEYto the build, so you don’t add them yourself. -
When the build is live, add your domain in the same place.
New websites rebuild automatically when your client publishes, so you’re done. Prefer another host? See Deploy.
11. Try the client’s side
Section titled “11. Try the client’s side”Edit the homepage headline in the dashboard, but don’t publish yet. Click Preview: AtMyApp opens your site on a preview server with the draft applied. Publish, and a new build goes live a minute or two later.
That loop (edit, preview, publish) is what your client will do every day. Before you hand the project over, read Hand over to your client.
Where to go next
Section titled “Where to go next”- Design your schema: nested content, references between entries, ordering.
- Collections: filters, pagination and sorting.
- Drafts and previews: how previews reach your pages.
- Change a live schema: rename fields without losing content.
@atmyapp/astroreference: every component and option.
