Express Auth Boilerplate 🚀
✨ Features
🔐 Security
- JWT Authentication with refresh tokens
- Two-Factor Auth (2FA) with QR code support
- Email Verification with secure tokens
- Rate Limiting against DDoS attacks
- CORS Protection with configurable origins
- Password Hashing with bcrypt
- XSS Protection with security headers
🏗 Architecture
- Clean Architecture principles
- Domain-Driven Design patterns
- Repository Pattern for data access
- Error Handling with custom AppError
- Dependency Injection ready
🧪 Quality Assurance
- 100% TypeScript coverage
- Jest Testing with mocks
- ESLint & Prettier configured
- Git Hooks with Husky
- CI/CD ready
🐳 Infrastructure
- Docker Compose setup
- PostgreSQL database
- MailHog for email testing
- Hot Reload development
- Swagger UI documentation
🚀 Quick Start
# Create new project
npx create-express-auth my-app
# Navigate and start services
cd my-app && docker-compose up -d
📚 Documentation
Authentication API
POST /api/auth/register # Create new account
POST /api/auth/login # Get JWT token
GET /api/auth/verify # Verify email
Two-Factor Auth API
POST /api/otp/enable # Enable 2FA
POST /api/otp/verify # Verify OTP code
POST /api/otp/disable # Disable 2FA
🛠 Development
# Start development server
npm run dev
# Run tests
npm test
# Database operations
npm run prisma:generate # Generate Prisma client
npm run prisma:migrate # Run migrations
npm run seed # Seed database
📦 Project Structure
src/
├── application/ # Business Logic Layer
│ └── use-cases/ # Application Use Cases
│
├── domain/ # Domain Layer
│ ├── entities/ # Business Objects
│ ├── repositories/ # Data Contracts
│ └── errors/ # Error Handling
│
├── infrastructure/ # Infrastructure Layer
│ ├── http/ # Express Setup
│ │ ├── controllers/ # Request Handlers
│ │ ├── middlewares/ # HTTP Pipeline
│ │ └── routes/ # API Routes
│ └── services/ # External Services
│
└── test/ # Test Suites
🔧 Environment Variables
# Server
PORT=8080
NODE_ENV=development
# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/auth-boiler-plate
# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=1d
# Email
SMTP_HOST=mailhog
SMTP_PORT=1025
🌐 Available Services
📝 License
MIT © Francesco Mazzi