saas-template-injector
v1.0.0
Published
Automatically inject complete SaaS functionality into existing Next.js projects with authentication, payments, database, and admin features
Downloads
9
Maintainers
Readme
saas-template-injector
🚀 Instantly transform any Next.js project into a production-ready SaaS application
✨ Features
- 🔐 Authentication: Complete auth system with NextAuth.js (Google, GitHub, Credentials)
- 💳 Payments: Stripe integration with subscriptions and webhooks
- 🗄️ Database: PostgreSQL + Prisma ORM with migrations
- 👥 Admin Dashboard: User management, analytics, and monitoring
- 🛡️ Route Protection: Middleware-based access control
- 💰 Credit System: Optional credit-based billing
- 📊 Analytics: Built-in analytics dashboard
- 🎨 Styling: Tailwind CSS with shadcn/ui components
- 📝 TypeScript: Full TypeScript support
🚀 Quick Start
# Install globally
npm install -g saas-template-injector
# Navigate to your Next.js project
cd my-nextjs-app
# Inject SaaS template (dry run first)
saas-inject subscription . --dry-run
# Apply the template
saas-inject subscription . --install📦 Installation
Global Installation (Recommended)
npm install -g saas-template-injectorLocal Installation
npm install saas-template-injector --save-devUsing npx (No Installation)
npx saas-template-injector subscription ./my-app🎯 Usage
Command Line Interface
saas-inject <template> [project-path] [options]Arguments
template- Template name or path to custom JSON templateproject-path- Path to Next.js project (default: current directory)
Options
-h, --help- Show help-v, --version- Show version-d, --dry-run- Preview changes without modifying files--verbose- Show detailed output-i, --install- Install dependencies after generation-m, --migrate- Run database migrations-f, --force- Force injection even if not Next.js--conflict-strategy- How to handle conflicts (merge|overwrite|skip|abort)
Preset Templates
1. Subscription (Full SaaS)
saas-inject subscription ./my-appIncludes: Auth, Stripe subscriptions, admin panel, user dashboard
2. Basic (Starter)
saas-inject basic ./my-appIncludes: Auth, database, basic dashboard
3. Credits (Usage-based)
saas-inject credits ./my-appIncludes: Credit system, usage tracking, pay-per-use
4. Enterprise (Advanced)
saas-inject enterprise ./my-appIncludes: Multi-tenant, SSO, audit logs, advanced analytics
Custom Templates
Create your own template JSON:
{
"metadata": {
"name": "My Custom SaaS",
"version": "1.0.0"
},
"configuration": {
"plans": [
{
"name": "Starter",
"price": 9,
"features": ["Feature 1", "Feature 2"]
}
],
"integrations": {
"stripe": true,
"nextauth": true
}
}
}Use it:
saas-inject ./my-template.json ./my-app🏗️ What Gets Generated
your-nextjs-app/
├── app/
│ ├── (auth)/
│ │ ├── signin/page.tsx # Sign in page
│ │ └── signup/page.tsx # Sign up page
│ ├── (dashboard)/
│ │ ├── dashboard/page.tsx # User dashboard
│ │ ├── billing/page.tsx # Billing management
│ │ └── settings/page.tsx # User settings
│ ├── admin/
│ │ ├── dashboard/page.tsx # Admin dashboard
│ │ ├── users/page.tsx # User management
│ │ └── analytics/page.tsx # Analytics
│ └── api/
│ ├── auth/[...nextauth]/ # NextAuth endpoints
│ ├── webhooks/stripe/ # Stripe webhooks
│ └── subscriptions/ # Subscription API
├── components/
│ ├── auth/ # Auth components
│ ├── subscription/ # Billing components
│ └── admin/ # Admin components
├── lib/
│ ├── auth.ts # Auth configuration
│ ├── db.ts # Database client
│ └── stripe.ts # Stripe client
├── prisma/
│ ├── schema.prisma # Database schema
│ └── seed.ts # Seed data
├── middleware.ts # Route protection
├── .env.example # Environment template
└── package.json # Updated dependencies🔧 Programmatic API
const { injectSaaSTemplate, createTemplate } = require('saas-template-injector');
// Use preset template
await injectSaaSTemplate('subscription', './my-app', {
dryRun: false,
install: true
});
// Create custom template
const template = createTemplate({
name: 'My SaaS',
plans: [
{ name: 'Free', price: 0 },
{ name: 'Pro', price: 29 }
]
});
// Apply custom template
await injectSaaSTemplate(template, './my-app');🛠️ Configuration
Environment Variables
After injection, configure your .env.local:
# Database
DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key"
# Stripe
STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_SECRET_KEY="sk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."
# OAuth (Optional)
GOOGLE_CLIENT_ID="..."
GOOGLE_CLIENT_SECRET="..."
GITHUB_CLIENT_ID="..."
GITHUB_CLIENT_SECRET="..."Database Setup
# Generate Prisma client
npx prisma generate
# Run migrations
npx prisma db push
# Seed database (optional)
npx prisma db seedStripe Setup
- Create products in Stripe Dashboard
- Add webhook endpoint:
https://yourapp.com/api/webhooks/stripe - Configure webhook events:
customer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_succeeded
📋 Examples
Basic Injection
saas-inject subscription ./my-appDry Run First
saas-inject subscription ./my-app --dry-runFull Setup
saas-inject subscription ./my-app --install --migrateForce Overwrite
saas-inject subscription ./my-app --conflict-strategy=overwriteCustom Template
saas-inject ./custom-saas.json ./my-app --verbose🤝 Conflict Resolution
The tool intelligently handles existing files:
- merge (default) - Merge with existing files
- overwrite - Replace existing files
- skip - Skip existing files
- abort - Stop if conflicts found
🔍 Project Analysis
Before injection, the tool analyzes your project:
- Detects Next.js version
- Identifies existing routes
- Checks for TypeScript/Tailwind
- Finds potential conflicts
- Validates project structure
🎨 Customization
Create Custom Templates
const { createTemplate } = require('saas-template-injector');
const myTemplate = createTemplate({
name: 'My Custom SaaS',
projectType: 'subscription',
plans: [
{
name: 'Starter',
price: 9,
features: ['Feature 1', 'Feature 2']
}
],
integrations: {
stripe: true,
nextauth: true,
analytics: true
}
});
// Save as JSON
fs.writeFileSync('my-template.json', JSON.stringify(myTemplate, null, 2));🚨 Important Notes
- Backup your project before running
- Use
--dry-runto preview changes - Review generated files
- Update environment variables
- Test thoroughly after injection
📝 License
MIT
🤝 Contributing
Contributions welcome! Please read our Contributing Guide.
🐛 Bug Reports
Found a bug? Open an issue
📚 Documentation
Full documentation: https://docs.saas-injector.com
💖 Support
If this tool saved you time, consider:
- ⭐ Starring the repo
- 🐦 Sharing on Twitter
- ☕ Buying me a coffee
Made with ❤️ for rapid SaaS development
Transform your Next.js app into a SaaS in minutes, not days!
