- Overview
- System Architecture
- Project Setup
- API Documentation
- Database Models
- Authentication & Authorization
- Email Service
- Middleware
- Error Handling
- Utilities
A robust project management system built with Node.js and Express, featuring user authentication, project collaboration, task management, and real-time updates.
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens)
- Email Service: Nodemailer with Mailtrap
- File Upload: Multer
- Validation: Custom middleware
The application follows a modular MVC (Model-View-Controller) architecture:
src/
├── controllers/ # Business logic
├── models/ # Database schemas
├── routes/ # API routes
├── middlewares/ # Custom middlewares
├── utils/ # Helper functions
├── validators/ # Input validation
└── db/ # Database configuration
- Node.js (v21.x or higher)
- MongoDB
- npm or yarn
Create a .env file in the root directory with the following variables:
NODE_ENV=development
CORS_ORIGIN=http://localhost:3000
PORT=5000
FORGOT_PASSWORD_REDIRECT_URL=http://localhost:3000/reset-password
SERVER_URL=http://localhost:5000
MONGO_URI=your_mongodb_uri
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=15m
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REFRESH_TOKEN_EXPIRY=7d
SMTP_FROM_EMAIL=[email protected]
MAILTRAP_SMTP_HOST=smtp.mailtrap.io
MAILTRAP_SMTP_PORT=2525
MAILTRAP_SMTP_USER=your_mailtrap_user
MAILTRAP_SMTP_PASS=your_mailtrap_password- Clone the repository
- Install dependencies:
npm install - Set up environment variables
- Start development server:
npm run dev
Register a new user
- Body:
{ email, username, password } - Returns: User object with JWT tokens
Login existing user
- Body:
{ email, password } - Returns: User object with JWT tokens
Create new project
- Auth: Required
- Body:
{ name, description } - Returns: Project object
Get all user's projects
- Auth: Required
- Returns: Array of projects
Create new task
- Auth: Required
- Body:
{ title, description, projectId, dueDate } - Returns: Task object
Get project tasks
- Auth: Required
- Returns: Array of tasks
{
username: String,
email: String,
password: String,
refreshToken: String,
emailVerificationToken: String,
emailVerificationExpiry: Date,
isEmailVerified: Boolean
}{
name: String,
description: String,
owner: ObjectId,
members: [ObjectId],
tasks: [ObjectId],
createdAt: Date,
updatedAt: Date
}{
title: String,
description: String,
project: ObjectId,
assignedTo: ObjectId,
status: String,
priority: String,
dueDate: Date,
subtasks: [ObjectId]
}The system uses JWT-based authentication with refresh tokens:
- Access tokens expire in 15 minutes
- Refresh tokens expire in 7 days
- Email verification required for new accounts
- Password reset functionality available
Email notifications are handled by Nodemailer with Mailtrap integration:
- Email verification
- Password reset
- Project invitations
- Task assignments
- Verifies JWT tokens
- Handles token refresh
- Manages user sessions
- Input validation
- Request sanitization
- Error formatting
- Handles file uploads
- Validates file types
- Manages storage
Custom error handling using ApiError class:
- Standardized error responses
- HTTP status codes
- Error logging
- Development vs Production error details
Standardized API response format:
{
success: Boolean,
data: Object|Array|null,
message: String,
errors: Array
}Wrapper for async route handlers with unified error handling.
Email service utility with development and production modes.
- Password Hashing
- JWT Token Management
- Rate Limiting
- CORS Protection
- Input Validation
- XSS Prevention
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
MIT License