A complete MongoDB, Express, React, Node.js (MERN) stack application featuring JWT-based authentication and containerized deployment with Docker.
.
├── backend/ # Node.js + Express server
│ ├── config/
│ │ └── database.js # MongoDB connection
│ ├── middleware/
│ │ └── auth.js # JWT authentication middleware
│ ├── models/
│ │ └── User.js # User schema
│ ├── routes/
│ │ ├── auth.js # Register & login endpoints
│ │ └── protected.js # Protected routes (profile, etc.)
│ ├── Dockerfile
│ ├── server.js
│ └── package.json
├── frontend/ # React app (Vite)
│ ├── src/
│ │ ├── pages/
│ │ │ ├── Login.jsx
│ │ │ ├── Register.jsx
│ │ │ └── Dashboard.jsx
│ │ ├── services/
│ │ │ └── authService.js # Axios + API calls
│ │ ├── styles/
│ │ │ ├── Auth.css
│ │ │ └── Dashboard.css
│ │ ├── App.jsx
│ │ ├── main.jsx
│ │ └── index.css
│ ├── Dockerfile
│ ├── vite.config.js
│ └── package.json
└── docker-compose.yml # Orchestrate all services
- Docker & Docker Compose installed
- Node.js 18+ (for local development without Docker)
- npm or yarn
cd /path/to/Zeitgeistdocker-compose up --buildThis will:
- Build the backend Docker image
- Build the frontend Docker image
- Connect backend to your existing MongoDB instance
- Start backend server (port 5000)
- Start frontend application (port 3000)
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- MongoDB: existing instance specified by
MONGODB_URI
cd backend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Update MONGODB_URI in .env for local MongoDB
# MONGODB_URI=mongodb://localhost:27017/mern-auth
# Start development server
npm run dev
# or npm start for productioncd frontend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Keep VITE_API_URL as http://localhost:5000/api
# Start development server
npm run dev-
POST /api/auth/register- Register new user{ "username": "john_doe", "email": "john@example.com", "password": "securepassword" } -
POST /api/auth/login- Login user{ "email": "john@example.com", "password": "securepassword" }
GET /api/protected/profile- Get user profile (requires JWT token)- Header:
Authorization: Bearer <token>
- Header:
✅ User Registration with validation ✅ JWT-based Authentication ✅ Protected Routes ✅ Secure Password Hashing (bcrypt) ✅ MongoDB Integration ✅ React Router Navigation ✅ Axios HTTP Client with Interceptors ✅ Responsive UI Design ✅ Docker Containerization ✅ Docker Compose Orchestration ✅ Health Checks ✅ Development & Production Ready
MONGODB_URI=mongodb://host.docker.internal:27017/mern-auth
JWT_SECRET=your_jwt_secret_key_change_this_in_production
JWT_EXPIRE=7d
PORT=5000
NODE_ENV=production
CLIENT_URL=http://localhost:3000VITE_API_URL=http://localhost:5000/api- Update
.envvariables with production values - Update
JWT_SECRETto a strong random string - Run:
docker-compose -f docker-compose.yml up -d
- Change
JWT_SECRETto secure random value - Set
NODE_ENV=productionin backend - Update
CLIENT_URLfor frontend domain - Configure MongoDB with proper authentication
- Set up SSL/TLS certificates
- Configure environment variables for production
# Build and start all services
docker-compose up --build
# Start services (if already built)
docker-compose up
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# View logs for specific service
docker-compose logs -f backend
docker-compose logs -f frontend
# Rebuild specific service
docker-compose up --build backend
# Stop services
docker-compose down- Frontend: React 18, Vite, React Router, Axios
- Backend: Node.js, Express, Mongoose
- Database: MongoDB
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcryptjs
- Containerization: Docker, Docker Compose
- Passwords are hashed using bcryptjs with 10 salt rounds
- JWT tokens expire after 7 days (configurable)
- CORS is enabled for frontend communication
- Protected routes require valid JWT token
- Input validation using express-validator
- Ensure MongoDB container is running:
docker-compose logs mongodb - Check MongoDB credentials in docker-compose.yml
- Change ports in docker-compose.yml
- Or kill process using the port:
lsof -i :5000/kill -9 <PID>
- Check VITE_API_URL in frontend/.env
- Ensure backend service is running:
docker-compose ps - Check network connectivity:
docker network ls
- Hot Reload: Frontend uses Vite (automatic hot reload on save)
- Backend Reload: Use
npm run devfor nodemon - Database Persistence: MongoDB data is stored in
mongodb_datavolume - Logs: Use
docker-compose logs -fto debug
- Add refresh token mechanism
- Implement role-based access control (RBAC)
- Add email verification
- Implement password reset functionality
- Add user profile editing
- Set up CI/CD pipeline
ISC
For issues or questions, check Docker Compose docs: