::
FIG 2.1 // ENTRY
Back to Index

Fastify + Astro starter

Date:

Github Repo

Latest Update

Following the deprecation of Lucia, I migrated session management to the recommended approach at lucia-next.pages.dev. This update also includes general fixes and improvements, such as resolving dark mode screen flashes.

Why?

As a solo developer, I often build JavaScript applications with separated server and client builds. While this is a valid approach—optimizing the client for the browser and the server for the backend—managing state across both can be complex.

I missed the simplicity of server-generated content enriching the client. While meta-frameworks like Next.js, Remix, Nuxt, and Astro handle this with SSR, I wanted a solution that combined Astro’s frontend capabilities with a robust backend like Fastify.

Decisions

I appreciate Astro’s approach, particularly ViewTransitions and its SPA mode. It offers excellent examples and supports various frontend frameworks. For the backend, Fastify is my preferred choice.

I explored two integration approaches:

  1. Astro Adapter for Fastify: I found a repository with contributions from both Astro and Fastify maintainers. However, it didn’t work out of the box. Although I forked it and fixed dev mode, production mode remained problematic.

  2. Node Middleware: Astro’s documentation provides middleware instructions for Node adapters. While this offers a clean separation, the example server wasn’t in TypeScript. Since I planned to use TRPC and Drizzle, a non-TypeScript backend was a dealbreaker.

Ultimately, I realized I could update my npm scripts to use tsx for watching and rollup for building. This flexible configuration aligns with Vite’s tooling and the recommended Astro setup.

Summary

This starter combines Astro, Fastify, TRPC, Lucia, React, NextUI, and Drizzle. It features:

  • Full TypeScript support for end-to-end type safety.
  • Session-based authentication via Lucia.
  • Pre-configured login and registration flows.

Check out the Github Repo and let me know your thoughts.