13 KiB
Estate Platform - Complete Setup Guide
Table of Contents
- Quick Start
- Prerequisites
- Local Development Setup
- Docker Setup
- Redis Configuration
- Database Setup
- Authentication Setup
- Testing the Application
- Troubleshooting
Quick Start
Using Docker (Recommended)
# 1. Clone the repository
git clone <repo-url>
cd estate-platform
# 2. Copy environment file
cp .env.example .env.local
# 3. Start all services (includes Redis)
docker-compose up -d
# 4. Run database migrations
docker-compose exec web npm run db:migrate
# 5. Seed the database (optional)
docker-compose exec web npm run db:seed
# 6. Access the application
open http://localhost:3000
Local Development
# 1. Install dependencies
npm install
# 2. Start Redis locally (macOS)
redis-server
# 3. Setup database
npm run db:migrate
npm run db:seed
# 4. Run development server
npm run dev
# 5. Open browser
open http://localhost:3001
Prerequisites
Required
Optional (for Docker)
- Docker (Download)
- Docker Compose (included with Docker Desktop)
For OAuth Providers (optional)
- Google OAuth credentials
- GitHub OAuth credentials
- Facebook OAuth credentials
- Discord OAuth credentials
Local Development Setup
1. Install Node.js
# Verify installation
node --version # Should be v18+
npm --version # Should be v9+
2. Clone Repository
git clone <repo-url>
cd estate-platform
3. Install Dependencies
npm install
4. Configure Environment Variables
# Copy example environment file
cp .env.example .env.local
# Edit with your values
nano .env.local # or use your preferred editor
Important variables to set:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/estate_platform"
REDIS_URL="redis://localhost:6379"
APP_BASE_URL="http://localhost:3001"
BETTER_AUTH_SECRET="your-random-secret-key"
5. Setup PostgreSQL Database
# Create database (if not exists)
createdb estate_platform
# Run migrations
npm run db:migrate
# Optional: Seed with sample data
npm run db:seed
6. Start Redis
# macOS (using Homebrew)
redis-server
# Linux (systemd)
sudo systemctl start redis-server
# Verify Redis is running
redis-cli ping # Should output "PONG"
7. Start Development Server
npm run dev
# Server runs at http://localhost:3001
8. Verify Setup
Open your browser and navigate to:
- Frontend: http://localhost:3001
- Admin Setup: http://localhost:3001/admin/setup
- API Health: http://localhost:3001/api/health (if available)
Docker Setup
1. Install Docker
# macOS
brew install docker
# Linux (Ubuntu)
sudo apt-get install docker.io docker-compose
# Verify installation
docker --version
docker-compose --version
2. Configure Environment
# Copy and edit environment
cp .env.example .env.local
# For Docker, use:
REDIS_URL="redis://:redis_password@redis:6379"
DATABASE_URL="postgresql://postgres:postgres@postgres:5432/estate_platform"
3. Start Services
# Start all services in background
docker-compose up -d
# View logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f web # Next.js app
docker-compose logs -f redis # Redis
docker-compose logs -f postgres # Database
4. Initialize Database
# Run migrations inside Docker
docker-compose exec web npm run db:migrate
# Seed with sample data
docker-compose exec web npm run db:seed
5. Access Application
- Frontend: http://localhost:3000
- Admin Setup: http://localhost:3000/admin/setup
6. Stop Services
# Stop containers
docker-compose down
# Stop and remove volumes (WARNING: deletes data!)
docker-compose down -v
Redis Configuration
Docker Setup (Recommended)
Redis is automatically configured in docker-compose.yml:
redis:
image: redis:7-alpine
ports:
- "6379:6379"
environment:
REDIS_PASSWORD: redis_password
volumes:
- redis_data:/data
Local Redis Setup
macOS
# Install with Homebrew
brew install redis
# Start Redis
redis-server
# Start as service (starts on boot)
brew services start redis
# Stop service
brew services stop redis
# Verify connection
redis-cli ping # Should output "PONG"
Linux (Ubuntu/Debian)
# Install Redis
sudo apt-get update
sudo apt-get install redis-server
# Start service
sudo systemctl start redis-server
# Enable on boot
sudo systemctl enable redis-server
# Check status
sudo systemctl status redis-server
# Verify connection
redis-cli ping # Should output "PONG"
Windows
# Using Windows Subsystem for Linux (WSL2)
# OR use Docker for Windows
docker run -d -p 6379:6379 redis:7-alpine
Verify Redis Connection
# Connect to Redis CLI
redis-cli
# Test commands
ping # Returns "PONG"
set key value # Set a key
get key # Get the value
del key # Delete the key
FLUSHALL # Clear all data (be careful!)
exit # Exit CLI
Configure Environment Variables
In .env.local:
# Local development
REDIS_URL="redis://localhost:6379"
# Docker setup
REDIS_URL="redis://:redis_password@redis:6379"
# With password (production)
REDIS_URL="redis://:your_strong_password@localhost:6379"
Database Setup
Using Docker (Easiest)
# Database runs automatically with docker-compose
docker-compose up -d postgres
# Run migrations
docker-compose exec web npm run db:migrate
# Seed data
docker-compose exec web npm run db:seed
# Access database
docker-compose exec postgres psql -U postgres -d estate_platform
Local PostgreSQL Setup
macOS
# Install PostgreSQL
brew install postgresql@15
# Start PostgreSQL
brew services start postgresql@15
# Verify installation
psql --version
Linux (Ubuntu/Debian)
# Install PostgreSQL
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
# Start service
sudo systemctl start postgresql
# Verify
psql --version
Create Database
# Connect to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE estate_platform;
# Exit
\q
Run Migrations
# Generate Prisma client
npm run db:generate
# Run migrations
npm run db:migrate
# Seed database (optional)
npm run db:seed
Database Commands
# Generate Prisma client after schema changes
npm run db:migrate
# Create new migration (if using manual SQL)
npm run db:migrate
# Reset database (WARNING: deletes all data!)
npx prisma migrate reset
# View database
npx prisma studio
Authentication Setup
BetterAuth Configuration
BetterAuth is configured in lib/auth.ts. Sessions are automatically cached with Redis.
Add OAuth Providers
-
Navigate to Admin Setup
- URL:
http://localhost:3001/admin/setup - Login as admin user
- URL:
-
Configure OAuth Providers
- Click each provider (Google, GitHub, Facebook, Discord)
- Add Client ID and Client Secret
- Save configuration
-
Get Provider Credentials
Google OAuth
- Go to Google Cloud Console
- Create new project
- Enable Google+ API
- Create OAuth 2.0 credentials (Web application)
- Add authorized redirect URIs:
http://localhost:3001/auth/google/callbackhttps://yourdomain.com/auth/google/callback
- Copy Client ID and Client Secret to admin setup
GitHub OAuth
- Go to GitHub Settings
- Click "New OAuth App"
- Fill in application details:
- Authorization callback URL:
http://localhost:3001/auth/github/callback
- Authorization callback URL:
- Copy Client ID and Client Secret
Facebook OAuth
- Go to Facebook Developers
- Create new app
- Add Facebook Login product
- Set Valid OAuth Redirect URIs:
http://localhost:3001/auth/facebook/callback
- Copy App ID and App Secret
Discord OAuth
- Go to Discord Developer Portal
- Create new application
- Go to OAuth2 settings
- Add redirect URI:
http://localhost:3001/auth/discord/callback
- Copy Client ID and Client Secret
Session Management
Sessions are automatically cached with Redis:
- Cache duration: 7 days
- Auto-expiry: TTL automatically managed
- User data cache: 1 hour (reduces database queries)
Testing the Application
Test User Creation
- Go to
/signup - Fill in user details:
- First Name: "John"
- Last Name: "Doe"
- Email: "john@example.com"
- Password: "SecurePassword123"
- Click Sign Up
Test OAuth Login
- Go to
/signin - Click any OAuth provider button
- Authenticate with provider credentials
- Should redirect to dashboard
Test Admin Setup
- Login as admin
- Navigate to
/admin/setup - Configure OAuth providers
- Save settings (cached with Redis)
- Verify settings persist
Test Redis Caching
# Connect to Redis
redis-cli
# Monitor cache operations
MONITOR
# In another terminal, make API calls
curl http://localhost:3001/api/admin/setup
# You should see Redis commands in monitor
Test Database
# View Prisma studio
npm run db:studio
# Or connect directly
psql -U postgres -d estate_platform
# Query users
SELECT * FROM "User";
# Query sessions
SELECT * FROM "Session";
Troubleshooting
Redis Connection Issues
Error: Error: connect ECONNREFUSED 127.0.0.1:6379
Solution:
# Check if Redis is running
redis-cli ping
# Start Redis
redis-server
# Or check Docker
docker-compose logs redis
docker-compose restart redis
Database Connection Issues
Error: Error: connect ECONNREFUSED localhost:5432
Solution:
# Check PostgreSQL status
psql -U postgres -c "SELECT version();"
# Start PostgreSQL
brew services start postgresql@15 # macOS
sudo systemctl start postgresql # Linux
# Check Docker
docker-compose logs postgres
docker-compose restart postgres
Port Already in Use
Error: Port 3001 is already in use
Solution:
# Kill process using port
lsof -i :3001
kill -9 <PID>
# Or use different port
npm run dev -- -p 3002
Authentication Issues
Issue: Cannot login or OAuth not working
Solution:
- Check OAuth credentials in admin setup
- Verify OAuth callback URLs match provider settings
- Check browser cookies:
Settings > Cookies > estate-platform - Clear cache:
Ctrl+Shift+Delete(Chrome) - Check console for errors:
F12 > Console
Admin Setup Page Blank
Issue: /admin/setup page shows nothing
Solution:
- Ensure logged in as admin
- Check Redis connection:
redis-cli ping - Check API response:
curl http://localhost:3001/api/admin/setup - Check browser console for errors
- Restart application
Slow Performance
Issue: Application feels slow
Solution:
-
Check Redis:
redis-cli INFO stats -
Check Database:
- Monitor slow queries
- Check indexes are created
-
Check Resources:
# Docker docker stats # Local top # macOS/Linux -
Clear Cache:
redis-cli FLUSHALL # WARNING: clears all cache!
Can't Access Admin Setup
Issue: /admin/setup returns 401 Unauthorized
Solution:
- Check user role is "ADMIN" in database
- Verify session/auth token exists
- Check JWT secret in
.env.local - Login again to refresh session
Docker Issues
Stop all containers:
docker-compose down
Remove all data (fresh start):
docker-compose down -v
Rebuild containers:
docker-compose up -d --build
View logs:
docker-compose logs -f [service] # web, redis, postgres
Performance Optimization Tips
-
Enable Redis Caching
- All API responses are automatically cached
- Reduces database queries by 50-70%
-
Optimize Database Indexes
- Check
prisma/schema.prismafor @@index - Add indexes for frequently queried fields
- Check
-
Use CDN for Static Assets
- Configure Cloudflare or similar
- Serve images and CSS globally
-
Monitor with Tools
- Use
npm run db:studiofor queries - Use
redis-cli MONITORfor cache hits - Use browser DevTools for performance
- Use
-
Enable Compression
- Gzip enabled by default in Next.js
- Verify with:
curl -I http://localhost:3001 | grep encoding
Next Steps
- Configure OAuth providers for your environment
- Setup email service for notifications
- Configure Stripe for payments (if needed)
- Deploy to production environment
- Setup monitoring and logging
- Configure backups for database and Redis
Support & Resources
- Next.js Documentation
- BetterAuth Documentation
- Prisma Documentation
- Redis Documentation
- PostgreSQL Documentation
For issues, check the REDIS_SETUP.md for additional Redis-specific guidance.