backend-auth
v1.0.9
Published
A CLI to generate Express backend boilerplates with Authentication (PostgreSQL/Prisma & MongoDB/Mongoose)
Maintainers
Readme
🚀 backend-auth
The Universal Authentication API Generator for Node.js
backend-auth is a powerful CLI tool that generates production-ready, battle-tested backend authentication systems instantly. Stop writing boilerplate auth code—just run a single command and get a fully configured Node.js server with JWT authentication, security middlewares, database connections, and user models.
✨ Features
- ⚡ Instant Setup: Get a running API in seconds, not hours.
- 🛠️ Multiple Stacks: Choose between Express + MongoDB (Mongoose) or Express + PostgreSQL (Prisma).
- 🧩 Feature Injection System: Add modular, self-contained features directly into your existing project (e.g., OTP Verification, Roles).
- 🔒 Secure by Default: Comes pre-configured with
helmet,cors,bcryptjs, and JSON Web Tokens (JWT). - 📝 TypeScript Ready: Fully typed out of the box.
📦 Getting Started
You do not need to install the package globally. You can run it instantly using npx:
npx backend-auth initThe CLI will prompt you for:
- Project Name: The directory where your backend will be generated.
- Framework: Choose Express.
- Database: Choose MongoDB or PostgreSQL.
- ORM: Choose Mongoose or Prisma.
Once generated, your project will come with an auto-generated .env file containing connection URIs, a secure JWT secret, and ports.
Running your new project:
cd <your-project-name>
npm run dev🧩 Adding Features
backend-auth uses an "additive" feature injection system. Once you generate a base project, you can inject modular features into it.
For example, to add an Email/Phone OTP (One-Time Password) Verification system to your project:
# Make sure you are inside your generated project folder!
npx backend-auth add otpThis will safely inject the routes, controllers, and services needed for OTP verification directly into your codebase.
Available Features
otp- OTP Generation & Verification flow- More features like
roles(RBAC) andforgot-passwordcoming soon!
📂 Project Structure
A generated backend-auth API is beautifully organized:
├── src/
│ ├── config/ # Database connections & environment variables
│ ├── controllers/ # Route handlers (e.g., authController.ts)
│ ├── middleware/ # JWT validation & error handling
│ ├── models/ # Database schemas (Mongoose) or Prisma clients
│ ├── routes/ # Express API routes
│ ├── utils/ # Helpers like jwt token generation
│ ├── app.ts # Express app configuration
│ └── index.ts # Server entrypoint
├── prisma/ # (Only if using Prisma/PostgreSQL)
├── .env # Environment Variables
├── .backend-auth.json # Internal configuration state
├── package.json
└── tsconfig.json🤝 Contributing
Contributions are always welcome! Feel free to open issues or submit Pull Requests to expand template support (e.g., NestJS, Fastify).
📄 License
MIT
