跳到正文
GitHub·· 9 天前AI 评分38

MohammedAltounsi 的 AI-Website-Auditor:用 Claude 与 PageSpeed 生成网站健康评分

MohammedAltounsi/AI-Website-Auditor

AI 导读

开源项目 AI-Website-Auditor 输入 URL 即可返回网站 Health Score、Google PageSpeed Insights 的性能/无障碍/SEO/最佳实践四项评分、Claude 撰写的摘要和按严重程度排序的修复清单,支持导出 PDF 或 CSV。

正文

AI Website Auditor: paste a URL, get a Health Score from real PageSpeed data and a ranked list of fixes. Sample panel shows a stripe.com audit scoring 73.

Live demo status Next.js 16 TypeScript 5 Data from Google PageSpeed Insights Tested with Vitest

Open the live demo · Run it locally · How it works

Paste a URL and the auditor returns a Health Score, a breakdown of performance, accessibility, SEO and best practices from Google PageSpeed Insights, a short Claude-written summary, and a severity-ranked list of fixes. You can export the report as PDF or CSV.

A real run

The live auditor after scanning stripe.com: Health Score 73, with Performance 44, Accessibility 100, SEO 92 and Best Practices 54

This is the live app auditing stripe.com. The four category scores come straight from PageSpeed. The 73 in the middle is their average, rounded.

The core design decision

The model never produces the Health Score. The code takes the four real PageSpeed scores and runs Math.round() on their average, so the same site gets the same score on every audit. Claude writes the summary and the fix list and nothing else.

The rule this project demonstrates: the model explains, the code decides anything that has to stay consistent between runs.

How an audit runs

Four stages: 01 Fetch (scrape.ts) and 02 Score (pagespeed.ts) run in code; 03 Explain (analyze.ts) calls Claude with forced tool-use for a summary and five fixes; 04 Report (route.ts) returns one JSON report with PDF and CSV export.

File-by-file walkthrough

  1. lib/scrape.ts fetches the target page and extracts on-page SEO signals with cheerio: title, meta description, H1 count, alt-text coverage, canonical tag, viewport meta and word count.
  2. lib/pagespeed.ts calls the PageSpeed Insights API (mobile strategy) for the four category scores, retries transient 5xx errors up to three times, and computes the Health Score as their average.
  3. lib/analyze.ts sends the scrape and PageSpeed data to Claude with forced tool-use (tool_choice: { type: 'tool' }). The response is always a structured object that matches the submit_audit_report schema, never free text to parse.
  4. app/api/audit/route.ts runs the pipeline and returns one JSON report.
  5. app/page.tsx + app/components/* render the URL form, the animated Health Score gauge, the category breakdown, the severity-badged fix list, and PDF (browser print) and CSV export.

Safe to point at any URL

The auditor fetches whatever public URL a visitor types, so lib/scrape.ts treats that input as hostile:

  • SSRF protection. It resolves DNS first, blocks private, loopback, link-local and IPv4-mapped IPv6 ranges, then pins the connection to the checked IP. A public hostname that resolves to 169.254.169.254 gets rejected.
  • Redirects. It follows up to 5 redirects by hand and re-checks every hop, so a public URL cannot redirect into an internal address.
  • Limits. Each fetch times out after 15 seconds and stops reading at 5 MB.
  • CSV export. It escapes cells that start with =, +, - or @ to prevent formula injection in spreadsheet apps.

Run it locally

You need Node.js, an Anthropic API key and a Google Cloud key with the PageSpeed Insights API enabled.

npm install
cp .env.local.example .env.local
# set ANTHROPIC_API_KEY and PAGESPEED_API_KEY in .env.local
npm run dev

Run the test suite:

npm test

Stack

Next.js 16 (App Router), TypeScript, Tailwind CSS 4, Google PageSpeed Insights API, Anthropic API (claude-sonnet-5 with forced tool-use), Vitest and Testing Library.

Roadmap

  • Persist past audits (Postgres or Supabase) so a user can reopen a report by link.
  • Competitor mode: audit two URLs and diff the fixes.
  • AI-crawler (GEO) visibility check: can ChatGPT, Perplexity or Gemini find and cite the page.
  • Weighted Health Score once real usage shows which category should count more.
  • Mobile and desktop PageSpeed toggle instead of mobile only.
  • Per-IP rate limiting (Vercel KV) once the tool sees real traffic.

Built and designed by Mohammed Altounsi · LinkedIn

来源:GitHub · github.com