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