A robust RESTful API backend built with NestJS for managing listings, users, categories, and messages. This application provides a scalable foundation for a marketplace or listing platform.
- User Management: Create, read, update, and delete users
- Listings Management: Full CRUD operations for product/service listings
- Category System: Organize listings with categories
- Messaging System: User-to-user messaging functionality
- Rate Limiting: Built-in protection against API abuse (10 requests per 60 seconds)
- Input Validation: Automatic request validation using DTOs
- Error Handling: Comprehensive error handling with appropriate HTTP status codes
- Type Safety: Full TypeScript support with Prisma ORM
- Framework: NestJS (v11.0.1)
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Validation: class-validator, class-transformer
- Rate Limiting: @nestjs/throttler
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- npm or yarn
- PostgreSQL (v12 or higher)
- Prisma CLI (included as dev dependency)
-
Clone the repository
git clone <repository-url> cd Listly_Backend
-
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory:DATABASE_URL="postgresql://username:password@localhost:5432/listly_db?schema=public" PORT=4000
-
Set up the database
# Generate Prisma Client npx prisma generate # Run database migrations npx prisma migrate dev # (Optional) Seed the database npx prisma db seed
Start the application in watch mode (auto-reload on file changes):
npm run start:devThe API will be available at http://localhost:4000 (or the port specified in your .env file).
-
Build the application
npm run build
-
Start the production server
npm run start:prod
# Start without watch mode
npm run start
# Start in debug mode
npm run start:debug
# Format code
npm run format
# Lint code
npm run lintGET /users- Get all usersGET /users?id={id}- Get user by IDPOST /users- Create a new userPUT /users/:id- Update a userDELETE /users/:id- Delete a user
GET /listings- Get all listingsGET /listings?id={id}- Get listing by IDGET /listings?user={userId}- Get listings by userGET /listings?category={categoryName}- Get listings by categoryPOST /listings- Create a new listingPUT /listings/:id- Update a listingDELETE /listings/:id- Delete a listing
GET /categories- Get all categoriesPOST /categories- Create a new categoryDELETE /categories/:id- Delete a category
GET /messages?sender={senderId}- Get messages by senderGET /messages?sender={senderId}&recipient={recipientId}- Get messages between usersPOST /messages- Create a new messageDELETE /messages/:id- Delete a message
The API implements rate limiting to protect against abuse:
- Limit: 10 requests per 60 seconds per IP address
- Response: HTTP 429 (Too Many Requests) when limit is exceeded
- Window: Sliding window based on first request timestamp
To customize rate limits, modify the configuration in src/app.module.ts:
ThrottlerModule.forRoot([{
ttl: 60000, // Time window in milliseconds
limit: 10, // Maximum requests per window
}]),src/
├── app.module.ts # Root application module
├── main.ts # Application entry point
├── prisma.service.ts # Prisma database service
├── users/ # User module
│ ├── users.controller.ts
│ ├── users.service.ts
│ └── dto/
├── listings/ # Listing module
│ ├── listings.controller.ts
│ ├── listings.service.ts
│ └── dto/
├── categories/ # Category module
│ ├── categories.controller.ts
│ ├── categories.service.ts
│ └── dto/
└── messages/ # Message module
├── messages.controller.ts
├── messages.service.ts
└── dto/
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov
# Watch mode
npm run test:watch# View database in Prisma Studio
npx prisma studio
# Create a new migration
npx prisma migrate dev --name migration_name
# Reset database (⚠️ deletes all data)
npx prisma migrate reset
# Generate Prisma Client after schema changes
npx prisma generateThe API uses standard HTTP status codes:
200- Success201- Created400- Bad Request (validation errors)404- Not Found409- Conflict (e.g., duplicate email)429- Too Many Requests (rate limit exceeded)
- Input validation on all endpoints
- Rate limiting to prevent abuse
- SQL injection protection (via Prisma ORM)
- Type-safe database queries
This project is private and unlicensed.
This is a private project. For questions or issues, please contact the project maintainer.
For NestJS-related questions:
Built with ❤️ using NestJS