Backend for LaBase, a workspace management system that includes reservations, user administration, employees, products, and an AI assistant chatbot. Built with Node.js, Express, and TypeScript following Clean Architecture with Vertical Slices to ensure scalability and maintainability.
The system includes integration with WhatsApp Business using whatsapp-web.js and Google Gemini to provide automated assistance to users.
- Node.js (v18+) - JavaScript runtime
- Express - Web framework for Node.js
- TypeScript - Static typing for JavaScript
- Prisma ORM - Object-relational mapping with PostgreSQL
- Zod - Schema validation and types
- PostgreSQL - Main database
- Redis - Cache and temporary sessions
- JWT (jsonwebtoken) - Authentication tokens
- Bcrypt - Password hashing
- AWS S3 - File storage
- Nodemailer - Email sending
- WhatsApp Web.js - WhatsApp Business integration
- Google Gemini API - Generative AI for chatbot
- Socket.IO - Real-time communication
- Swagger - Interactive API documentation
- Multer - File uploads
- EJS - Email templates
- Morgan - HTTP logger
- Day.js & date-fns - Date handling
- Nanoid & UUID - Unique identifier generation
- Node.js v18 or higher (recommended v20+)
- PostgreSQL 16+ (local or Docker)
- Redis (local or Docker)
- Docker (optional, for containerized development)
- Chromium/Chrome (required by whatsapp-web.js)
git clone <REPOSITORY_URL>
cd labase-servernpm installCreate a .env file in the project root with the following variables:
# Start PostgreSQL and Redis
docker-compose up -d
# Restart database (only in local)
npx prisma migrate reset --force
# Create first migration
npx prisma migrate dev --name init
# (Optional) Open Prisma Studio
npm run prisma:studio# Install PostgreSQL and Redis locally
# Then run:
# Restart database (only in local)
npx prisma migrate reset --force
# Create first migration
npx prisma migrate dev --name initnpm run seed:devnpm run devnpm run build
npm start# Start only services (DB + Redis)
docker-compose up -d
# Run the app locally
npm run devThe docker-compose.yml file includes:
- PostgreSQL 16 on port 5432
- Redis on port 6379
- Persistent volumes for data
# Generate Prisma client
npm run prisma:generate
# Create and apply new migration
npm run prisma:migrate
# Open Prisma Studio (graphical interface)
npm run prisma:studio
# Complete database reset
npx prisma migrate reset
# Apply migrations in production
npx prisma migrate deploy- Modify the
prisma/schema.prismafile - Create migration:
npx prisma migrate dev --name migration_name
- Apply in production:
npx prisma migrate deploy
prisma/
βββ migrations/
β βββ 20250824204101_init/
β β βββ migration.sql
β βββ migration_lock.toml
βββ schema.prisma
src/
βββ config/ # Global configurations
β βββ env/ # Environment variables
β βββ prisma_client/ # Prisma client
β βββ redis/ # Redis configuration
β βββ socket/ # Socket.IO configuration
βββ constants/ # Global constants
βββ infrastructure/ # External services (AWS, JWT)
βββ middlewares/ # Express middlewares
βββ modules/ # Business modules (See architecture.md)
βββ shared/ # Shared code
βββ utils/ # General utilities
βββ docs/ # Swagger documentation
βββ index.ts # entry point
βββ routes.ts # Main route configuration
- Client: whatsapp-web.js with local authentication
- AI: Google Gemini with personalized context
- Functionalities:
- Intelligent automatic responses
- Space inquiry management
- Reservation assistance
- General business information
- Ensure
API_KEY_GEMINIis configured - When starting the application, a QR code will be displayed in console
- Scan the QR with WhatsApp on your mobile device
- The bot will be active and respond automatically
Interactive API documentation is available at:
http://localhost:3001/api-docs
- Auth:
/api/v1/auth/*- Authentication and registration - Spaces:
/api/v1/spaces/*- Space management - Reservations:
/api/v1/reservations/*- Reservation system - Users:
/api/v1/users/*- User management - Products:
/api/v1/products/*- Product management - Chatbot:
/api/v1/chatbot/*- Bot interaction
# Development
npm run dev # Server with hot reload
# Production
npm run build # Compile TypeScript
npm start # Run compiled version
# Database
npm run prisma:generate # Generate Prisma client
npm run prisma:migrate # Run migrations
npm run prisma:studio # Open Prisma StudioInstall extensions:
- Prisma - Prisma schema support
- TypeScript Importer - Auto-imports
- REST Client - Test endpoints
For local development, use the following configurations in .env:
ENVIRONMENT=development
NODE_ENV=development
DATABASE_URL=postgresql://root:root@localhost:5432/labase-service
REDIS_URL=redis://localhost:6379
APP_URL=http://localhost:3001For detailed information about architecture, modules, and patterns used, consult:
π Architecture.md - Complete project architecture guide
- Fork the repository
- Create feature branch:
git checkout -b feature/new-functionality - Commit changes:
git commit -m 'Add new functionality' - Push to branch:
git push origin feature/new-functionality - Create Pull Request
- Logs appear in console with HTTP request details
- Use Morgan for automatic request logging
# Debug mode with more information
DEBUG=* npm run dev- WhatsApp Web: Requires keeping the session active, don't close the application abruptly
- Files: Images are stored in AWS S3, configure credentials correctly
- Redis: Required for session and cache functionality
- Migrations: Always backup before running migrations in production
For more detailed information about architecture and how to create new modules, see architecture.md.