Initial commit: Full project structure
- Backend: NestJS with Docker - Frontend: Next.js with Docker - Nginx configuration for reverse proxy - PostgreSQL setup - Docker compose for orchestration - Development environment configuration
This commit is contained in:
95
backend/SETUP.md
Normal file
95
backend/SETUP.md
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
# Dyolink Backend - Development Setup Guide
|
||||
|
||||
## 📋 Prerequisites
|
||||
|
||||
Before starting, ensure you have the following installed:
|
||||
- **Node.js** (v18 or higher)
|
||||
- **PostgreSQL** (v15 or higher) - We use v18, but any v15+ works
|
||||
- **Git** (for cloning)
|
||||
- **npm** or **yarn** (npm comes with Node.js)
|
||||
|
||||
## 🚀 Initial Setup Steps
|
||||
|
||||
1. Clone the Repository
|
||||
```bash
|
||||
git clone [your-repository-url]
|
||||
cd dyolink/backend
|
||||
|
||||
2. Install Dependencies
|
||||
bash
|
||||
npm install
|
||||
|
||||
3. Environment Configuration
|
||||
Create a .env file in the backend folder:
|
||||
env
|
||||
# backend/.env
|
||||
DATABASE_URL=postgresql://postgres:1234@localhost:5432/dyolink_db
|
||||
JWT_SECRET=your-super-secret-key-here-change-this
|
||||
JWT_REFRESH_SECRET=your-super-secret-refresh-key-here-different-from-above
|
||||
JWT_EXPIRES_IN=15m
|
||||
JWT_REFRESH_EXPIRES_IN=7d
|
||||
PORT=3000
|
||||
⚠️ Important: Never commit the .env file to git! We have .gitignore set up to prevent this.
|
||||
|
||||
4. Database Setup
|
||||
Option A: Fresh PostgreSQL Installation
|
||||
If you don't have PostgreSQL installed:
|
||||
Windows (using Chocolatey):
|
||||
bash
|
||||
choco install postgresql
|
||||
macOS (using Homebrew):
|
||||
bash
|
||||
brew install postgresql@15
|
||||
brew services start postgresql@15
|
||||
Common Installation Issues & Fixes:
|
||||
Issue Solution
|
||||
"Password not set during installation" Edit pg_hba.conf temporarily (see Troubleshooting section)
|
||||
"Service not starting" Run PowerShell/Terminal as Administrator
|
||||
"Port 5432 already in use" Stop local PostgreSQL service or change port
|
||||
Option B: Using Existing PostgreSQL
|
||||
If you already have PostgreSQL:
|
||||
bash
|
||||
# Connect to PostgreSQL
|
||||
psql -U postgres
|
||||
# Create the database (if it doesn't exist)
|
||||
CREATE DATABASE dyolink_db;
|
||||
\q
|
||||
|
||||
5. Database Migrations
|
||||
Once PostgreSQL is running and you've created the database:
|
||||
bash
|
||||
# Generate Prisma client
|
||||
npx prisma generate
|
||||
# Run migrations to create tables
|
||||
npx prisma migrate dev --name init_schema
|
||||
⚠️ Known Issue: If you get P1001: Can't reach database server, ensure PostgreSQL is running:
|
||||
bash
|
||||
# Check PostgreSQL status
|
||||
# Windows:
|
||||
Get-Service postgresql-x64-18
|
||||
# macOS:
|
||||
brew services list | grep postgres
|
||||
|
||||
6. Seed the Database
|
||||
bash
|
||||
# Seed with initial data (organization types, plans, permissions, test user)
|
||||
npx prisma db seed
|
||||
⚠️ Prisma 7 Note: If seeding fails with PrismaClientInitializationError, we've fixed this by using the driver adapter pattern. The seed file now uses:
|
||||
typescript
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { Pool } from 'pg';
|
||||
const adapter = new PrismaPg(pool);
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
7. Verify Setup
|
||||
bash
|
||||
# Open Prisma Studio to verify data
|
||||
npx prisma studio
|
||||
# This opens http://localhost:5555 - you should see all tables with seeded data
|
||||
8. Start Development Server
|
||||
bash
|
||||
npm run start:dev
|
||||
You should see:
|
||||
text
|
||||
Application is running on: http://localhost:3000
|
||||
✅ Database connected successfully
|
||||
Reference in New Issue
Block a user