← Back to Blog

How to Add AI-Moderated Comments to Your Astro Site

TL;DR: Install @respectify/astro, point it at your database through Drizzle, drop <CommentSection postSlug="..." /> into your layout, and every comment is screened by Respectify before it appears. Setup takes about 20 minutes.

Updated October 2026 for @respectify/astro 1.0. Earlier versions stored comments through Astro DB, which Astro removed in version 7. Version 1.0 stores them in your own Postgres or SQLite/Turso database through Drizzle, and works with Astro 5, 6 and 7. Upgrading from 0.x? The migration guide shows how to keep your existing Turso comments without moving any data.

Astro is a great framework for blogs and content sites — and comment sections are one of the things it doesn’t give you out of the box. The usual options are embedding a third-party widget (which means someone else owns your readers’ data) or building your own (which means a lot of work).

@respectify/astro is a third option: a self-contained Astro integration that stores comments in your own database, screens them with Respectify’s AI before they post, and renders a clean comment UI with a single component. You own the data, Respectify handles the moderation.

This is the site you’re reading right now — the Respectify blog uses this exact integration, with its comments in Turso.

What you’ll need

  • An Astro 5, 6 or 7 project with output: 'server' (or hybrid mode) and a server adapter
  • A database you reach through Drizzle ORM: SQLite or libSQL (such as Turso), or Postgres
  • A Respectify account and API key

If you’re starting fresh, the Astro docs cover setting up server rendering. This guide uses Turso; the Postgres steps are the same apart from the package names noted along the way.

1. Install the packages

npm install @respectify/astro @respectify/client drizzle-orm @libsql/client
npm install -D drizzle-kit

For Postgres, install pg instead of @libsql/client (and @types/pg as a dev dependency).

2. Add the comment table to your database

Add the table to your Drizzle schema:

// src/db/schema.ts
export { respectifyComments } from "@respectify/astro/sqlite"; // or "@respectify/astro/postgres"

Point drizzle-kit at your database and schema:

// drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "turso", // or "postgresql"
  schema: "./src/db/schema.ts",
  dbCredentials: {
    url: process.env.TURSO_DATABASE_URL ?? "",
    authToken: process.env.TURSO_AUTH_TOKEN,
  },
});

Then generate and run the migration:

npx drizzle-kit generate
npx drizzle-kit migrate

The integration never creates or changes tables itself, so your schema stays under your control. If you manage migrations some other way, the package ships the SQL for its table in migrations/sqlite and migrations/postgres.

3. Write the runtime module

The database connection lives in a small module that runs inside your server bundle:

// src/respectify.runtime.ts
import { createClient } from "@libsql/client";
import { defineRespectifyRuntime } from "@respectify/astro/runtime";
import { createSqliteCommentStore } from "@respectify/astro/sqlite";
import { drizzle } from "drizzle-orm/libsql";
import { TURSO_AUTH_TOKEN, TURSO_DATABASE_URL } from "astro:env/server";

const db = drizzle({
  client: createClient({ url: TURSO_DATABASE_URL, authToken: TURSO_AUTH_TOKEN }),
});

export default defineRespectifyRuntime({
  store: createSqliteCommentStore(db),
  // Optional: the URL Respectify reads a post from for topic context
  getPostUrl: (slug, site) => `${site}/blog/${slug}/`,
});

For Postgres, use createPostgresCommentStore(db) from @respectify/astro/postgres with a drizzle-orm/node-postgres database.

4. Add the integration to astro.config.ts

import { defineConfig, envField } from "astro/config";
import node from "@astrojs/node";
import respectify from "@respectify/astro";

export default defineConfig({
  output: "server",
  adapter: node({ mode: "standalone" }),
  env: {
    schema: {
      TURSO_DATABASE_URL: envField.string({ context: "server", access: "secret" }),
      TURSO_AUTH_TOKEN: envField.string({ context: "server", access: "secret" }),
    },
  },
  integrations: [
    respectify({
      runtime: "./src/respectify.runtime.ts",
    }),
  ],
});

5. Wire up the Astro Actions

// src/actions/index.ts
import { respectifyCommentActions } from "@respectify/astro/actions";

export const server = {
  comments: respectifyCommentActions,
};

If you already have actions defined, merge them in:

export const server = {
  comments: respectifyCommentActions,
  // ...your other actions
};

6. Add environment variables

Add these to your .env file locally, and to your hosting provider’s environment for production:

RESPECTIFY_EMAIL=you@example.com
RESPECTIFY_API_KEY=your-api-key-from-dashboard
TURSO_DATABASE_URL=libsql://your-db.turso.io
TURSO_AUTH_TOKEN=your-turso-token

Get your Respectify credentials from the dashboard. Get your Turso credentials from turso.tech.

7. Drop the component into your layout

---
import CommentSection from "@respectify/astro/components/CommentSection.astro";
---

<!-- At the bottom of your blog post layout -->
<CommentSection postSlug={post.id} />

That’s it. The component handles rendering existing approved comments, the submission form, and Respectify’s feedback when a comment needs revising.

How moderation works

When a reader submits a comment, it goes to Respectify before anything is saved. Respectify checks for toxicity, spam, logical fallacies, and whether the comment is relevant to the post topic.

  • If the comment passes: it’s saved to your database and appears on the page straight away
  • If it fails: the commenter sees an explanation and a suggestion for how to revise it. Nothing is saved, but they can revise and try again.

You decide how strict that is: each kind of problem has a tolerance you can tighten or relax in respectify.config.json. If Respectify can’t be reached, the integration fails closed and turns the comment away rather than publishing it unchecked.

Customising the component

All styling is done via CSS variables on .rf-comments. Override them to match your site’s design:

.rf-comments {
  --rf-accent: #7c3aed;
  --rf-accent-hover: #6d28d9;
  --rf-radius: 0.5rem;
  --rf-font-size: 0.95rem;
}

The component ships with self-contained CSS — no Tailwind required, though it plays fine alongside it.

Available props:

Prop Default What it does
postSlug required Unique key for the comment thread
apiPath /api/respectify/comments Comments API path (must match the integration)
showBranding true Shows “Powered by Respectify” callout
enableDelete false Shows delete controls for authenticated admins
class — Extra class on the root wrapper

What about prerendered pages?

Comments load at runtime via a small API route, so your blog posts can stay export const prerender = true. Only the API route and actions need server runtime — the pages themselves stay static. This keeps your build fast and your CDN happy.

Checking the integration is working

After wiring everything up, run npm run dev and navigate to a page with the comment section. Submit a test comment with benign content — it should post successfully. Then try something clearly toxic (“you’re an idiot”) — you should see Respectify’s coaching response explaining the problem and suggesting a revision.

If anything isn’t working, check that your environment variables are set and that the drizzle-kit migration created the comment table.

Further reading

Powered by Respectify

Comments are analyzed in real time for spam and respectfulness before they appear. Leave a comment to see Respectify in action.

Try the demo →

Comments (…)

Loading comments…

No comments yet. Be the first to comment!

Leave a Comment

Your comment will be reviewed by Respectify before it appears.

Powered by Respectify