4.8 KiB
4.8 KiB
Findings: Backend Integration Research
Date: 2026-01-21
Project Structure
- Package Manager: bun
- Base URL: https://api.mixvideo.bowong.cc
- Owner ID: t0m9cketSQdCA6cHXI9mXQLJPM9LDIw5
- SDK Location: node_modules/@repo/sdk
@repo/sdk Analysis
Architecture
- Pattern: Dependency Injection with Better Auth integration
- Controllers: 23 total (Activity, Template, Project, Chat, File, etc.)
- Access Methods:
- Better Auth style:
authClient.loomart.xxx - DI style:
root.get(Controller)
- Better Auth style:
Key Controllers
- TemplateController - Template CRUD, workflow execution
- CategoryController - Category management with templates
- ProjectController - Project management
- ChatController - Chat functionality
- FileController - File management
- ActivityController - Activity tracking
- TemplateSocialController - Likes, views, social features
- TemplateGenerationController - Generation tracking
- AICharacterController - AI character management
- AigcController - AIGC operations
Current State Management
Zustand Stores (Only 1)
- useCategoriesStore (hooks/use-categories.ts)
- Global cache for categories
- Has loading/error/hasLoaded states
- Prevents redundant API calls
Custom Hooks Pattern (15 hooks)
Most screens use local state via custom hooks:
- use-templates.ts - Template list with pagination
- use-template-detail.ts - Single template
- use-template-actions.ts - Like, view actions
- use-template-generations.ts - Generation history
- use-activates.ts - Activity list
- use-tags.ts - Tag management
- use-search-history.ts - Search history
API Integration Patterns
Pattern 1: Better Auth Client (Primary)
import { authClient, loomart } from '@/lib/auth'
const result = await loomart.template.list(params)
Pattern 2: DI Container
import { root } from '@repo/core'
import { TemplateController } from '@repo/sdk'
const template = root.get(TemplateController)
const result = await template.list(params)
Pattern 3: Error Handling
const { data, error } = await handleError(async () => await apiCall())
Frontend Screens Inventory
Tab Screens (5)
| Screen | Path | Needs API | SDK Support | Notes |
|---|---|---|---|---|
| Home | (tabs)/index.tsx | ✅ Categories, Templates | ✅ TemplateController, CategoryController | Has basic integration |
| Video | (tabs)/video.tsx | ✅ Video list | ✅ TemplateController | Already uses useTemplates |
| Message | (tabs)/message.tsx | ✅ Chat/messages | ❌ No list API | ChatController只有chat()和listModels(),没有消息列表接口 |
| My Profile | (tabs)/my.tsx | ✅ User data | ⚠️ 需确认 | 需要用户信息接口 |
Main Screens (15)
| Screen | Path | Needs API | Notes |
|---|---|---|---|
| Auth | auth.tsx | ✅ Login/signup | Has Better Auth |
| Membership | membership.tsx | ✅ Subscription | Needs Stripe |
| Template Detail | templateDetail.tsx | ✅ Template data | Has integration |
| Generate Video | generateVideo.tsx | ✅ Generation API | Needs progress |
| Generation Record | generationRecord.tsx | ✅ History list | Needs pagination |
| Works List | worksList.tsx | ✅ User works | Needs pagination |
| Search Template | searchTemplate.tsx | ✅ Search API | Needs debounce |
| Search Results | searchResults.tsx | ✅ Results list | Needs pagination |
| Search Works | searchWorks.tsx | ✅ Works search | Needs pagination |
| Search Works Results | searchWorksResults.tsx | ✅ Results list | Needs pagination |
| Channels | channels.tsx | ✅ Category data | Needs refresh |
| Change Password | changePassword.tsx | ✅ Auth API | Has integration |
| Privacy | privacy.tsx | ❌ Static | No API needed |
| Terms | terms.tsx | ❌ Static | No API needed |
Key Discoveries
- Minimal Global State: Only 1 Zustand store (categories), rest uses local state
- Hook-Based Architecture: 15 custom hooks handle API calls
- Existing Patterns: Some screens already have API integration
- Missing Features:
- Loading states inconsistent across screens
- No pull-to-refresh on most screens
- Pagination exists in hooks but not all screens use it
- No error retry mechanisms
- No optimistic updates
- SDK限制:
- ❌ ChatController没有消息列表接口(只有chat()和listModels())
- ❌ 没有用户信息相关的Controller
- ✅ Video页面已正确使用TemplateController(不需要单独的视频hook)
Technical Constraints
- Multi-tenant: All requests need
x-owneridheader - Authentication: Token stored in expo-secure-store
- Design Width: 375px (need to convert styles to Tailwind)
- No Redux: Project uses minimal global state approach
- Better Auth: Primary auth method, SDK integrated as plugin