A Node.js backend service for MetaCreators platform, handling user management, image generation, and payment processing.
- User registration and authentication
- Credit system for image generation
- User profile management
- AI-powered image generation using Replicate API
- Image fine-tuning capabilities
- Training image management
- Generated image storage and retrieval
- Razorpay integration for payments
- Multiple subscription plans (Plus, Max, Pro)
- Credit purchase system
- Payment verification and webhook handling
- AWS S3/DigitalOcean Spaces integration for image storage
- Presigned URL generation for secure uploads
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL with Drizzle ORM
- Storage: AWS S3/DigitalOcean Spaces
- Payment: Razorpay
- AI Services:
- Google Gemini API
- Replicate API
- Cache: Redis
graph TB
subgraph Client
Web[Web Client]
Mobile[Mobile Client]
end
subgraph Backend
API[Express API Server]
Auth[Authentication]
Cache[Redis Cache]
Queue[Redis Queue]
end
subgraph External Services
AI[AI Services]
subgraph AI
Gemini[Gemini API]
Replicate[Replicate API]
end
Storage[Storage]
subgraph Storage
S3[AWS S3/DO Spaces]
end
Payment[Razorpay]
end
subgraph Database
DB[(PostgreSQL)]
subgraph DB
Users[(Users Table)]
Images[(Generated Images)]
Credits[(Credit Transactions)]
end
end
%% Client to Backend connections
Web --> API
Mobile --> API
%% Backend internal connections
API --> Auth
API --> Cache
API --> Queue
%% Backend to External Services
API --> AI
API --> Storage
API --> Payment
%% Backend to Database
API --> DB
%% AI Services connections
Gemini --> API
Replicate --> API
%% Storage connections
S3 --> API
%% Payment connections
Payment --> API
%% Database tables
Users --> DB
Images --> DB
Credits --> DB
classDef primary fill:#f9f,stroke:#333,stroke-width:2px
classDef secondary fill:#bbf,stroke:#333,stroke-width:2px
classDef external fill:#bfb,stroke:#333,stroke-width:2px
classDef database fill:#fbb,stroke:#333,stroke-width:2px
class Web,Mobile primary
class API,Auth,Cache,Queue secondary
class AI,Storage,Payment external
class DB,Users,Images,Credits database
-
Client Layer
- Web and Mobile clients interact with the backend through REST APIs
- Handles user interface and API requests
-
Backend Layer
- Express API Server: Main application server handling all requests
- Authentication: User authentication and authorization
- Redis Cache: Caching frequently accessed data
- Redis Queue: Background job processing and task queues
-
External Services
- AI Services:
- Gemini API: Text generation and processing
- Replicate API: Image generation and processing
- Storage: AWS S3/DigitalOcean Spaces for image storage
- Payment: Razorpay for payment processing
- AI Services:
-
Database Layer
- PostgreSQL database with Drizzle ORM
- Tables:
- Users: User information and credits
- Generated Images: AI-generated image metadata
- Credit Transactions: Credit purchase and usage history
-
User Authentication Flow
- Client → API → Auth → Database
- Returns JWT token for subsequent requests
-
Image Generation Flow
- Client → API → AI Services → Storage → Database
- Updates user credits after generation
-
Payment Flow
- Client → API → Razorpay → API → Database
- Updates user credits after successful payment
-
Background Processing
- API → Queue → Worker → External Services
- Handles long-running tasks asynchronously
- Node.js (v16 or higher)
- PostgreSQL
- Redis
- AWS/DigitalOcean account for storage
- Razorpay account
- Google Cloud account (for Gemini API)
- Replicate account
Create a .env
file in the root directory with the following variables:
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/metacreators
# Storage
DIGIOCEAN_OBJECT_ACCESS_ID=your_access_id
DIGIOCEAN_OBJECT_SECRET=your_secret_key
# AI Services
GEMINI_API_KEY=your_gemini_api_key
REPLICATE_API_KEY=your_replicate_api_key
# Payment
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_secret
# Redis
REDIS_URL=redis://localhost:6379
- Clone the repository:
git clone https://github.com/yourusername/metacreators-backend.git
cd metacreators-backend
- Install dependencies:
npm install
- Set up the database:
npm run db:generate # Generate migrations
npm run db:push # Push migrations to database
- Start the development server:
npm run dev
- Docker installed on your system
- Docker Compose (optional, for easier management)
Create a Docker network for the services:
docker network create backend_redis_worker_network
Start Redis container:
docker run --name lithouse-redis --network backend_redis_worker_network -d -p 6379:6379 redis
If Redis container is not on the network, connect it manually:
docker network connect backend_redis_worker_network lithouse-redis
Build the backend image:
docker build -t lithouse_backend .
Run the backend container:
docker run -d \
--network backend_redis_worker_network \
-p 3000:3000 \
-e REPLICATE_API_TOKEN="your_replicate_token" \
-e TOGETHER_API_KEY="your_together_key" \
-e GEMINI_API_KEY="your_gemini_key" \
-e VITE_SUPABASE_URL="your_supabase_url" \
-e VITE_SUPABASE_ANON_KEY="your_supabase_key" \
-e REDIS_URL="redis://lithouse-redis:6379" \
lithouse_backend
Connect to PostgreSQL database using Docker:
docker run --rm -it postgres psql "DATABASE_URL"
Create a docker-compose.yml
file:
version: '3.8'
services:
redis:
image: redis
container_name: lithouse-redis
ports:
- "6379:6379"
networks:
- backend_redis_worker_network
backend:
build: .
container_name: lithouse_backend
ports:
- "3000:3000"
environment:
- REPLICATE_API_TOKEN=${REPLICATE_API_TOKEN}
- TOGETHER_API_KEY=${TOGETHER_API_KEY}
- GEMINI_API_KEY=${GEMINI_API_KEY}
- VITE_SUPABASE_URL=${VITE_SUPABASE_URL}
- VITE_SUPABASE_ANON_KEY=${VITE_SUPABASE_ANON_KEY}
- REDIS_URL=redis://redis:6379
depends_on:
- redis
networks:
- backend_redis_worker_network
networks:
backend_redis_worker_network:
external: true
Start all services:
docker-compose up -d
Stop all services:
docker-compose down
POST /api/signup
- Create new userPOST /api/user/check
- Check if user existsPOST /api/user/addcredits
- Add credits to user account
POST /api/genpersonimage
- Generate AI imagesPOST /api/imagefinetune
- Fine-tune image generationGET /api/get-presignedurl-upload
- Get presigned URL for image uploadPOST /api/training-status
- Update training status
POST /api/razorpay/create-order
- Create Razorpay orderPOST /api/verify-payment
- Verify payment and add credits
- id (UUID, primary key)
- name (varchar)
- email (varchar, unique)
- available_credits (integer)
- totalMoneyPaidUSD (integer)
- created_at (timestamp)
- updated_at (timestamp)
- id (UUID, primary key)
- imageId (varchar, unique)
- model_id (UUID, foreign key)
- userId (UUID, foreign key)
- cloud_url (varchar)
- replicate_url (varchar)
- prompt (text)
- status (enum)
- credits_used (integer)
- created_at (timestamp)
- id (UUID, primary key)
- user_id (UUID, foreign key)
- change_amount (integer)
- reason (enum)
- created_at (timestamp)
- Price: $16 (USD) / ₹1280 (INR)
- Features:
- 50 AI Generation Minutes
- 80 iStock Credits
- 100GB Storage
- 2 Voice Clones
- Price: $27 (USD) / ₹2176 (INR)
- Features:
- 200 AI Generation Minutes
- 320 iStock Credits
- 400GB Storage
- 5 Voice Clones
- Price: $35 (USD) / ₹2800 (INR)
- Features:
- 200 AI Generation Minutes
- 320 iStock Credits
- 400GB Storage
- 5 Voice Clones
npm test
npm run db:generate # Generate new migration
npm run db:push # Apply migrations
The project uses ESLint for code linting. Run:
npm run lint
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.