Primetrade

Task Manager - Full Stack Web Application

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.

Features

Frontend

Backend

Security Features

Project Structure

.
├── 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

Prerequisites

Installation & Setup

1. Clone the Repository

git clone <repository-url>
cd task-manager

2. Backend Setup

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.

3. Frontend Setup

cd frontend
npm install

Create a .env.local file in the frontend directory:

NEXT_PUBLIC_API_URL=http://localhost:5000/api

4. Start MongoDB

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

5. Run the Application

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

6. Access the Application

Open your browser and navigate to http://localhost:3000

  1. Sign Up: Create a new account
  2. Login: Sign in with your credentials
  3. Dashboard: Manage your tasks

API Endpoints

Authentication

Tasks

For detailed API documentation, see API_DOCUMENTATION.md

Testing with Postman

  1. Import Task_Manager_API.postman_collection.json into Postman
  2. The collection includes all API endpoints with example requests
  3. After login/signup, the auth token is automatically saved to variables
  4. All protected routes use the saved token automatically

Features Demonstration

1. Authentication Flow

2. Task Management

3. Search and Filtering

4. User Profile

Scalability Notes

Current Architecture

The application is built with scalability in mind using modular architecture and best practices.

Scaling for Production

1. Frontend Scaling

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
    },
  },
});

2. Backend Scaling

Current Setup:

Production Improvements:

Horizontal Scaling:

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,
});

4. Security Enhancements

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);

5. Monitoring and Logging

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' })
  ]
});

6. CI/CD Pipeline

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

7. Microservices Architecture (Future)

For very large scale:

8. Performance Optimization

Estimated Capacity

Current Setup:

With Optimizations:

Development Scripts

Backend

npm start       # Start production server
npm run dev     # Start development server with nodemon

Frontend

npm run dev     # Start development server
npm run build   # Build for production
npm start       # Start production server
npm run lint    # Run ESLint

Environment Variables

Backend (.env)

PORT=5000
MONGODB_URI=mongodb://localhost:27017/taskmanager
JWT_SECRET=your_secret_key
NODE_ENV=development

Frontend (.env.local)

NEXT_PUBLIC_API_URL=http://localhost:5000/api

Technologies Used

Frontend

Backend

License

MIT License

Author

Created for Frontend Developer Intern Assignment


Quick Start Commands

# 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!