A full-stack authentication system built with Laravel (Backend) and React + TypeScript (Frontend).
auth-system/
├── backend/ # Laravel API Backend
│ ├── app/ # Application logic
│ ├── database/ # Migrations, seeders, factories
│ ├── routes/ # API routes
│ ├── tests/ # Backend tests
│ └── ...
├── frontend/ # React + TypeScript Frontend
│ ├── src/ # Source code
│ ├── public/ # Static assets
│ ├── tests/ # Frontend tests
│ └── ...
└── README.md # This file
- PHP: ^8.2
- Composer: Latest version
- Node.js: ^18.0 (for asset compilation)
- NPM/Yarn: For frontend dependencies
- Database: SQLite (included) or MySQL/PostgreSQL
- Node.js: ^18.0
- NPM/Yarn: Package manager
For a fast setup, run these commands in sequence:
# 1. Setup Backend
cd backend
composer install
cp .env.example .env
php artisan key:generate
touch database/database.sqlite
php artisan migrate
npm install && npm run build
# 2. Setup Frontend (in a new terminal)
cd ../frontend
npm install
# 3. Start Backend Server
cd ../backend
php artisan serve
# 4. Start Frontend Server (in another terminal)
cd frontend
npm run devYour application will be available at:
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
-
Navigate to the backend directory:
cd backend -
Install PHP dependencies:
composer install
-
Environment Configuration:
# Copy environment file cp .env.example .env # Generate application key php artisan key:generate
-
Database Setup:
# Create SQLite database (if not exists) touch database/database.sqlite # Run migrations php artisan migrate
-
Install Node.js dependencies for asset compilation:
npm install
-
Build frontend assets:
npm run build
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
Option 1: Simple Laravel Server
cd backend
php artisan serveThe API will be available at: http://localhost:8000
Option 2: Full Development Environment (Recommended)
cd backend
composer run devThis command runs:
- Laravel server (
http://localhost:8000) - Queue worker
- Log monitoring
- Asset compilation with hot reload
cd frontend
npm run devThe frontend will be available at: http://localhost:5173
Terminal 1 (Backend):
cd backend
php artisan serveTerminal 2 (Frontend):
cd frontend
npm run devThe backend provides the following authentication endpoints:
POST /api/register- User registrationPOST /api/login- User loginPOST /api/logout- User logoutGET /api/user- Get authenticated userPUT /api/profile- Update user profilePOST /api/password/change- Change passwordPOST /api/password/email- Request password resetPOST /api/password/reset- Reset passwordPOST /api/email/verify- Verify email address
cd backend
# Run all tests
php artisan test
# Run specific test suites
php artisan test --testsuite=Feature # Feature tests
php artisan test --testsuite=Unit # Unit tests
# Run with coverage
php artisan test --coveragecd frontend
# Run tests
npm run test
# Run tests with UI
npm run test:ui
# Run tests with coverage
npm run test:coverageKey environment variables for the backend:
APP_NAME="Authentication System"
APP_ENV=local
APP_KEY=base64:your-generated-key
APP_DEBUG=true
APP_URL=http://localhost:8000
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
MAIL_MAILER=logCreate a .env file in the frontend directory:
VITE_API_URL=http://localhost:8000
VITE_APP_NAME="Authentication System"- ✅ User registration with validation
- ✅ User login with rate limiting
- ✅ User logout and session management
- ✅ Profile updates and management
- ✅ Password changes with security checks
- ✅ Password reset with email notifications
- ✅ Email verification with secure links
- ✅ Rate limiting on all endpoints
- ✅ CSRF protection
- ✅ Password strength validation
- ✅ Email uniqueness validation
- ✅ Session regeneration
- ✅ Token-based authentication
- ✅ Route accessibility
- ✅ Authentication requirements
- ✅ JSON response format
- ✅ CORS handling
- ✅ Error handling
- ✅ Rate limiting
- ✅ Required field validation
- ✅ Format validation (email, password)
- ✅ Length validation
- ✅ Uniqueness validation
- ✅ Type validation
- ✅ Special character handling
-
Permission Issues (Linux/Mac):
chmod -R 755 storage bootstrap/cache
-
Composer Memory Limit:
php -d memory_limit=-1 /usr/local/bin/composer install
-
Node.js Version Issues:
# Use Node Version Manager nvm use 18 -
Database Connection Issues:
- Ensure SQLite file exists:
touch database/database.sqlite - Check file permissions
- Verify .env configuration
- Ensure SQLite file exists:
cd backend
# Install production dependencies
composer install --optimize-autoloader --no-dev
# Generate optimized autoloader
composer dump-autoload --optimize
# Cache configuration
php artisan config:cache
# Cache routes
php artisan route:cache
# Cache views
php artisan view:cache
# Run migrations
php artisan migrate --forcecd frontend
# Install dependencies
npm ci
# Build for production
npm run build- Laravel 12 - PHP Framework
- Laravel Sanctum - API Authentication
- SQLite - Database (can be changed to MySQL/PostgreSQL)
- PHPUnit - Testing Framework
- React 19 - UI Framework
- TypeScript - Type Safety
- Vite - Build Tool
- Bootstrap 5 - CSS Framework
- React Router - Client-side Routing
- Axios - HTTP Client
- React Hook Form - Form Management
- Zod - Schema Validation
- Vitest - Testing Framework
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.