A modern, scalable, and secure task management application built with Next.js (frontend) and Node.js/Express (backend) featuring JWT-based authentication, CRUD operations, and responsive design.
.
├── frontend/ # Next.js frontend application
│ ├── app/ # Next.js app directory
│ │ ├── dashboard/ # Dashboard page (protected)
│ │ ├── login/ # Login page
│ │ ├── signup/ # Signup page
│ │ ├── globals.css # Global styles
│ │ ├── layout.tsx # Root layout with AuthProvider
│ │ └── page.tsx # Home page
│ ├── components/ # Reusable React components
│ │ ├── Navbar.tsx # Navigation bar
│ │ └── ProtectedRoute.tsx # Route protection wrapper
│ ├── lib/ # Utility functions
│ │ ├── api.ts # Axios instance with interceptors
│ │ └── AuthContext.tsx # Authentication context
│ ├── types/ # TypeScript type definitions
│ │ └── index.ts
│ └── package.json
│
├── backend/ # Express backend application
│ ├── config/ # Configuration files
│ │ └── db.js # MongoDB connection
│ ├── middleware/ # Express middleware
│ │ ├── auth.js # JWT authentication middleware
│ │ └── errorHandler.js # Error handling middleware
│ ├── models/ # Mongoose models
│ │ ├── User.js # User model with password hashing
│ │ └── Task.js # Task model
│ ├── routes/ # API routes
│ │ ├── auth.js # Authentication routes
│ │ └── tasks.js # Task CRUD routes
│ ├── utils/ # Utility functions
│ │ └── generateToken.js # JWT token generation
│ ├── .env # Environment variables
│ ├── server.js # Express server entry point
│ └── package.json
│
├── API_DOCUMENTATION.md # Complete API documentation
├── Task_Manager_API.postman_collection.json # Postman collection
└── README.md # This file
git clone <repository-url>
cd task-manager
cd backend
npm install
Create a .env file in the backend directory:
PORT=5000
MONGODB_URI=mongodb://localhost:27017/taskmanager
JWT_SECRET=your_jwt_secret_key_here_change_in_production
NODE_ENV=development
Important: Change the JWT_SECRET to a strong, random string in production.
cd frontend
npm install
Create a .env.local file in the frontend directory:
NEXT_PUBLIC_API_URL=http://localhost:5000/api
Make sure MongoDB is running on your system:
# For Windows (if installed as service)
net start MongoDB
# For macOS/Linux
mongod
# Or using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest
Backend (Terminal 1):
cd backend
npm run dev
The backend server will start on http://localhost:5000
Frontend (Terminal 2):
cd frontend
npm run dev
The frontend application will start on http://localhost:3000
Open your browser and navigate to http://localhost:3000
POST /api/auth/signup - Register new userPOST /api/auth/login - Login userGET /api/auth/profile - Get user profile (protected)PUT /api/auth/profile - Update user profile (protected)GET /api/tasks - Get all tasks with filters (protected)GET /api/tasks/:id - Get single task (protected)POST /api/tasks - Create task (protected)PUT /api/tasks/:id - Update task (protected)DELETE /api/tasks/:id - Delete task (protected)For detailed API documentation, see API_DOCUMENTATION.md
Task_Manager_API.postman_collection.json into PostmanThe application is built with scalability in mind using modular architecture and best practices.
Current Setup:
Production Improvements:
Example:
// Add React Query for caching
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 10 * 60 * 1000, // 10 minutes
},
},
});
Current Setup:
Production Improvements:
Horizontal Scaling:
pm2 start server.js -i max
Database Scaling:
Caching Layer:
// Cache frequent queries
app.get(‘/api/tasks’, async (req, res) => {
const cacheKey = tasks:${req.user._id};
const cached = await client.get(cacheKey);
if (cached) { return res.json(JSON.parse(cached)); }
const tasks = await Task.find({ user: req.user._id }); await client.setEx(cacheKey, 300, JSON.stringify(tasks)); // 5 min cache res.json(tasks); });
**API Gateway:**
- Implement **rate limiting** to prevent abuse
- Add **API versioning** for backward compatibility
- Use **GraphQL** for flexible data fetching (future enhancement)
#### 3. **Database Optimization**
**Indexing Strategy:**
```javascript
// Already implemented in Task model
taskSchema.index({ user: 1, status: 1 });
taskSchema.index({ user: 1, createdAt: -1 });
// Additional indexes for production
taskSchema.index({ user: 1, priority: 1 });
taskSchema.index({ title: 'text', description: 'text' }); // Full-text search
Connection Pooling:
mongoose.connect(process.env.MONGODB_URI, {
maxPoolSize: 50,
minPoolSize: 10,
serverSelectionTimeoutMS: 5000,
});
Current: Basic JWT authentication and bcrypt hashing
Production Additions:
Example:
const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
app.use(helmet());
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
});
app.use('/api/', limiter);
Production Requirements:
Example:
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
Recommended Setup:
Example GitHub Actions:
name: CI/CD
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: npm test
- name: Deploy
run: npm run deploy
For very large scale:
Current Setup:
With Optimizations:
npm start # Start production server
npm run dev # Start development server with nodemon
npm run dev # Start development server
npm run build # Build for production
npm start # Start production server
npm run lint # Run ESLint
PORT=5000
MONGODB_URI=mongodb://localhost:27017/taskmanager
JWT_SECRET=your_secret_key
NODE_ENV=development
NEXT_PUBLIC_API_URL=http://localhost:5000/api
MIT License
Created for Frontend Developer Intern Assignment
# Install all dependencies
cd backend && npm install && cd ../frontend && npm install && cd ..
# Start MongoDB (if not running)
mongod
# Start backend (in one terminal)
cd backend && npm run dev
# Start frontend (in another terminal)
cd frontend && npm run dev
Visit http://localhost:3000 to see the application!