A production-ready full-stack authentication template with React, TypeScript, Express, and MongoDB.
🎨 This is a template repository - Use it as a starting point for your projects!
-
🔐 Complete Authentication System
- User registration and login
- JWT-based authentication
- Password reset via email
- Secure password hashing with bcrypt
-
🎨 Modern Frontend
- React 18 with TypeScript
- Tailwind CSS for styling
- React Router for navigation
- React Hook Form + Zod for validation
- TanStack Query for server state management
-
⚡ Robust Backend
- Express.js REST API
- MongoDB with Mongoose
- Input validation with Zod
- Comprehensive error handling
- Winston logger
-
🧪 Testing Ready
- Jest configuration
- Unit test examples
- MongoDB Memory Server for testing
- Node.js (v18 or higher)
- MongoDB (local or Atlas)
- npm or yarn
-
Clone the repository
git clone <your-repo-url> cd fullstack-auth-template
-
Install dependencies
# Install backend dependencies cd backend npm install # Install frontend dependencies cd ../frontend npm install
-
Configure environment variables
Create
.envfiles by copying the example files:# macOS/Linux cp backend/.env.example backend/.env cp frontend/.env.example frontend/.env # Windows (Command Prompt) copy backend\.env.example backend\.env copy frontend\.env.example frontend\.env # Windows (PowerShell) Copy-Item backend\.env.example backend\.env Copy-Item frontend\.env.example frontend\.env
Backend (
backend/.env):# Application Settings APP_NAME=Your App Name # Server Configuration PORT=5000 NODE_ENV=development # Database DATABASE_URL=mongodb://localhost:27017/your-project-name # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-change-this-in-production-min-32-chars JWT_EXPIRES_IN=15m JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production-32 JWT_REFRESH_EXPIRES_IN=7d # Frontend URL FRONTEND_URL=http://localhost:5173 # Email Configuration (for password reset emails) EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_USER=your-email@gmail.com EMAIL_PASSWORD=your-app-password EMAIL_FROM=noreply@yourapp.com
Frontend (
frontend/.env):# Application Settings VITE_APP_NAME=Your App Name # API Configuration VITE_API_URL=http://localhost:5000/api
-
Start MongoDB
Option A: Local MongoDB
# Windows mongod --dbpath C:\data\db # macOS/Linux mongod --dbpath /path/to/your/db # Or if MongoDB is installed as a service # Windows: Already running as service # macOS: brew services start mongodb-community # Linux: sudo systemctl start mongod
Option B: MongoDB Atlas
- Create a free cluster at MongoDB Atlas
- Get your connection string
- Update
DATABASE_URLinbackend/.envwith your Atlas connection string
-
Start the development servers
Open two new terminal windows:
Terminal 1 - Backend
cd backend npm run devTerminal 2 - Frontend
cd frontend npm run dev -
Open your browser
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000/api
To customize this template for your project:
-
Update Application Name
- Set
APP_NAMEinbackend/.env - Set
VITE_APP_NAMEinfrontend/.env
- Set
-
Update Database Name
- Change
your-project-nameinDATABASE_URLto your project name
- Change
-
Update package.json
- Change
name,description, and other fields in bothbackend/package.jsonandfrontend/package.json
- Change
-
Customize Branding
- Replace logo in
frontend/public/ - Update colors in Tailwind config if needed
- Modify page titles and descriptions
- Replace logo in
fullstack-auth-template/
├── backend/
│ ├── src/
│ │ ├── config/ # Configuration files
│ │ ├── controllers/ # Route controllers
│ │ ├── middleware/ # Express middleware
│ │ ├── models/ # Mongoose models
│ │ ├── routes/ # API routes
│ │ ├── services/ # Business logic
│ │ ├── utils/ # Utility functions
│ │ ├── validators/ # Input validation
│ │ └── server.ts # Entry point
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── api/ # API client
│ │ ├── components/ # React components
│ │ ├── hooks/ # Custom hooks
│ │ ├── pages/ # Page components
│ │ ├── store/ # State management
│ │ ├── utils/ # Utility functions
│ │ └── validators/ # Form validation
│ └── package.json
└── docs/ # Documentation
- React 18 - UI library
- TypeScript - Type safety
- Vite - Build tool
- Tailwind CSS - Styling
- React Router - Routing
- React Hook Form - Form handling
- Zod - Schema validation
- TanStack Query - Server state
- Zustand - Client state
- Axios - HTTP client
- Node.js - Runtime
- Express - Web framework
- TypeScript - Type safety
- MongoDB - Database
- Mongoose - ODM
- JWT - Authentication
- bcrypt - Password hashing
- Zod - Validation
- Winston - Logging
- Nodemailer - Email sending
# Backend tests
cd backend
npm test
npm run test:coverage# Build backend
cd backend
npm run build
# Build frontend
cd frontend
npm run buildMIT
Contributions are welcome! Feel free to open issues or submit pull requests.
Made with ❤️ using React, Express, and MongoDB