# Database Setup

### PostgreSQL Setup

1. **Create Database**
   ```sql
   CREATE DATABASE onmarket_db;
   CREATE USER onmarket_user WITH ENCRYPTED PASSWORD 'your_password';
   GRANT ALL PRIVILEGES ON DATABASE onmarket_db TO onmarket_user;
   ```

2. **Database Models**
   The application uses Sequelize ORM with auto-sync. Models include:
   - `store` - Store information
   - `user_info` - User profiles
   - `product` - Product catalog
   - `cart` - Shopping carts
   - `store_order` - Orders
   - `balance_mutation` - Financial transactions
   - `affiliate_account` - Affiliate accounts
   - `affiliate_commissions` - Commission records
   - `address_list` - Delivery addresses
   - `bank_info` - Bank account information
   - `review` - Product reviews
   - `voucher` - Discount vouchers
   - And many more...

3. **Initial Data**
   - Categories
   - Expedition methods
   - Bank configurations
   - Commission rates

### MongoDB Setup

1. **Start MongoDB**
   ```bash
   mongod --dbpath /path/to/data/directory
   ```

2. **Collections**
   MongoDB is used for:
   - `store_chat` - Chat messages
   - `store_chat_room` - Chat rooms
   - `affiliate_category` - Affiliate categories
   - `affiliate_clicks` - Click tracking
   - `affiliate_links` - Affiliate link management
   - `order_info_cached` - Order cache
   - `shipping_info_cached` - Shipping cache
   - `price_info_cached` - Price cache
   - `expedition_count` - Delivery statistics

### Redis Setup

1. **Start Redis**
   ```bash
   redis-server
   ```

2. **Usage**
   Redis is used for:
   - Session management
   - API response caching
   - Rate limiting
   - Bull queue jobs