A production-ready authentication system built with clean architecture principles and modern technologies
This comprehensive full-stack authentication template is designed with clean architecture principles, providing a solid foundation for building scalable web applications with robust user authentication and authorization systems.
π Documentation: https://full-stack-clean-auth-template.vercel.app/
π CLI Package: https://www.npmjs.com/package/clean-auth

The template demonstrates modern web development practices with a focus on security, scalability, and maintainability. It includes comprehensive authentication flows, role-based access control, and production-ready deployment configurations.
The fastest way to get started is using our CLI tool:
Install the CLI
npm install -g clean-auth
Create a New Project
clean-auth init my-auth-project --install
cd my-auth-project
Configure Authentication
clean-auth auth-config
Start Development
pnpm dev
If you prefer to set up the project manually without installing the CLI globally:
- Clone the repository
git clone https://github.com/sinanptm/fullstack-clean-auth-template.git
cd fullstack-clean-auth-template
- Install dependencies
pnpm install
- Environment Configuration
Start Development
pnpm dev
π οΈ CLI Commands
The clean-auth CLI provides powerful commands to scaffold and manage your authentication project:
Create a new full-stack authentication project with clean architecture.
clean-auth init <project-name> [options]
Options:
-i, --install
- Automatically install dependencies after project creation
Examples:
clean-auth init my-auth-project
clean-auth init my-auth-project --install
Set up environment variables and authentication configuration interactively.
clean-auth auth-config [options]
Options:
-s, --skip
- Skip interactive prompts and use default values
Examples:
clean-auth auth-config
clean-auth auth-config --skip
Remove unnecessary parts of your project structure to customize it for your needs.
clean-auth clean [options]
Options:
-s, --server
- Remove entire server directory and update root configurations-w, --web
- Remove entire web directory and update root configurations-o, --opensource
- Remove open source files (LICENSE, CONTRIBUTING.md, README.md)
Examples:
clean-auth clean --server
clean-auth clean --web --opensource
Display a list of all available commands.
clean-auth help
clean-auth --help
clean-auth init --help
π± Application Screenshots
π Authentication Flow Diagram
graph TB
%% Entry Point
A["π Sign In/Up Page"] --> B{"Authentication Method"}
%% Email/Password Flow
B -->|"π§ Email/Password"| C["π Enter Credentials"]
C --> D{"Valid Credentials?"}
D -->|"β"| E["β Error Message"]
E --> C
D -->|"β
"| F["π’ Generate OTP"]
F --> G["π§ Send OTP Email"]
G --> H["π’ OTP Verification Page"]
H --> I["Enter OTP Code"]
I --> J{"Valid & Fresh OTP?"}
J -->|"β"| K["Try Again"]
K --> I
J -->|"β
"| L["π― Generate JWT"]
%% OAuth Flow
B -->|"π₯ OAuth (Google/GitHub)"| M["π₯ Firebase OAuth Popup"]
M --> N["π€ Select Provider"]
N --> O["π Provider Authentication"]
O --> P{"Auth Success?"}
P -->|"β"| Q["β OAuth Error"]
Q --> A
P -->|"β
"| R["π― Get Firebase Token"]
R --> S["π§ Extract User Info"]
S --> T["π Send Token to Backend"]
T --> U["π Validate Firebase Token"]
U --> V{"Token Valid?"}
V -->|"β"| W["β Token Invalid"]
W --> A
V -->|"β
"| X{"User Exists?"}
X -->|"β"| Y["π€ Create New User"]
X -->|"β
"| Z["π Update User Info"]
Y --> L
Z --> L
%% Common Final Steps
L --> AA["πͺ Set HTTP-Only Cookies"]
AA --> BB["β¨ Authenticated User"]
BB --> CC["π‘οΈ User Dashboard Access"]
%% Additional Flows
DD["π Token Expiry"] --> EE["π Auto Refresh"]
EE --> BB
FF["π Forgot Password"] --> GG["π§ Reset Email with OTP"]
GG --> HH["π’ OTP Verification"]
HH --> II["π New Password"]
II --> A
%% Admin Flow (Separate)
JJ["π Admin Login"] --> KK["π§ Admin Credentials"]
KK --> LL["π Validate with .env"]
LL --> MM{"Match Admin Config?"}
MM -->|"β"| NN["β Access Denied"]
NN --> JJ
MM -->|"β
"| OO["π― Generate Admin JWT"]
OO --> PP["π·οΈ Set Admin Role"]
PP --> QQ["πͺ Set Admin Cookies"]
QQ --> RR["β¨ Authenticated Admin"]
RR --> SS["π Admin Panel Access"]
β¨ Key Features
- Clean Architecture - Domain-driven design with clear separation of concerns
- Modular Structure - Easy to extend and maintain
- Framework Independence - Core business logic is decoupled from frameworks
- TypeScript First - Full type safety across the entire stack
- Multi-factor Authentication - Email/Password with OTP verification
- OAuth Integration - Google and GitHub social login
- Role-based Access Control - User and admin roles with protected routes
- JWT Token Management - Secure access and refresh token implementation
- Security Best Practices - Rate limiting, CORS, bcrypt hashing
- Frontend: Next.js 15, React 19, Tailwind CSS, Shadcn UI
- Backend: Express.js 5, Node.js, TypeScript
- Database: MongoDB with Mongoose ODM
- State Management: Zustand + React Query
- Authentication: Firebase OAuth, JWT, Nodemailer
- Scalable Architecture - Built for enterprise-level applications
- Comprehensive Testing - Unit and integration tests included
- Development Tools - ESLint, Prettier, Hot reload
- Deployment Ready - Production-optimized builds
- CI/CD Pipeline - Automated testing, building, and quality checks
- Node.js v20 or higher
- pnpm v10.8.1 or higher
- MongoDB (local installation or MongoDB Atlas)
- Firebase project with Authentication enabled
- Separation of Concerns: Each layer has a single responsibility
- Dependency Inversion: Abstractions don't depend on concrete implementations
- Testability: Business logic is framework-independent
- Maintainability: Easy to modify and extend features
- Continuous Integration - Automated testing and building on every push
- Quality Assurance - Code formatting, linting, and type checking
- Security Auditing - Weekly dependency vulnerability scans
- Dependency Management - Automated dependency updates with PR creation
Workflow | Trigger | Purpose |
---|---|---|
CI/CD Pipeline | Push to main /develop , PRs |
Build, test, and quality checks |
Security Audit | Weekly schedule, Push/PR | Vulnerability scanning |
Update Dependencies | Weekly schedule, Manual | Automated dependency updates |
- Parallel Execution - Server and web builds run simultaneously
- Caching Strategy - Optimized build times with dependency caching
- Artifact Management - Build artifacts stored for deployment
- Multi-stage Validation - Tests, linting, and type checking
π Authentication Endpoints
Method | Endpoint | Description | Body |
---|---|---|---|
POST |
/api/auth/signup |
User registration | { email, password, name } |
POST |
/api/auth/signin |
Email/password login | { email, password } |
POST |
/api/auth/verify-otp |
Verify OTP code | { email, otp } |
POST |
/api/auth/oauth-2 |
OAuth authentication | { firebaseToken } |
POST |
/api/auth/forgot-password |
Request password reset | { email } |
POST |
/api/auth/reset-password |
Reset password with OTP | { email, otp, newPassword } |
POST |
/api/auth/refresh |
Refresh access token | { refreshToken } |
POST |
/api/auth/logout |
User logout | - |
π€ User Endpoints
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET |
/api/user/profile |
Get user profile | β User |
PUT |
/api/user/profile |
Update user profile | β User |
π Admin Endpoints
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST |
/api/admin/signin |
Admin login | - |
GET |
/api/admin/users |
List all users | β Admin |
GET |
/api/admin/users/:id |
Get specific user | β Admin |
PUT |
/api/admin/users/:id |
Update user | β Admin |
DELETE |
/api/admin/users/:id |
Delete user | β Admin |
GET |
/api/admin/analytics |
System analytics | β Admin |
π Security Features
- JWT Tokens: Secure access and refresh token implementation
- HTTP-Only Cookies: Protection against XSS attacks
- Password Hashing: bcrypt with 10 salt rounds
- OTP Verification: Time-limited one-time passwords
- Role-Based Access Control (RBAC): User and admin roles
- Protected Routes: Middleware-based route protection
- Token Validation: Server-side Firebase token verification
- Rate Limiting: Request throttling to prevent abuse
- CORS Configuration: Cross-origin request security
- Input Validation: Comprehensive Joi schema validation
- SQL Injection Prevention: Parameterized database queries
- Request Logging: Detailed API request logging
- Error Tracking: Comprehensive error handling
- Security Headers: Helmet.js security headers
pnpm dev # Start both frontend and backend
pnpm format # Format code using Prettier
pnpm lint # Lint entire project
pnpm dev # Start development server with hot reload
pnpm build # Build for production
pnpm start # Start production server
pnpm test # Run test suite
pnpm dev # Start Next.js development server
pnpm build # Build for production
pnpm start # Start production server
pnpm lint # Lint frontend code
We welcome contributions from the community! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Follow the existing code style and architecture patterns
- Add tests for new functionality
- Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow the clean architecture principles
- Write comprehensive tests for new features
- Update documentation for API changes
- Use TypeScript for type safety
- Follow the existing code formatting standards
If you find a bug or have a feature request, please open an issue with:
- Clear description of the problem
- Steps to reproduce (for bugs)
- Expected vs actual behavior
- System information (OS, Node.js version, etc.)
This project is licensed under the MIT License - see the LICENSE file for details.
- β Commercial Use: Use this code in commercial projects
- β Modification: Modify the code as needed
- β Distribution: Share and distribute the code
- β Private Use: Use for private projects
- β License Notice: Keep the original license notice
- π Documentation: Full Documentation
- π Bug Reports: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π¦ NPM Package: clean-auth CLI