StudioBot.ai is a microservice-ready Node.js/TypeScript application that automates video content creation and multi-platform distribution. The architecture follows clean layering principles with clear separation of concerns.
┌─────────────────────────────────────────────────────────────┐
│ Client Applications │
│ (Web, Mobile, Desktop, Third-party) │
└────────────────────────┬────────────────────────────────────┘
│ HTTP/REST
┌────────────────────────▼────────────────────────────────────┐
│ Express.js Server │
│ (Port 3000) │
├─────────────────────────────────────────────────────────────┤
│ Middleware Layer │
│ - CORS, Body Parser, Error Handler │
├─────────────────────────────────────────────────────────────┤
│ Route Layer │
│ - /auth (Authentication) │
│ - /videos (Video Upload & Analysis) │
│ - /clips (Clip Management) │
│ - /shorts (Short Form Content) │
│ - /thumbnails (Thumbnail Generation) │
│ - /platforms (Multi-Platform Distribution) │
├─────────────────────────────────────────────────────────────┤
│ Service Layer (Business Logic) │
│ - AuthService → User Management │
│ - VideoService → Video Processing & AI Analysis │
│ - ClipService → Clip Extraction │
│ - ShortService → Vertical Format Conversion │
│ - ThumbnailService → Image Generation │
│ - PlatformService → API Integration │
├─────────────────────────────────────────────────────────────┤
│ Data Layer │
│ - SQLite3 Database │
│ - Type Definitions │
│ - Utilities (Logger, Error Handler) │
├─────────────────────────────────────────────────────────────┤
│ External Integrations │
│ - FFmpeg (Video Processing) │
│ - YouTube API │
│ - Twitch API │
│ - Rumble API │
│ - File System (Local Storage) │
└─────────────────────────────────────────────────────────────┘
Located in src/routes/
Responsibilities:
- Handle HTTP requests and responses
- Validate input parameters
- Route requests to appropriate services
- Return formatted API responses
Files:
auth.routes.ts- Authentication endpointsvideo.routes.ts- Video managementclip.routes.ts- Clip operationsshort.routes.ts- Short form contentthumbnail.routes.ts- Thumbnail operationsplatform.routes.ts- Platform integration
Located in src/services/
Responsibilities:
- Implement core business logic
- Coordinate between routes and data layer
- Handle async operations
- Manage external API calls
- Process videos and generate content
Services:
- AuthService: User registration, login, profile management
- VideoService: Download, analyze videos, detect viral moments
- ClipService: Extract video segments, manage clips
- ShortService: Convert clips to vertical format
- ThumbnailService: Generate preview images
- PlatformService: Publish to YouTube, Twitch, Rumble
Located in src/database/
Responsibilities:
- Database schema initialization
- Execute database queries
- Data persistence and retrieval
Files:
init.ts- SQLite initialization and schema
Located in src/utils/ and src/middleware/
Utilities:
- logger.ts - Structured logging for debugging
- errorHandler.ts - Centralized error handling
Middleware:
- Request validation
- Error catching
- Response formatting
Located in src/types/
Files:
models.ts- TypeScript interfaces for all entities
┌─────────────┐
│ Client │
│ POST /videos│
│ /upload │
└──────┬──────┘
│
▼
┌─────────────────────┐
│ VideoRoute │
│ - Validate input │
│ - Create video ID │
└──────┬──────────────┘
│
▼
┌──────────────────────┐ ┌──────────────┐
│ VideoService │─────▶│ Database │
│ - Save to DB │ │ (Insert) │
│ - Start async job │ └──────────────┘
└──────┬───────────────┘
│
▼
┌──────────────────────┐
│ Background Process │
│ 1. Download from URL │
│ 2. Run AI Analysis │
│ 3. Extract keyframes │
│ 4. Update DB status │
└──────────────────────┘
┌──────────────┐
│ User creates │
│ clip │
└────┬─────────┘
│
▼
┌──────────────────┐ ┌──────────────┐
│ ClipRoute │───────▶│ Database │
│ POST /clips/ │ │ (Insert) │
│ create │ └──────────────┘
└────┬─────────────┘
│
▼
┌──────────────────┐
│ ClipService │
│ - Extract segment│
│ - Generate output│
│ - Update status │
└────┬─────────────┘
│
▼
┌──────────────────┐ ┌──────────────────┐
│ User approves │───────▶│ ShortService │
│ clip │ │ - Convert format │
└────┬─────────────┘ └────┬─────────────┘
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Thumbnail │ │ PlatformService │
│ Generation │ │ - Publish to API │
└──────────────────┘ └──────────────────┘
┌──────────────┐
│ Users │
├──────────────┤
│ id (PK) │
│ username │
│ email │
│ password_hash│
└──────┬───────┘
│
│ 1:N
│
├──────────────────────────┬──────────────┬──────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Videos │ │ Platforms │ │ Clips │ │ Shorts │
├──────────────┤ ├──────────────┤ ├──────────────┤ ├──────────────┤
│ id (PK) │ │ id (PK) │ │ id (PK) │ │ id (PK) │
│ user_id (FK) │ │ user_id (FK) │ │ video_id (FK)│ │ clip_id (FK) │
│ title │ │ platform_name│ │ user_id (FK) │ │ user_id (FK) │
│ source_url │ │ access_token │ │ title │ │ title │
│ local_path │ │ channel_id │ │ start_time │ │ resolution │
│ status │ │ is_connected │ │ end_time │ │ status │
│ analysis_data│ └──────┬───────┘ │ status │ │ approved │
└──────┬───────┘ │ │ approved │ └──────┬───────┘
│ │ └──────┬───────┘ │
│ │ │ │
└─────────────────────┼─────────────────┼────────────────┘
│ │
└────────┬────────┘
│
│ N:N (through Distributions)
│
▼
┌──────────────────┐
│ Distributions │
├──────────────────┤
│ id (PK) │
│ content_id (FK) │
│ content_type │
│ platform_name │
│ platform_post_id │
│ status │
│ published_at │
│ url │
│ view_count │
└──────────────────┘
Thumbnails table (standalone, referenced by videos/clips/shorts)
┌──────────────────┐
│ Thumbnails │
├──────────────────┤
│ id (PK) │
│ source_id (FK) │
│ source_type │
│ output_path │
│ status │
└──────────────────┘
AuthService
├── registerUser(username, email, password)
├── loginUser(email, password)
├── getUser(userId)
├── updateUser(userId, updates)
├── changePassword(userId, oldPwd, newPwd)
├── hashPassword(password)
├── verifyPassword(password, hash)
└── generateToken(userId, email)
VideoService
├── createVideo(video)
├── getVideoById(videoId)
├── getUserVideos(userId, page, limit)
├── updateVideo(videoId, updates)
├── deleteVideo(videoId)
├── downloadAndAnalyzeVideo(videoId)
├── getVideoAnalysis(videoId)
├── downloadFile(url, filePath)
└── analyzeVideo(videoPath)
ClipService
├── createClip(clip)
├── getClipById(clipId)
├── getVideoClips(videoId, page, limit)
├── approveClip(clipId, approved, notes)
├── deleteClip(clipId)
├── processClip(clipId)
└── simulateClipGeneration(outputPath)
ShortService
├── createShort(short)
├── getShortById(shortId)
├── getUserShorts(userId, page, limit)
├── approveShort(shortId, approved)
├── deleteShort(shortId)
├── convertClipToShort(clipId, userId, title, description)
└── processShortConversion(shortId, inputPath, outputPath)
ThumbnailService
├── createThumbnail(thumbnail)
├── getThumbnailById(thumbnailId)
├── getThumbnailsForSource(sourceId)
├── getThumbnailFilePath(thumbnailId)
├── deleteThumbnail(thumbnailId)
├── generateThumbnail(thumbnailId, timestamp)
└── simulateThumbnailGeneration(outputPath)
PlatformService
├── connectPlatform(userId, platformName, credentials)
├── getUserPlatforms(userId)
├── publishContent(userId, platformName, contentId, contentType, metadata)
├── getDistributionHistory(contentId)
├── getAnalytics(userId, platformName)
├── disconnectPlatform(platformId)
└── publishToProvider(platformName, contentId, contentType, distributionId, metadata)
1. Client sends HTTP request
↓
2. Express receives request
↓
3. Middleware processes (CORS, Body Parser)
↓
4. Route handler validates input
↓
5. Service processes business logic
↓
6. Database query executed
↓
7. Result formatted as JSON
↓
8. Response sent to client (200/201)
1. Error occurs in service
↓
2. Thrown as AppError with statusCode
↓
3. Caught by catchAsync middleware wrapper
↓
4. Passed to errorHandler middleware
↓
5. Formatted as standardized error response
↓
6. Sent to client with appropriate HTTP code
Jobs that run in the background:
-
Video Download & Analysis
- Triggered after: Video upload
- Duration: Minutes to hours
- Status updates:
pending→downloading→analyzing→analyzed
-
Clip Processing
- Triggered after: Clip creation
- Duration: Seconds to minutes
- Status updates:
pending→processing→ready
-
Short Conversion
- Triggered after: Clip approval
- Duration: Seconds to minutes
- Status updates:
pending→processing→ready
-
Thumbnail Generation
- Triggered after: Thumbnail request
- Duration: Seconds
- Status updates:
pending→processing→ready
-
Platform Publishing
- Triggered after: Publish request
- Duration: Seconds to minutes
- Status updates:
pending→publishing→published
- Endpoint validation in routes
- Type checking with TypeScript
- Email format validation
- Password strength requirements (min 8 chars)
- Password hashing with SHA-256 (production should use bcrypt)
- Database encryption (optional for platform credentials)
- Secure file permissions for database
- No sensitive data in error messages
- Logging without credentials
- Standard error response format
- Async Processing: Video processing doesn't block requests
- Database Indexing: Indexes on foreign keys and frequently queried fields
- Streaming: Large file downloads use streams
- Caching: Consider caching popular analysis results
- Pagination: List endpoints support pagination
- Horizontal Scaling: Add more servers behind load balancer
- Queue System: Use Bull or RabbitMQ for background jobs
- Database: Migrate to PostgreSQL for production
- Storage: Move media to cloud storage (S3, Google Cloud)
- Caching: Add Redis for session/analysis caching
- Microservices: Split into separate services as needed
| Bottleneck | Issue | Solution |
|---|---|---|
| Video Processing | FFmpeg CPU intensive | Queue system, worker processes |
| Database Locks | SQLite concurrent writes | PostgreSQL or sharding |
| Storage | Local disk space | Cloud storage integration |
| API Rate Limits | Platform throttling | Retry logic, caching |
| Memory | Large video files | Streaming, chunked processing |
Local Machine
├── Express Server
├── SQLite Database
├── Local File Storage
└── FFmpeg (local)
Load Balancer
├── Server 1 (Express + Node)
├── Server 2 (Express + Node)
├── Server 3 (Express + Node)
│
├── Database Cluster (PostgreSQL)
├── Redis Cache
├── Cloud Storage (S3/GCS)
├── Message Queue (RabbitMQ/SQS)
│
└── Worker Servers
├── Video Processor
├── Thumbnail Generator
├── Platform Publisher
└── Analytics Updater
- GraphQL API: Support for more flexible queries
- WebSocket Support: Real-time status updates
- Event Streaming: Kafka for event sourcing
- Serverless: AWS Lambda for scalability
- Containerization: Full Kubernetes support
- API Gateway: Rate limiting, authentication
- Monitoring: Prometheus + Grafana dashboards
- Distributed Tracing: Jaeger integration
For implementation details, see individual service files in src/services/.