4.2 KiB
4.2 KiB
🚀 Quick Setup Guide
Prerequisites
- Node.js 18+ installed
- MySQL 8.0+ running
- Anthropic Claude API key (get from https://console.anthropic.com/)
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_taggingdatabase - 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 informationGET /api/images/health- Detailed health checkPOST /api/images/tag- Tag an uploaded image filePOST /api/images/tag-base64- Tag a base64-encoded imagePOST /api/images/tag-batch- Tag multiple uploaded imagesPOST /api/images/tag-batch-base64- Tag multiple base64 imagesGET /api/images/search?tag=kitchen- Search images by tagGET /api/images/stats- Get tagging statistics
Troubleshooting
MySQL Connection Error
If you see "Access denied for user 'root'@'localhost'":
- Check your MySQL password in
.env - Or try connecting with sudo:
sudo mysql - 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":
- Sign up at https://console.anthropic.com/
- Create an API key
- Add it to your
.envfile
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.jsoninto 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 logslogs/error-YYYY-MM-DD.log- Error logs only