A robust REST API built with NestJS, PostgreSQL, Sequelize ORM, and Docker Compose. Features authentication and product management with Swagger documentation.
- 🚀 NestJS Framework - Scalable Node.js server-side applications
- 🐘 PostgreSQL Database - Reliable relational database
- 🔗 Sequelize ORM - Promise-based Node.js ORM
- 🐳 Docker Compose - Easy deployment and development
- 📚 Swagger Documentation - Interactive API documentation
- 🔐 JWT Authentication - Secure user authentication
- ✅ Input Validation - Request validation with class-validator
- 🛡️ Guards & Strategies - Passport.js integration
- POST
/auth/register
- Register new user - POST
/auth/login
- User login - GET
/auth/profile
- Get user profile (protected)
- POST
/products
- Create product (protected) - GET
/products
- Get all products (protected) - GET
/products/my-products
- Get current user's products (protected) - GET
/products/:id
- Get product by ID (protected) - PATCH
/products/:id
- Update product (protected, owner only) - DELETE
/products/:id
- Delete product (protected, owner only)
- Docker and Docker Compose
- Node.js 18+ (for local development)
-
Clone and setup
git clone <your-repo> cd nestjs-product-api cp .env.example .env
-
Start the application
docker-compose up -d
-
Access the application
- API: http://localhost:3000
- Swagger Documentation: http://localhost:3000/api
- PostgreSQL: localhost:5432
-
Install dependencies
npm install
-
Setup PostgreSQL database
# Start only PostgreSQL with Docker docker-compose up postgres -d
-
Configure environment
cp .env.example .env # Edit .env with your configuration
-
Start development server
npm run start:dev
Variable | Description | Default |
---|---|---|
DATABASE_HOST |
PostgreSQL host | localhost |
DATABASE_PORT |
PostgreSQL port | 5432 |
DATABASE_USER |
PostgreSQL username | postgres |
DATABASE_PASSWORD |
PostgreSQL password | password |
DATABASE_NAME |
PostgreSQL database name | nestjs_db |
JWT_SECRET |
JWT signing secret | your-secret-key-here |
PORT |
Application port | 3000 |
curl -X POST http://localhost:3000/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123",
"firstName": "John",
"lastName": "Doe"
}'
curl -X POST http://localhost:3000/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'
curl -X POST http://localhost:3000/products \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"name": "iPhone 14",
"description": "Latest iPhone",
"price": 999.99,
"stock": 50
}'
curl -X GET http://localhost:3000/products \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
id
- Primary keyemail
- Unique user emailpassword
- Hashed passwordfirstName
- User's first namelastName
- User's last namecreatedAt
- Creation timestampupdatedAt
- Update timestamp
id
- Primary keyname
- Product namedescription
- Product descriptionprice
- Product price (decimal)stock
- Stock quantityuserId
- Foreign key to users tablecreatedAt
- Creation timestampupdatedAt
- Update timestamp
src/
├── auth/
│ ├── dto/
│ │ ├── login.dto.ts
│ │ └── register.dto.ts
│ ├── entities/
│ │ └── user.entity.ts
│ ├── guards/
│ │ └── jwt-auth.guard.ts
│ ├── strategies/
│ │ ├── jwt.strategy.ts
│ │ └── local.strategy.ts
│ ├── auth.controller.ts
│ ├── auth.module.ts
│ └── auth.service.ts
├── product/
│ ├── dto/
│ │ ├── create-product.dto.ts
│ │ └── update-product.dto.ts
│ ├── entities/
│ │ └── product.entity.ts
│ ├── product.controller.ts
│ ├── product.module.ts
│ └── product.service.ts
├── app.module.ts
└── main.ts
# Development
npm run start:dev
# Build
npm run build
# Production
npm run start:prod
# Testing
npm run test
npm run test:watch
npm run test:cov
# Linting
npm run lint
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Rebuild and start
docker-compose up --build -d
# Reset database
docker-compose down -v
docker-compose up -d
- Password Hashing - bcryptjs for secure password storage
- JWT Authentication - Stateless authentication tokens
- Input Validation - class-validator for request validation
- Authorization Guards - Route protection with JWT guards
- CORS Enabled - Cross-origin resource sharing configured
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License.