image_tagger/SETUP_GUIDE.md
2025-11-03 13:22:29 +05:30

4.2 KiB

🚀 Quick Setup Guide

Prerequisites

Step-by-Step Setup

1. Configure Environment Variables

Edit the .env file in the project root and fill in the required values:

# Set your MySQL password (if root has a password)
DB_PASSWORD=your_mysql_root_password

# Add your Anthropic API key (REQUIRED for image tagging)
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxx

Note: If your MySQL root user doesn't have a password, leave DB_PASSWORD empty.

2. Set Up the Database

Run the database setup script:

npm run db:setup

This will:

  • Create the property_tagging database
  • Import all required tables (api_keys, tagged_images, image_tags)
  • Verify the setup

3. Create an API Key (Optional)

If you want to test with authentication (SKIP_AUTH=false), create an API key:

npm run apikey:create

Save the generated API key for testing.

4. Start the Server

Development mode (with auto-reload):

npm run dev

Production mode:

npm start

The server will start on http://localhost:3000

Testing the API

Health Check (No Auth Required)

curl http://localhost:3000/

Tag an Image (With SKIP_AUTH=true)

curl -X POST http://localhost:3000/api/images/tag-base64 \
  -H "Content-Type: application/json" \
  -d '{
    "base64Image": "data:image/jpeg;base64,/9j/4AAQ...",
    "fileName": "test.jpg"
  }'

Tag an Image (With API Key Authentication)

curl -X POST http://localhost:3000/api/images/tag-base64 \
  -H "Content-Type: application/json" \
  -H "X-API-Key: key_live_xxxxxxxxxx" \
  -d '{
    "base64Image": "data:image/jpeg;base64,/9j/4AAQ...",
    "fileName": "test.jpg"
  }'

Available Scripts

Command Description
npm start Start the server in production mode
npm run dev Start the server in development mode (with nodemon)
npm run db:setup Set up the database and import schema
npm run apikey:create Create a new API key
npm run apikey:list List all API keys
npm run apikey:revoke Revoke an API key

API Endpoints

  • GET / - Health check and API information
  • GET /api/images/health - Detailed health check
  • POST /api/images/tag - Tag an uploaded image file
  • POST /api/images/tag-base64 - Tag a base64-encoded image
  • POST /api/images/tag-batch - Tag multiple uploaded images
  • POST /api/images/tag-batch-base64 - Tag multiple base64 images
  • GET /api/images/search?tag=kitchen - Search images by tag
  • GET /api/images/stats - Get tagging statistics

Troubleshooting

MySQL Connection Error

If you see "Access denied for user 'root'@'localhost'":

  1. Check your MySQL password in .env
  2. Or try connecting with sudo: sudo mysql
  3. Create a new MySQL user if needed:
CREATE USER 'property_tagger'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON property_tagging.* TO 'property_tagger'@'localhost';
FLUSH PRIVILEGES;

Then update your .env:

DB_USER=property_tagger
DB_PASSWORD=your_password

Anthropic API Key Error

If you see "ANTHROPIC_API_KEY not set":

  1. Sign up at https://console.anthropic.com/
  2. Create an API key
  3. Add it to your .env file

Port Already in Use

If port 3000 is already in use, change it in .env:

PORT=3001

Development Mode

For development with authentication disabled, set in .env:

SKIP_AUTH=true

This allows testing without API keys.

Next Steps

  • Import the Property_Image_Tagging_API.postman_collection.json into Postman for easy API testing
  • Check the logs in the logs/ directory for debugging
  • Review the code structure in the src/ directory

Architecture

This project follows Clean Architecture:

src/
├── domain/          # Business entities and interfaces
├── application/     # Use cases and business logic
├── infrastructure/  # External services (DB, AI)
├── presentation/    # HTTP controllers and routes
└── shared/          # Common utilities

Support

For issues or questions, check the logs:

  • logs/combined-YYYY-MM-DD.log - All logs
  • logs/error-YYYY-MM-DD.log - Error logs only