Because rebuilding auth for every project is a waste of time.
This is a Fastify backend template that already includes the stuff you end up writing anyway:
JWT auth, signup/login, password reset, email, MongoDB, and error handling.
Clone it, rename it, and pretend you wrote it from scratch.
- Sets up a Fastify server
- Handles JWT authentication (access + refresh tokens)
- Provides signup, login, logout, and token refresh
- Implements forgot-password and reset-password flows
- Sends emails via SMTP
- Centralizes error handling so your app doesn’t explode
- Works locally and deploys cleanly on Vercel
No frameworks inside frameworks. No magic. Just code.
git clone https://github.com/Ratul-islam/fastify-template.git
cd fastify-template
npm install
### 2. Environment setup
Create a `.env` file in the root of the project. Yes, it’s required.
```env
# App
NODE_ENV=development
# Database
MONGO_URL=your_mongodb_connection_string
# JWT
JWT_SECRET=your_main_secret
JWT_ACCESS_SECRET=your_access_secret
JWT_REFRESH_SECRET=your_refresh_secret
JWT_PASS_RESET_SECRET=your_password_reset_secret
# Email (SMTP)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_email_app_password
SMTP_FROM=your_email@gmail.comI’m open to any suggestions and improvements.
If you notice a mistake, a bad pattern, or know a better way to do something, I’d really appreciate it if you point it out.
Feel free to open an issue or submit a pull request.
Contributions are welcome and appreciated.
If you want to contribute:
- Fork the repository
- Create a new branch
- Make your changes
- Open a pull request with a clear description
Even small improvements or suggestions help. You’re free to use it, modify it, and ship it in your own projects.