This backend API is designed to support the Pixelar frontend application, providing:
- User authentication and management (Firebase Auth + Firestore)
- Project management (sprites and scenes)
- Asset storage and metadata (Vercel Blob)
- AI generation job tracking
- Credits system
npm installCopy .env.example to .env and configure:
# Firebase Configuration (if not using service account JSON file)
FIREBASE_PROJECT_ID=pixelar-webapp
FIREBASE_PRIVATE_KEY="..."
FIREBASE_CLIENT_EMAIL="..."
# Vercel Blob Storage
BLOB_READ_WRITE_TOKEN=your_token_here
# Server Configuration
PORT=3001
NODE_ENV=development
FRONTEND_URL=http://localhost:3000npm run devThe API will be available at http://localhost:3001
npm run build
npm startThis backend can be deployed to Firebase Cloud Run:
- Build the Docker image
- Deploy to Cloud Run
- Set environment variables in Cloud Run console
Alternatively, you can deploy as Firebase Functions (requires additional configuration).
All TypeScript types are available in types/:
types/database.types.ts- Database entity typestypes/blob-storage.types.ts- Blob storage types
| Collection | Purpose | Key Relationships |
|---|---|---|
users |
User accounts and authentication | → projects, generation_jobs, credits_transactions |
projects |
Sprite/scene projects | → assets, generation_jobs |
assets |
File metadata | → projects, users |
generation_jobs |
AI generation tracking | → users, projects, assets |
credits_transactions |
Credit usage history | → users, generation_jobs |
See schemas/firestore-collections.ts for collection names and required indexes.
Vercel Blob:
├── users/{userId}/
│ ├── avatar/
│ ├── projects/{projectId}/
│ │ ├── sprites/
│ │ ├── scenes/
│ │ ├── references/
│ │ ├── poses/
│ │ └── exports/
│ └── temp/
- Firebase Authentication integration
- Subscription plans (free, pro, enterprise)
- Credits system with transaction history
- Profile management
- Support for sprite and scene projects
- Flexible settings via JSONB
- Status tracking (draft, active, archived, deleted)
- Thumbnail management
- Metadata storage in database
- Actual files in Vercel Blob
- Support for multiple asset types
- Variant tracking for scenes
- Job tracking with status
- Input parameter storage
- Output asset linking
- Credit cost tracking
Backend/
├── api/
│ ├── index.ts # Express server entry point
│ └── routes/
│ └── auth.routes.ts # Authentication routes
├── lib/
│ ├── auth.ts # Firebase Auth utilities
│ ├── blob.ts # Vercel Blob service
│ └── db.ts # Firestore connection
├── services/
│ ├── user.service.ts # User business logic
│ └── project.service.ts # Project business logic
├── schemas/
│ └── firestore-collections.ts # Firestore collection definitions
├── types/
│ ├── database.types.ts # Database TypeScript types
│ └── blob-storage.types.ts # Blob storage TypeScript types
└── README.md # This file
POST /api/auth/sync-user- Sync user from Firebase Auth to FirestoreGET /api/auth/me- Get current user by Firebase token
GET /health- Server health check
- User signs in with Firebase Auth (frontend)
- Frontend calls
POST /api/auth/sync-userwith user data - Backend creates/updates user in Firestore
- Returns user data to frontend
- User creates project via API
- Generate thumbnail and upload to Vercel Blob
- Update project with thumbnail URL
- Generate sprite via AI generation job
- Upload result to Vercel Blob
- Create asset record in Firestore
import { UserService } from './services/user.service';
import { ProjectService } from './services/project.service';
// Create a user
const user = await UserService.create({
firebase_uid: 'firebase-uid',
email: 'user@example.com',
display_name: 'John Doe',
provider: 'google',
});
// Create a project
const project = await ProjectService.create({
user_id: user.id,
title: 'My Sprite',
type: 'sprite',
settings: {
style: 'pixel_art',
dimensions: '64x64'
}
});