A progressive Node.js framework for building efficient and scalable server-side applications.
Nest framework TypeScript application with JWT authentication, Prisma ORM, Supabase integration, and real-time WebSocket notifications.
- JWT Authentication - Secure token-based authentication with Passport.js
- Prisma ORM - Type-safe database access with Supabase PostgreSQL
- WebSocket Support - Real-time notifications using Socket.IO
- Device Management - Device monitoring and alert system
- User Management - User registration and profile management
- Alert System - Real-time alert notifications
src/
├── auth/ # JWT authentication module
├── users/ # User management
├── device/ # Device operations
├── devices/ # Device management
├── alert/ # Alert system
├── interventions/ # Intervention management
├── notification/ # WebSocket notifications
├── prisma/ # Prisma service
├── supabase/ # Supabase integration
└── app.module.ts # Main application module
- Node.js
- npm or yarn
- Supabase
- PostgreSQL database (via Supabase)
Create a .env
file in the root directory with the following variables:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
#DATABASE_URL="postgresql://safa:safa@localhost:5432/xceed?schema=public"
#DIRECT_URL="postgresql://safa:safa@localhost:5432/xceed"
DATABASE_URL="postgresql://postgres.rsctlmexmrtoamsucnsp:kitxiV-0gofce-henboq@aws-0-eu-west-3.pooler.supabase.com:6543/postgres?pgbouncer=true"
DIRECT_URL="postgresql://postgres.rsctlmexmrtoamsucnsp:kitxiV-0gofce-henboq@aws-0-eu-west-3.pooler.supabase.com:5432/postgres"
JWT_SECRET="9b33622f0fe0486cff5f5bc4bee3716f9652db6d9d86e953a25c75b8694be71b666d106eaf65bc637213a4d21aed2f232e414c1fab34ba4447b3250d83dd4079d5b31762a9c809b335a1fa7f1253488afeed06a09973092fc7d424e185224ac2bac97a9ec5f263794a05f670d7f84899eb4d995d93c10a9c34c015948fa7869aac6e6b4d476cda4b7164d4db54e1708fddcbcd86016955c19afb949801cb466a83045005d744530a5fed7d45cee9b0d209d548ed3f891e3f399e8198a692f28e25d93cad2529ea5f066c306b79c97f2b28942b8982c6344765f6c4ed347bb3c68ba76682015f8616c10f75745a9006593865429ebdbd97b0e33243810749b7f0"
# Install dependencies
$ npm install
# Generate Prisma client
$ npx prisma generate
# Run database migrations
$ npx prisma migrate dev --name init
# Regenerate Prisma client (if needed)
$ npx prisma generate
#Core NestJS Dependencies
$ npm install @nestjs/core @nestjs/common @nestjs/platform-express
# Authentication Dependencies
$ npm install @nestjs/jwt @nestjs/passport passport passport-jwt bcrypt
$ npm install --save-dev @types/passport-jwt @types/bcrypt
# Database Dependencies
$ npm install prisma @prisma/client @supabase/supabase-js
# WebSocket Dependencies
$ npm install @nestjs/websockets @nestjs/platform-socket.io socket.io
# Configuration & Validation
$ npm install @nestjs/config class-validator class-transformer
# Development Dependencies
$ npm install --save-dev @types/passport-jwt @types/bcrypt @types/node typescript ts-node
$ npx prisma migrate dev
# Development mode
$ npm run start
# Watch mode (recommended for development)
$ npm run start:dev
# Production mode
$ npm run start:prod
The application will start on http://localhost:3000
.
POST /auth/login
- User loginPOST /auth/validate-token
- Token validation
GET /users
- Get all usersPOST /users
- Create new userGET /users/:id
- Get user by ID
GET /devices
- Get all devicesPOST /devices
- Create new devicePUT /devices/:id
- Update device
GET /alerts
- Get all alertsPOST /alerts
- Create new alert
The application supports real-time notifications via WebSocket:
- Connect to:
ws://localhost:3000
- Listen for
alert
events for real-time notifications
# Unit tests
$ npm run test
# End-to-end tests
$ npm run test:e2e
# Test coverage
$ npm run test:cov
Access your database with a visual editor:
$ npx prisma studio
Reset your database and run migrations:
$ npx prisma migrate reset
$ npx prisma db pull
# Build the application
$ npm run build
- Prisma Client not generated: Run
npx prisma generate
- Database connection issues: Check your
DATABASE_URL
in.env
- JWT errors: Ensure
JWT_SECRET
is set in your environment - CORS issues: Update CORS origins in
src/main.ts
If you encounter database-related issues:
# Reset and migrate
$ npx prisma migrate reset
# Check database status
$ npx prisma migrate status