fastify-auth-starter
Version:
Scaffold a Fastify + Prisma + Auth backend app
154 lines (108 loc) • 3.56 kB
Markdown
# Fastify Auth Starter CLI
A CLI tool to scaffold a production-grade backend using **Fastify + TypeScript + Prisma + PostgreSQL** - ready to go with built-in authentication, role management, and modern best practices.
Use it to kickstart new apps with all common boilerplate setup out of the box.
## 📦 Features Included
✅ Node.js + Fastify
✅ TypeScript + Prisma
✅ PostgreSQL via Docker
✅ JWT-based Authentication (Login, Signup)
✅ Email Verification & Forgot/Reset Password
✅ Role-based Access Control
✅ Basic Admin Dashboard API stats
✅ User management
✅ Image upload & asset handling
✅ Swagger API documentation
✅ CORS configuration and security
✅ Input validation with Zod schemas
✅ Comprehensive error logging
✅ Health check endpoint
✅ ESLint + Prettier for code quality, Husky git hooks
### 🧠 Template Highlights
- 🔁 Follows **DRY (Don't Repeat Yourself)** principle
- 🧱 **Modular, class-based architecture** for scalability
- 🗂️ Structured for separation of concerns (routes, controllers, services, plugins)
- ✅ Pre-configured with Zod validation, Swagger, and type-safe Prisma integration
## 🎯 Frontend Compatibility
This backend works seamlessly with the [**Next Auth Starter Kit**](https://www.npmjs.com/package/next-auth-starter-kit) frontend CLI.
Use it together to build a fullstack, production-ready app with:
- Pre-wired auth flows (login, registration, email verification, etc.)
- Role-based UI rendering
- Compatible API contract and token structure
- Dashboard and user management integration
> If you're using a different frontend, just ensure:
>
> - API routes (`/auth/login`, `/auth/register`, etc.) match your client
> - Token format and HTTP status codes align
> - Role-based access and profile data are supported
## 📦 Installation & Usage
### Quickstart
```bash
npx fastify-auth-starter my-app
```
You will be prompted to:
- Provide a project name (if not passed)
- Choose your preferred package manager
- Optionally initialize a Git repository
### Optional: Specify Package Manager
```bash
npx fastify-auth-starter my-app --pm npm
```
Supports: `pnpm`, `npm`, or `yarn`.
## 📁 What Gets Generated?
Your project will follow this structure:
```
src/
├── app.ts
├── config/
├── controllers/
├── lib/
├── plugins/
├── routes/
├── schema/
├── server.ts
├── services/
├── template/
├── tests/
├── types/
└── utils/
```
A complete `README.md` is also included in the scaffolded project, explaining:
- .env setup
- Docker DB commands
- Prisma migration
- Dev vs Prod runs
- API usage and Swagger docs
## ⚙️ Setting Up the Database
This starter kit no longer includes pre-built migrations. To set up your database:
1. Edit `prisma/schema.prisma` to match your data needs
2. Set your `.env` with the correct `DATABASE_URL`
3. Run:
```bash
pnpm migrate
```
## 🔧 Local Development (for CLI contributors)
Clone and run locally:
```bash
pnpm install
pnpm build
pnpm dev
```
This will invoke the CLI with live TS support.
## 🧩 Extendable for Real Projects
This scaffold is production-ready and can be extended with:
- OAuth (Google, GitHub, LinkedIn)
- 2FA/MFA support
- Redis-based session and cache management
- Queue systems (e.g. BullMQ for jobs and workers)
- Multi-tenant support or SaaS-style apps
## 📄 Developer Guide
All contributors must follow the [Developer Guide](./docs/Developer_Guide.md).