Skip to content
AtMyAppDocs
Open dashboard
Get started

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.

  1. Sign in at app.atmyapp.com and create a project for this website.

  2. 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.

  3. 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.

  1. Create a minimal Astro project and install the AtMyApp packages:

    Terminal window
    npm create astro@latest my-site -- --template minimal --yes
    cd my-site
    npm install @atmyapp/astro @atmyapp/core @atmyapp/structure
    npm install --save-dev @atmyapp/cli
  2. Add the website keys to a .env file in the project root:

    .env
    ATMYAPP_API_URL=https://edge.atmyapp.com/v0/projects/<project-id>
    ATMYAPP_API_KEY=<api-key>
  3. 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()],
    });

    site is used for canonical links and form redirects. Use the real domain, even before it’s live.

  4. 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.

Create atmyapp.schema.ts in the project root. It lists everything your client can edit:

atmyapp.schema.ts
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:

  • home is a document: one set of fields. services is a collection: many entries with the same fields.
  • description text is shown to your client and to the AI assistant. Say where the text appears.
  • max lengths 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:

Terminal window
npx atmyapp migrate --dry-run # compile and check it locally
npx atmyapp migrate # upload it to the project

migrate 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.

Your website reads published content, so publish something before you render it.

  1. In the dashboard, open Content → Home. Fill in the headline and introduction, and optionally upload an image.

  2. Open Content → Services and add two or three entries.

  3. Open Settings → Website settings. Enter the website name and a default description. These feed the page titles and social tags in the next step.

  4. Click Review & publish and publish everything.

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.

src/layouts/BaseLayout.astro
---
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.

Replace src/pages/index.astro:

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: try home. 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.

Create src/pages/services/[slug].astro:

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.

Create src/pages/contact.astro:

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:

Terminal window
npx atmyapp submissions tail contact

Messages sent from localhost are stored as local development, so they never reach your client’s inbox or notifications. More in Astro forms.

Terminal window
npm run build

The 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).

  1. 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 website
    git push atmyapp main

    Using GitHub instead? Choose Connect GitHub and pick the repository. See Store code in AtMyApp.

  2. Use npm run build as the build command and dist as the output directory.

  3. Start the first build. AtMyApp provides ATMYAPP_API_URL and ATMYAPP_API_KEY to the build, so you don’t add them yourself.

  4. 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.

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.