Skip to content

Latest commit

 

History

History
207 lines (148 loc) · 4.12 KB

File metadata and controls

207 lines (148 loc) · 4.12 KB

Setup Guide - Shazan Platform

Complete step-by-step guide to set up the Shazan marketplace platform.

Prerequisites

  • Node.js: v16.0.0 or higher
  • npm or yarn: Package manager
  • PostgreSQL: v12 or higher
  • Git: Version control

Initial Setup

1. Clone Repository

git clone <repository-url>
cd shazan-backend

2. Install Dependencies

npm install

3. Environment Configuration

cp .env.example .env

Edit .env with your configuration. See ENV.md for details.

4. Database Setup

PostgreSQL Connection

Ensure PostgreSQL is running and accessible:

# Test connection
psql -h localhost -U bornali -d shazan

Initialize Prisma

# Generate Prisma client
npx prisma generate

# Run migrations
npx prisma migrate dev --name init

# View database in Prisma Studio (optional)
npx prisma studio

5. Start Development Server

npm run start:dev

Expected output:

Shazan API running on http://localhost:3000

External Services Setup

Stripe

  1. Create Account: https://stripe.com
  2. Get API Keys:
    • Go to Developers → API Keys
    • Copy Secret Key (starts with sk_test_)
    • Copy Webhook Secret (starts with whsec_)
  3. Update .env:
    STRIPE_SECRET_KEY=sk_test_51234567890...
    STRIPE_WEBHOOK_SECRET=whsec_1234567890...
    

Cloudinary

  1. Create Account: https://cloudinary.com
  2. Get Credentials:
    • Dashboard → Settings
    • Copy Cloud Name, API Key, API Secret
  3. Update .env:
    CLOUDINARY_NAME=your_cloud_name
    CLOUDINARY_API_KEY=your_api_key
    CLOUDINARY_API_SECRET=your_api_secret
    

Gmail (Email Service)

  1. Enable 2-Factor Authentication on Gmail account
  2. Generate App Password:
  3. Update .env:
    MAIL_USER=your_email@gmail.com
    MAIL_PASS=xxxx xxxx xxxx xxxx
    

Database Schema Initialization

All tables are created automatically via Prisma migrations. Key tables include:

  • Auth - User accounts and authentication
  • SellerProfile - Seller business information
  • Ad - Marketplace listings
  • Bid - Auction bids
  • Payment - Transaction records
  • Message - User conversations
  • Comment - Product reviews and comments
  • Category - Product categories
  • SubCategory - Category subdivisions

See DATABASE.md for complete schema details.

Development Commands

# Start development server
npm run start:dev

# Build for production
npm run build

# Run production server
npm run start:prod

# Run tests
npm run test

# Format code
npm run lint

# Generate Prisma client
npx prisma generate

# View database UI
npx prisma studio

Common Issues

PostgreSQL Connection Error

Error: connect ECONNREFUSED 127.0.0.1:5434

Solution: Ensure PostgreSQL is running on the correct port (5434 in your config).

# Check if PostgreSQL is running
sudo service postgresql status

# Start PostgreSQL
sudo service postgresql start

Prisma Migration Error

Error: database "shazan" does not exist

Solution: Create the database first.

createdb -U bornali shazan
npx prisma migrate dev

Environment Variables Not Found

Ensure .env file is in the project root and contains all required variables. See ENV.md.

Next Steps

  1. Review API.md for endpoint documentation
  2. Configure external services (Stripe, Cloudinary, Gmail)
  3. Run development server and test endpoints
  4. Check DATABASE.md for schema reference
  5. Read CONTRIBUTING.md before making changes

Production Deployment

Before deploying to production:

  1. Set NODE_ENV=production in .env
  2. Update FRONTEND_URL to production domain
  3. Use production API keys for Stripe, Cloudinary
  4. Enable HTTPS
  5. Set up automated backups for PostgreSQL
  6. Configure monitoring and logging
  7. Review security best practices

For detailed deployment instructions, see your hosting provider's documentation.