A robust REST API built with NestJS and TypeORM for managing products, authentication, and real-time messaging with WebSockets.
Artisan API is a production-ready backend service that provides:
- π JWT Authentication with secure password hashing
- π¦ Product Management with full CRUD operations
- π Role-based Access Control (RBAC)
- π€ File Upload Management with static file serving
- π¬ Real-time Messaging with WebSocket support
- π PostgreSQL Database integration
- β Data Validation with class-validator
- π Comprehensive Testing (unit & e2e tests)
- User registration and login
- JWT token generation and validation
- Password encryption with bcrypt
- Role-based access control
- List, create, update, and delete products
- Product search and filtering
- Product images/files management
- Seed data for development
- WebSocket support for live messaging
- Socket.IO integration
- Real-time notifications
- File upload handling
- Static file serving
- Product image storage
| Category | Technology |
|---|---|
| Framework | NestJS 9 |
| Language | TypeScript 4.7 |
| Database | PostgreSQL 14+ |
| ORM | TypeORM |
| Authentication | JWT + Passport |
| WebSockets | Socket.IO |
| Validation | Class-validator |
| Testing | Jest |
| Package Manager | npm |
- Node.js 16+
- npm or yarn
- PostgreSQL 14+
- Docker (optional, for PostgreSQL via docker-compose)
# Clone the repository
git clone <repository-url>
cd artisan-api
# Install dependencies
npm install
# Create environment variables file
cp .env.example .env
# Update .env with your database credentials
# Example:
# DB_HOST=localhost
# DB_PORT=5432
# DB_USERNAME=postgres
# DB_PASSWORD=your_password
# DB_NAME=artisan_db
# JWT_SECRET=your_jwt_secretnpm run start:devThe API will run on http://localhost:3000
npm run build
npm run start:prod# Start PostgreSQL container
docker-compose up -d
# Run migrations and start app
npm run start:dev# Development
npm run start:dev # Start with watch mode
npm run start:debug # Start with debugger
npm run start # Start production-like mode
# Building
npm run build # Build for production
npm run prebuild # Clean dist folder
# Testing
npm run test # Run unit tests
npm run test:watch # Run tests in watch mode
npm run test:cov # Generate coverage report
npm run test:e2e # Run end-to-end tests
# Code Quality
npm run lint # Run ESLint with auto-fix
npm run format # Format code with Prettiersrc/
βββ auth/ # Authentication & Authorization
β βββ strategies/ # JWT & Passport strategies
β βββ guards/ # Auth guards
β βββ decorators/ # Custom decorators
βββ products/ # Product management
β βββ entities/ # Product models
β βββ dto/ # Data transfer objects
β βββ services/ # Business logic
βββ files/ # File management
β βββ controllers/ # File upload endpoints
β βββ services/ # File handling logic
βββ messages-ws/ # WebSocket messaging
β βββ gateways/ # Socket.IO gateways
β βββ services/ # Message logic
βββ common/ # Shared utilities
β βββ decorators/ # Custom decorators
β βββ guards/ # Common guards
β βββ pipes/ # Validation pipes
β βββ filters/ # Exception filters
βββ seed/ # Database seeding
βββ main.ts # Application entry point
The API uses JWT (JSON Web Tokens) with Passport.js:
- Register: Create a new user account
- Login: Get a JWT token
- Access Protected Routes: Use token in Authorization header
# Example request
curl -H "Authorization: Bearer <your_jwt_token>" \
http://localhost:3000/api/productsdocker-compose up -d# Create database
createdb artisan_db
# Run migrations
npm run typeorm migration:runnpm run seed# Unit tests
npm run test
# Watch mode
npm run test:watch
# Coverage report
npm run test:cov
# E2E tests
npm run test:e2eCreate a .env file in the root directory:
# Database
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_NAME=artisan_db
# JWT
JWT_SECRET=your_secret_key
JWT_EXPIRATION=3600
# File Upload
FILE_UPLOAD_PATH=./static/uploads
# Server
PORT=3000
NODE_ENV=developmentnpm run lintnpm run format- Verify PostgreSQL is running
- Check DATABASE_URL in .env
- Ensure database exists
- Verify JWT_SECRET in .env
- Check token format in Authorization header
- Ensure token hasn't expired
# Find and kill process on port 3000
lsof -ti:3000 | xargs kill -9MIT
Artisan Development Team
For issues and questions, please open an issue on GitHub.
Last Updated: November 2025