A production-ready authentication system built with Next.js, NestJS, and NATS microservices architecture.
# Clone the repository
git clone <repository-url>
cd <project-directory>
# Start everything with one command
docker-compose up -dThat's it! The entire application stack will be up and running:
- 🎨 Frontend: http://localhost:3001
- 🔧 Backend API: http://localhost:3000
- 📚 API Documentation: http://localhost:3000/api/docs
- 📊 NATS Monitoring: http://localhost:8222
Monorepo Structure:
- Frontend: Next.js 16 + React 19 + TypeScript + Tailwind CSS
- Backend: NestJS 11 + MongoDB + JWT Authentication
- Microservices: NATS message broker for service communication
- Cache: Redis for session management
- Database: MongoDB for data persistence
All services are containerized and orchestrated with Docker Compose.
- 🔐 Complete JWT-based authentication (register, login, protected routes)
- 🎨 Modern UI with dark/light mode support
- 🚀 Microservices architecture with NATS
- ⚡ Redis caching for optimal performance
- 📱 Responsive design with Tailwind CSS v4
- 🧪 Comprehensive test coverage
- 📖 Auto-generated API documentation (Swagger/OpenAPI)
- 🔒 Production-ready security (HTTP-only cookies, bcrypt hashing, CORS)
- Docker & Docker Compose
- Node.js 20+ (for local development only)
- pnpm (for local development only)
Backend Tests:
cd apps/server
pnpm install
pnpm test # Unit tests
pnpm test:watch # Watch mode
pnpm test:cov # Coverage reportFrontend Tests:
cd apps/client
pnpm install
pnpm test # All tests
pnpm test:watch # Watch mode
pnpm test:coverage # Coverage report- API Documentation: http://localhost:3000/api/docs (Interactive Swagger UI)
- Available Endpoints:
POST /auth/register- Register new userPOST /auth/login- Login userGET /user/me- Get current user (authenticated)
If you prefer to run services locally:
1. Start Infrastructure:
docker-compose up mongodb redis nats -d2. Configure Environment:
apps/server/.env:
NODE_ENV=development
PORT=3000
MONGODB_URI_DEV=mongodb://localhost:27017/app-db
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=7d
SALT_ROUNDS=10
NATS_URLS=nats://localhost:4222apps/client/.env.local:
NODE_ENV=development
PORT=3001
AUTH_COOKIE_NAME=auth_token
NATS_URLS=nats://localhost:4222
REDIS_URL=redis://localhost:63793. Run Applications:
# Terminal 1 - Backend
cd apps/server && pnpm install && pnpm start:dev
# Terminal 2 - Frontend
cd apps/client && pnpm install && pnpm dev.
├── apps/
│ ├── client/ # Next.js frontend
│ │ ├── app/ # App router pages
│ │ ├── components/ # React components (atomic design)
│ │ ├── lib/ # Utils, types, state management
│ │ └── __tests__/ # Test files
│ │
│ └── server/ # NestJS backend
│ ├── src/
│ │ ├── auth/ # Authentication module
│ │ ├── user/ # User management
│ │ └── utils/ # Helpers
│ └── test/ # E2E tests
│
├── docker-compose.yml # Production setup
└── docker-compose.dev.yml # Development setup
- User registers/logs in → Server validates credentials
- JWT token generated and stored in HTTP-only cookie
- Token cached in Redis with user data
- Subsequent requests include token for authentication
- Middleware validates token and retrieves user data
NATS message patterns:
auth.register- User registrationauth.login- User authenticationuser.getOwnData- Fetch user profile
- ✅ JWT tokens with configurable expiration
- ✅ bcrypt password hashing
- ✅ HTTP-only cookies (XSS protection)
- ✅ CORS configuration
- ✅ Environment-based secrets
- ✅ Input validation (client + server)
- ✅ Protected API routes with guards
# Stop all services
docker-compose down
# Remove all data (fresh start)
docker-compose down -v| Layer | Technology |
|---|---|
| Frontend | Next.js 16, React 19, TypeScript, Tailwind CSS v4 |
| Backend | NestJS 11, MongoDB, Mongoose |
| Authentication | JWT, bcrypt |
| Microservices | NATS 2.10 |
| Cache | Redis 7 |
| Database | MongoDB 7 |
| Testing | Jest, React Testing Library, Supertest |
| UI Components | shadcn/ui, Radix UI, Lucide Icons |
| State Management | Zustand, React Hook Form |
| Validation | Yup, class-validator |
Ready to build? Just run docker-compose up and start developing! 🚀