A full-stack application featuring a secure, scalable backend API with JWT authentication, role-based access control, and a React frontend for task management.
- β User registration & login with JWT authentication
- β Password hashing using bcrypt
- β Role-based access control (User & Admin)
- β CRUD operations for Tasks entity
- β API versioning (v1)
- β Comprehensive error handling & validation
- β Swagger API documentation
- β MongoDB database with Mongoose ODM
- β Security features (Helmet, CORS, Rate Limiting)
- β Request logging with Morgan
- β React.js with Vite
- β User authentication (Register/Login)
- β Protected routes with JWT
- β Task management dashboard
- β CRUD operations for tasks
- β Responsive UI design
- β Real-time error/success messages
- Node.js (v16 or higher)
- MongoDB Atlas account (or local MongoDB)
- npm or yarn package manager
git clone <your-repo-url>
cd primetradecd backend
npm installCreate a .env file in the backend directory:
PORT=5000
MONGODB_URI=mongodb+srv://harshtanishq2002_db_user:FcHAClWNONYHvetB@cluster0.w86isu1.mongodb.net/primetrade?retryWrites=true&w=majority
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production_12345
JWT_EXPIRE=7d
NODE_ENV=developmentStart the backend server:
npm run devThe server will start at http://localhost:5000
Swagger documentation will be available at http://localhost:5000/api-docs
cd frontend
npm installCreate a .env file in the frontend directory:
VITE_API_URL=http://localhost:5000/api/v1Start the frontend development server:
npm run devThe frontend will start at http://localhost:5173
Once the backend is running, access the Swagger documentation at:
http://localhost:5000/api-docs
POST /register- Register a new userPOST /login- Login userGET /me- Get current user (Protected)PUT /profile- Update user profile (Protected)
GET /tasks- Get all tasks (Protected)GET /tasks/:id- Get single task (Protected)POST /tasks- Create new task (Protected)PUT /tasks/:id- Update task (Protected)DELETE /tasks/:id- Delete task (Protected)GET /tasks/stats- Get task statistics (Admin only)
{
name: String,
email: String (unique),
password: String (hashed),
role: String (enum: ['user', 'admin']),
isActive: Boolean,
createdAt: Date,
updatedAt: Date
}{
title: String,
description: String,
status: String (enum: ['pending', 'in-progress', 'completed']),
priority: String (enum: ['low', 'medium', 'high']),
dueDate: Date,
user: ObjectId (ref: User),
createdAt: Date,
updatedAt: Date
}- JWT Authentication - Secure token-based authentication
- Password Hashing - bcrypt with salt rounds
- Input Validation - express-validator for request validation
- Rate Limiting - Prevent brute force attacks (100 requests per 10 minutes)
- Helmet - Security headers
- CORS - Cross-Origin Resource Sharing configuration
- Role-Based Access - User and Admin roles with different permissions
primetrade/
βββ backend/
β βββ config/
β β βββ database.js
β β βββ swagger.js
β βββ controllers/
β β βββ authController.js
β β βββ taskController.js
β βββ middleware/
β β βββ auth.js
β β βββ errorHandler.js
β β βββ validator.js
β βββ models/
β β βββ User.js
β β βββ Task.js
β βββ routes/
β β βββ authRoutes.js
β β βββ taskRoutes.js
β βββ utils/
β β βββ generateToken.js
β β βββ responseHandler.js
β βββ .env
β βββ .gitignore
β βββ package.json
β βββ server.js
β
βββ frontend/
βββ src/
β βββ components/
β β βββ Login.jsx
β β βββ Register.jsx
β β βββ Dashboard.jsx
β β βββ PrivateRoute.jsx
β β βββ Auth.css
β β βββ Dashboard.css
β βββ services/
β β βββ authService.js
β β βββ taskService.js
β βββ utils/
β β βββ api.js
β βββ App.jsx
β βββ App.css
β βββ main.jsx
β βββ index.css
βββ .env
βββ package.json
βββ vite.config.js
- Register a new user at
http://localhost:5173/register - Login with credentials
- Create, view, update, and delete tasks
- Filter tasks by status
- Logout when done
- Go to
http://localhost:5000/api-docs - Test each endpoint
- Use the "Authorize" button to add JWT token
Import the API endpoints and test each route with proper authentication headers.
- Modular Architecture - Separated concerns (routes, controllers, models, middleware)
- API Versioning - Prepared for future API changes without breaking existing clients
- Database Indexing - Indexes on frequently queried fields for better performance
- Error Handling - Centralized error handling for consistency
- Input Validation - Prevents invalid data from reaching the database
- Separate authentication service
- Dedicated task management service
- User management service
- API Gateway for routing
- Redis for session management
- Cache frequently accessed data
- Reduce database load
// Example Redis implementation
import redis from "redis";
const client = redis.createClient();
// Cache user data
await client.set(`user:${userId}`, JSON.stringify(userData), "EX", 3600);- Sharding - Distribute data across multiple databases
- Read Replicas - Separate read and write operations
- Connection Pooling - Reuse database connections
- Use NGINX or AWS ELB
- Distribute traffic across multiple server instances
- Auto-scaling based on demand
- RabbitMQ or Apache Kafka for async processing
- Background jobs for email notifications
- Task processing queues
- CloudFlare or AWS CloudFront for static assets
- Reduce latency for global users
- ELK Stack (Elasticsearch, Logstash, Kibana)
- Prometheus + Grafana for metrics
- Sentry for error tracking
- Docker for containerization
- Kubernetes for orchestration
- CI/CD pipeline with GitHub Actions
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 5000
CMD ["node", "server.js"]FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]-
Database Queries
- Use projection to fetch only required fields
- Implement pagination for large datasets
- Use aggregation pipelines efficiently
-
API Response
- Compress responses with gzip
- Implement response caching
- Use ETags for conditional requests
-
Code Optimization
- Use async/await properly
- Avoid blocking operations
- Implement connection pooling
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
This project is licensed under the ISC License.
Harsh Tanishq
- Email: support@primetrade.com
- Express.js for the backend framework
- React.js for the frontend
- MongoDB for the database
- JWT for authentication
- Swagger for API documentation
Note: This is an intern assignment project demonstrating scalable backend development with authentication, role-based access, and a functional frontend UI.