Skip to content
Proyectos

Acerca de

It’s my portfolio, reimagined as a chat conversation, answered by AI.

IA y aprendizaje automático

Cómo se miden estas cifras

What you can do

  • Streaming chat with markdown rendering and shadcn/typeset
  • Web search via OpenRouter's web search server tool
  • Web fetch via the AI SDK's first-party web fetch tool, with HTML-to-markdown conversion and SSRF protections
  • Human-in-the-loop questionnaire. The model can ask clarifying questions, answered with the shadcn questionnaire component

Crecimiento de estrellas medido

in 24h
0
in 7 days
Recopilando historial
in 15 days
Recopilando historial
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original
Nathan's AI — ask anything about Nathan Brodin

Nathan's AI

It’s my portfolio, reimagined as a chat conversation, answered by AI.

GitHub stars GitHub forks License

Features

  • Streaming chat with markdown rendering and shadcn/typeset
  • Tool calling
  • Web search via OpenRouter's web search server tool
  • Web fetch via the AI SDK's first-party web fetch tool, with HTML-to-markdown conversion and SSRF protections
  • Human-in-the-loop questionnaire. The model can ask clarifying questions, answered with the shadcn questionnaire component
  • Per-IP rate limiting on /api/chat with Upstash Redis + @upstash/ratelimit
  • Drizzle ORM + Neon PostgreSQL chat persistence
  • Server-rendered SEO surface: JSON-LD, canonical metadata, sitemap, robots, llms.txt, manifest, and dynamic OG images
  • Title animation from @jh3yy

Deploy

The vite config uses Nitro by default, which supports many deployment presets like Netlify, Vercel, Node.js, and more. Refer to the TanStack Start hosting docs for more information.

Set the following in your hosting provider's environment variables:

  • OPENROUTER_API_KEY, create one at openrouter.ai/keys.
  • UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN, create a Redis database at console.upstash.com, then copy the REST URL and REST token from the database details (or use the Vercel Upstash integration, which sets them automatically).
  • DATABASE_URL and GITHUB_API_TOKEN — see .env.schema, which is the source of truth for every variable. Use your Neon project's pooled connection string for DATABASE_URL.

After the first deploy, verify the domain in Google Search Console and Bing Webmaster Tools, then submit https://chat.brodin.dev/sitemap.xml.

Local development

Prerequisites

Setup

vp install

Create a Neon project, then create a .env.local file with your values based on .env.schema. Copy the pooled connection string into DATABASE_URL, then validate the environment:

vpr env:load

Create an OpenRouter key at openrouter.ai/keys and a Redis database at console.upstash.com.

Generate the initial migration with drizzle-kit, then apply it to your Neon database:

vpr db generate
vpr db migrate

https://orm.drizzle.team/docs/migrations

Start the dev server:

vpr dev

The development server should now be running at http://localhost:3000.

That's it, you are all set! If you run into any problems or have any questions, please hesitate to ask me.

Configuration

Varlock keeps the environment-variable contract in .env.schema and generates types from it. Put local values, including secrets, in the uncommitted .env.local, then run vpr env:load to validate them.

In application code, import { ENV } from "varlock/env" instead of reading process.env directly.

The model is defined in src/lib/chat/model.ts, together with its context window and output limit.

Rate limit

/api/chat is rate-limited per client IP with @upstash/ratelimit backed by Upstash Redis (Redis.fromEnv()).

Current windows, in src/routes/api/chat/route.ts:

Ratelimit.slidingWindow(5, "30s") // burst: 5 requests per 30 seconds
Ratelimit.slidingWindow(50, "24h") // daily: 50 requests per day

Both limits are keyed by the first IP in the x-forwarded-for header (requests without the header share a single fallback bucket). Exceeding either returns 429 with { "error": "Ratelimited" }. Tune the numbers there to match your budget — see the Security section below.

Security

The /api/chat route is public: every allowed request spends your OpenRouter credits. It is rate-limited (see Configuration above).

  • Rate limit is per-IP, not global. One IP is capped at 50 requests/day with the default windows, but N IPs (botnet, rotating proxies) get N× the budget.
  • Cap spend. Keep an OpenRouter spend limit as a backstop.
  • Add a WAF if abuse appears: add firewall rules from your hosting provider in front of /api/chat.
  • Requests without an x-forwarded-for header share one fallback bucket, so they throttle each other — expected on local dev, suspicious in production logs.
  • Web fetch can request any public URL. It blocks localhost, private, reserved, and cloud metadata addresses, including redirects and DNS-resolved addresses, and caps response size. Fetched content is untrusted and can contain prompt injections; set requireUrlInUserMessage: true in src/lib/chat/tools/web_fetch.ts so the model can only fetch URLs that appear in user messages.

The route already validates the request body, caps output tokens and step count, and aborts generation on client disconnect — but those bound a single request, not overall volume.

How it works

Tool parts

Assistant messages are a list of typed parts. src/components/chat/chat-message.tsx switches on part.type and delegates each one to a component in src/components/chat/parts/:

Part type Component Renders
text text-part.tsx Markdown via react-markdown and coss typeset.
tool-github_repo github-repo-part.tsx A spinner while the lookup runs, then a linked stat line (stars, forks, language).
tool-web_search web-search-part.tsx A "Searching the web…" status while the search runs, then a persistent "Searched the web" line per search.
tool-web_fetch web-fetch-part.tsx A "Reading…" status while the page loads, then a collapsible summary with a markdown preview and an external link.
tool-ask_user ask-user-part.tsx The answered questions inline. Pending questions render in question-card.tsx, pinned to the scroller bottom.
source-url sources-part.tsx Web search citations, deduped into a "Searched N websites" drawer once the message finishes streaming.

Tool parts move through states as the stream progresses — input-streaming → input-available → output-available (or output-error) — and each component switches on part.state to show progress, results, and failures.

Adding your own tool

  1. Create src/lib/chat/tools/<name>.ts (the filename is the model-facing tool name) exporting a tool() with a description, an inputSchema, and an execute function (omit execute for tools the user answers in the UI, like ask_user), then register it in src/lib/chat/tools/index.ts.
  2. Add a part component in src/components/chat/parts/ and a case "tool-<name>" in chat-message.tsx.

Message types are inferred from the tool definitions via InferUITools, so part.input and part.output are fully typed in your part component — renaming a tool field is a build error, not a silent undefined.

Logging

evlog is wired into the app through Nitro and emits one structured event per request. Chat requests also emit a correlated chat.ai event when the stream ends, because Nitro v3 logs the request before streamed AI usage is known. Add a drain when production needs logs sent to your chosen provider.

SEO & GEO

The indexable pages are /, /about, and /privacy. Conversation routes are noindex and excluded from the sitemap.

Machine-readable endpoints:

The public pages (/, /about, /privacy) also negotiate content. Requests that include Accept: text/markdown receive markdown — the homepage returns the site index — while browsers asking for HTML get the app. Both variants send Vary: Accept so shared caches keep them separate.

The canonical Person entity lives on brodin.dev. Chat's JSON-LD references https://brodin.dev/#person rather than defining a competing profile.

When page content changes, update lastModified in src/lib/seo.ts. If the logo changes, run vpr icons to regenerate the favicon and PWA icon set.

Scripts

Check package.json for the full list of available scripts.

  • db - Run drizzle-kit commands. (e.g. vpr db generate, vpr db studio)
  • ui - The shadcn/ui CLI. (e.g. vpr ui add button)
  • icons - Regenerate the favicon, Apple touch icon, and PWA icons with scripts/generate-icons.mjs.
  • format, lint - Run Oxfmt and Oxlint, or both via vpr check.
  • deps - Selectively upgrade dependencies via taze. Dependency versions are pinned, so run vpr deps to selectively upgrade packages.

Utilities

Issue watchlist

  • Devtools releases - TanStack Devtools is in alpha and may still have breaking changes.
  • Nitro v3 beta - The app is configured with Nitro v3 beta by default.
  • evlog Nitro v3 streaming - Nitro v3 emits request events at response headers, so stream-end AI usage is logged as a separate correlated chat.ai event.
  • Drizzle ORM v1 RC - Drizzle ORM v1 is in RC with relations v2.

License

MIT, see LICENSE.

Explorar proyectos relacionados

Cargando…