A simplified, monolithic NestJS backend application with Prisma ORM for rapid MVP development.
- Monolithic Architecture: Single NestJS application instead of microservices
- Prisma ORM: Type-safe database access with PostgreSQL
- User Management: CRUD operations for users
- Product Management: CRUD operations for products with user relationships
- Validation: Built-in request validation with class-validator
- Docker Support: PostgreSQL database via Docker Compose
- Node.js 18+
- Docker and Docker Compose
- npm or yarn
- Clone and install dependencies:
npm install- Set up environment variables:
cp .env.example .env
# Edit .env with your database credentials- Start the database:
npm run db:up- Run database migrations:
npm run prisma:migrate- Start the development server:
npm run start:devThe application will be available at http://localhost:3000
npm run devThis command safely:
- Checks if the database is already running (starts only if needed)
- Runs database migrations
- Starts the development server
npm run dev:freshUse this when you need a completely clean environment:
- Restarts the PostgreSQL container
- Runs database migrations
- Starts the development server
# Check database status
npm run db:status
# Stop database
npm run db:down
# Restart database only
npm run db:restart
# Check what's using port 3000
lsof -ti:3000
# Kill process on port 3000
kill $(lsof -ti:3000)"Port 3000 already in use":
kill $(lsof -ti:3000)
npm run dev"Container name already in use":
npm run dev:freshDatabase connection issues:
npm run db:restart
npm run prisma:migrate
npm run start:devnpm run start:dev- Start development server with hot reloadnpm run dev- Start database, migrate, and run dev servernpm run build- Build the applicationnpm run start:prod- Start production server
npm run db:up- Start PostgreSQL databasenpm run db:down- Stop databasenpm run prisma:migrate- Run database migrationsnpm run prisma:generate- Generate Prisma clientnpm run prisma:studio- Open Prisma Studionpm run prisma:reset- Reset database
npm run res:create <name>- Generate module, controller, service, and DTO folder (Prisma-friendly)
npm run format- Format code with Prettiernpm run lint- Lint and fix code with ESLintnpm run test- Run unit testsnpm run test:watch- Run tests in watch modenpm run test:cov- Run tests with coveragenpm run test:e2e- Run end-to-end tests
For Prisma-based projects, use the custom resource generator:
npm run res:create video-streamingThis creates:
- Module:
src/video-streaming/video-streaming.module.ts - Controller:
src/video-streaming/video-streaming.controller.ts - Service:
src/video-streaming/video-streaming.service.ts - DTO folder:
src/video-streaming/dto/
No entities are generated since we use Prisma schema instead.
GET /users- Get all usersGET /users/:id- Get user by IDPOST /users- Create new userPUT /users/:id- Update userDELETE /users/:id- Delete user
GET /products- Get all productsGET /products?ownerId=:id- Get products by ownerGET /products/:id- Get product by IDPOST /products- Create new productPUT /products/:id- Update productDELETE /products/:id- Delete product
src/
├── app.module.ts # Main application module
├── main.ts # Application entry point
├── prisma/
│ └── prisma.service.ts # Prisma service
├── user/ # User module
│ ├── user.controller.ts
│ ├── user.service.ts
│ ├── user.module.ts
│ └── dto/
└── product/ # Product module
├── product.controller.ts
├── product.service.ts
├── product.module.ts
└── dto/
-
Generate Prisma client:
pnpm prisma:generate
-
Build the project:
pnpm build
-
Start all services:
pnpm dev
Alternatively, run all steps at once:
pnpm start:all-
POST /api/users- Create a new user{ "email": "user@example.com", "name": "John Doe" } -
GET /api/users- Get all users
-
POST /api/products- Create a new product{ "name": "Product Name", "price": 29.99, "ownerId": "user_id" } -
GET /api/products- Get all products -
GET /api/products/owner/:ownerId- Get products by owner ID
Run the end-to-end test script:
./e2e-test.shView your database with Prisma Studio:
pnpm prisma:studioStop all services:
Ctrl+C in the terminal where the services are runningStop and remove the PostgreSQL container:
pnpm db:downThe application uses a simple schema with Users and Products:
- User: id, email, name, products[]
- Product: id, name, price, ownerId, owner
- Create a new module:
nest g module feature-name - Add service:
nest g service feature-name - Add controller:
nest g controller feature-name - Update database schema in
prisma/schema.prisma - Run migration:
npm run prisma:migrate
npm run test # Unit tests
npm run test:e2e # End-to-end tests
npm run test:cov # Test coverage
./test-api.sh # API endpoint tests- Build the application:
npm run build - Set production environment variables
- Run migrations:
npm run prisma:migrate - Start:
npm run start:prod
DATABASE_URL="postgresql://mvpuser:mvppassword@localhost:5433/mvpdb?schema=public"
PORT=3000
NODE_ENV=developmentThis project was simplified from a complex microservices architecture to a monolithic structure perfect for MVP development. See MIGRATION_SUMMARY.md for detailed information about the transformation process and benefits achieved.