Skip to content

Skg58/PrimeTrade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ PrimeTrade Assignment

A full-stack Task Management Application featuring a scalable REST API with JWT Authentication, Role-Based Access Control (RBAC), and a modern Next.js frontend.

Repository: https://github.com/skg58/primetrade-assignment


πŸ“‹ Table of Contents


πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js    β”‚  HTTP  β”‚   Express    β”‚  Query  β”‚   MongoDB    β”‚
β”‚   Frontend   │◄──────►│   Backend    │◄──────►│   Database   β”‚
β”‚  (Port 3000) β”‚  REST  β”‚  (Port 8000) β”‚  ODM   β”‚  (Port 27017)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚                        β”‚
     β”‚ TailwindCSS            β”‚ JWT / bcrypt / Zod
     β”‚ React Context          β”‚ Helmet / CORS / Rate Limit

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Node.js + Express.js Server & API framework
TypeScript Type safety
MongoDB + Mongoose Database & ODM
JWT (jsonwebtoken) Authentication tokens
bcrypt Password hashing
Zod Request validation
Helmet + CORS + Rate Limiter API security

Frontend

Technology Purpose
Next.js 14 (App Router) React framework
TypeScript Type safety
TailwindCSS Utility-first styling
Axios HTTP client
React Hot Toast Notifications
Lucide React Icons

πŸš€ Getting Started

Prerequisites

  • Node.js >= 18.x
  • MongoDB >= 6.x (running locally or MongoDB Atlas)
  • npm >= 9.x

Clone the Repository

git clone https://github.com/skg58/primetrade-assignment.git
cd primetrade-assignment

βš™οΈ Backend Setup

# Navigate to backend
cd backend

# Install dependencies
npm install

# Configure environment (edit .env as needed)
# The .env file is pre-configured for local development

# Start development server
npm run dev

The backend will start on http://localhost:8000

Build for Production

npm run build
npm start

🎨 Frontend Setup

# Navigate to frontend (from project root)
cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

The frontend will start on http://localhost:3000

Build for Production

npm run build
npm start

πŸ“‘ API Documentation

Base URL: http://localhost:8000/api/v1

Authentication Endpoints

Method Endpoint Description Auth Required
POST /auth/register Register new user ❌
POST /auth/login Login & get JWT ❌
POST /auth/logout Logout & clear cookie βœ…
GET /auth/me Get current user profile βœ…

Task Endpoints

Method Endpoint Description Auth Required
POST /tasks Create a new task βœ…
GET /tasks Get all tasks (paginated) βœ…
GET /tasks/:id Get task by ID βœ…
PUT /tasks/:id Update a task βœ…
DELETE /tasks/:id Delete a task βœ…

Query Parameters (GET /tasks)

Parameter Type Default Options
page number 1 Any positive integer
limit number 10 1-50
status string β€” todo, in_progress, done
priority string β€” low, medium, high
search string β€” Free text search
sortBy string createdAt createdAt, title, status, priority, dueDate
sortOrder string desc asc, desc

Full OpenAPI 3.0 specification available in backend/swagger.yaml


πŸ“ Project Structure

primetrade-assignment/
β”œβ”€β”€ backend/                    # Express.js REST API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/        # Route handlers
β”‚   β”‚   β”œβ”€β”€ database/           # MongoDB connection
β”‚   β”‚   β”œβ”€β”€ middleware/         # Auth, RBAC, validation, error handling
β”‚   β”‚   β”œβ”€β”€ models/             # Mongoose schemas
β”‚   β”‚   β”œβ”€β”€ routes/             # Express routers
β”‚   β”‚   β”œβ”€β”€ type/               # TypeScript interfaces
β”‚   β”‚   β”œβ”€β”€ utils/              # Helpers (ApiError, ApiResponse, etc.)
β”‚   β”‚   β”œβ”€β”€ app.ts              # Express configuration
β”‚   β”‚   β”œβ”€β”€ constants.ts        # App-wide constants
β”‚   β”‚   └── index.ts            # Server entry point
β”‚   β”œβ”€β”€ .env                    # Environment variables
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ swagger.yaml            # API documentation
β”‚   └── tsconfig.json
β”‚
β”œβ”€β”€ frontend/                   # Next.js Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                # App Router pages
β”‚   β”‚   β”‚   β”œβ”€β”€ (auth)/         # Login & Register pages
β”‚   β”‚   β”‚   └── dashboard/      # Protected dashboard pages
β”‚   β”‚   β”œβ”€β”€ components/         # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ layout/         # Sidebar, Header, DashboardLayout
β”‚   β”‚   β”‚   β”œβ”€β”€ tasks/          # TaskCard, TaskForm, TaskList, TaskFilters
β”‚   β”‚   β”‚   └── ui/             # Button, Input, Modal, Badge, etc.
β”‚   β”‚   β”œβ”€β”€ context/            # React AuthContext
β”‚   β”‚   β”œβ”€β”€ lib/                # Axios instance, auth helpers
β”‚   β”‚   └── types/              # TypeScript interfaces
β”‚   β”œβ”€β”€ .env.local
β”‚   β”œβ”€β”€ package.json
β”‚   └── tailwind.config.ts
β”‚
β”œβ”€β”€ README.md                   # This file
└── SCALABILITY.md              # Scalability architecture notes

✨ Features

Backend

  • βœ… RESTful API with versioning (/api/v1/)
  • βœ… JWT Authentication (Bearer token + httpOnly cookies)
  • βœ… Role-Based Access Control (User & Admin roles)
  • βœ… Zod input validation
  • βœ… bcrypt password hashing (10 salt rounds)
  • βœ… Standardized API responses (ApiResponse / ApiError)
  • βœ… Global error handling middleware
  • βœ… Pagination, search, filtering, and sorting
  • βœ… Rate limiting & security headers (Helmet)
  • βœ… MongoDB compound indexes for performance

Frontend

  • βœ… Modern dark UI with glassmorphism effects
  • βœ… Responsive design (mobile + desktop)
  • βœ… Auth context with persistent sessions
  • βœ… Protected routes with auth gate
  • βœ… Full CRUD operations for tasks
  • βœ… Real-time search with debouncing
  • βœ… Toast notifications for API feedback
  • βœ… Animated dashboard with stat cards
  • βœ… Collapsible sidebar navigation

πŸ” Environment Variables

Backend (.env)

Variable Default Description
PORT 8000 Server port
MONGODB_URI mongodb://127.0.0.1:27017/primetrade_db MongoDB connection
JWT_SECRET β€” JWT signing secret
JWT_EXPIRES_IN 7d Token expiration
CORS_ORIGIN http://localhost:3000 Allowed CORS origin
NODE_ENV development Environment

Frontend (.env.local)

Variable Default Description
NEXT_PUBLIC_API_URL http://localhost:8000/api/v1 Backend API URL

πŸ“œ License

ISC


Built with ❀️ for the PrimeTrade Backend Developer Intern Assignment.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors