A modern AI-powered customer support application built with Next.js, PostgreSQL, and Docker.
- AI-Powered Chat: Intelligent customer support using OpenAI and document-based responses
- User Authentication: Secure JWT-based authentication with role management
- Document Management: Upload and manage knowledge base documents (PDF support)
- Vector Search: Fast document retrieval using Qdrant vector database
- Database Integration: PostgreSQL for persistent user and application data
- Dockerized Deployment: Complete containerized setup with Docker Compose
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Node.js
- Database: PostgreSQL with Drizzle ORM
- Vector DB: Qdrant for document embeddings
- AI: OpenAI GPT models, LangChain
- Authentication: JWT tokens, bcrypt password hashing
- Deployment: Docker, Docker Compose
- Docker and Docker Compose
- Node.js 18+ (for local development)
- OpenAI API key
-
Clone the repository:
git clone <repository-url> cd lab-llm
-
Complete setup with one command:
make setup
-
Configure environment variables when prompted:
- Add your
OPENAI_API_KEY
- Set a secure
JWT_SECRET
- Add your
-
Clone the repository:
git clone <repository-url> cd lab-llm
-
Run the setup script:
./scripts/setup.sh
-
Configure environment variables when prompted:
- Add your
OPENAI_API_KEY
- Set a secure
JWT_SECRET
- Add your
-
Clone and install dependencies:
git clone <repository-url> cd lab-llm npm install
-
Configure environment:
cp env.example .env # Edit .env with your configuration
-
Generate database schema:
npm run db:generate
-
Start services:
docker-compose up -d
-
Run migrations:
docker-compose run --rm migrate
After setup, the application will be available at:
- Application: http://localhost:3000
- PostgreSQL: localhost:5432
- Qdrant: http://localhost:6333
lab-llm/
βββ src/
β βββ app/ # Next.js App Router
β β βββ api/ # API routes
β β βββ chat/ # Chat interface
β β βββ admin/ # Admin panel
β β βββ auth/ # Authentication pages
β βββ components/ # React components
β βββ lib/ # Utility libraries
β β βββ db.ts # Database configuration
β β βββ schema.ts # Database schema
β β βββ user-db.ts # User database operations
β β βββ auth.tsx # Authentication context
β βββ types/ # TypeScript type definitions
βββ drizzle/ # Database migrations
βββ scripts/ # Setup and utility scripts
βββ docker-compose.yml # Docker services configuration
βββ Dockerfile # Application container
βββ drizzle.config.ts # Database configuration
# Complete setup (first time)
make setup
# Start development environment
make dev # Local dev server + database services
make dev-full # Full development environment
# Docker operations
make start # Start all services
make stop # Stop all services
make restart # Restart all services
make status # Show service status
# After code changes
make update # Full update (rebuild + restart)
make quick-update # Quick app-only update
# Database operations
make db-generate # Generate migrations
make db-migrate-docker # Run migrations in Docker
make db-studio # Open database studio
make db-reset # Reset database (β οΈ deletes data)
# Utility commands
make logs # Show all logs
make logs-app # App logs only
make health # Health check
make urls # Show service URLs
make help # Show all available commands
-
Start the database:
docker-compose up postgres qdrant -d
-
Run the development server:
npm run dev
-
Access the application: http://localhost:3000
- Generate migrations:
npm run db:generate
- Run migrations:
npm run db:migrate
- Open database studio:
npm run db:studio
- Start all services:
docker-compose up -d
- View logs:
docker-compose logs -f
- Stop services:
docker-compose down
- Rebuild application:
docker-compose build app
Variable | Description | Default |
---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://postgres:password@localhost:5432/lab_llm |
JWT_SECRET |
Secret for JWT token signing | your-secret-key-change-this-in-production |
OPENAI_API_KEY |
OpenAI API key for AI features | Required |
QDRANT_URL |
Qdrant vector database URL | http://localhost:6333 |
NODE_ENV |
Environment mode | development |
- User: Basic access to chat interface
- Admin: Full access including document management and admin panel
POST /api/auth/login
- User loginPOST /api/auth/register
- User registration
POST /api/chat
- Send chat message
POST /api/upload
- Upload documentsGET /api/documents
- List documents
GET /api/init-db
- Database health checkPOST /api/init-db
- Initialize database
- Update environment variables for production
- Use secure JWT secret: Generate a strong random string
- Configure database: Use a managed PostgreSQL service
- SSL/TLS: Enable HTTPS in production
- Resource limits: Configure Docker resource constraints
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License.
-
Database connection failed:
- Check if PostgreSQL is running:
docker-compose ps
- Verify DATABASE_URL in .env file
- Check if PostgreSQL is running:
-
OpenAI API errors:
- Ensure OPENAI_API_KEY is set correctly
- Check API quota and billing
-
Docker issues:
- Restart Docker daemon
- Run
docker-compose down && docker-compose up -d
-
Port conflicts:
- Check if ports 3000, 5432, or 6333 are in use
- Update docker-compose.yml port mappings if needed
View application logs:
docker-compose logs -f app
View database logs:
docker-compose logs -f postgres