This document provides essential information for LLM agents working with the ComfyUI Station codebase.
ComfyUI Station is a comprehensive management platform for ComfyUI instances, built with modern web technologies. It provides:
- Multi-instance ComfyUI management
- Workflow execution and monitoring
- Resource tracking and optimization
- User and permission management
- AI-powered assistance
- Internationalization support
app/
├── [locale]/ # Internationalized routes
│ ├── layout.tsx # Root layout with providers
│ └── ... # Page components
├── api/ # API routes
└── manifest.ts # App manifest
components/
├── ui/ # Base UI components (Radix UI)
├── ui-ext/ # Extended UI components
└── ... # Feature-specific components
hooks/ # Custom React hooks
states/ # Global state management (Zustand)
utils/ # Utility functions
server/
├── routers/ # tRPC route handlers
├── services/ # Business logic
├── handlers/ # Request handlers
├── middlewares/ # Custom middlewares
└── workers/ # Background workers
entities/
├── repositories/ # Database repositories
└── *.ts # MikroORM entities
## Build Configuration
### Next.js Configuration
- Standalone output for optimal production deployment
- React compiler optimization in production
- Internationalization with next-intl
- Memory-optimized webpack cache configuration
-
Frontend
- Next.js 15 (React 19)
- TypeScript
- TailwindCSS
- Radix UI
- next-intl
- React Query
- Zustand
-
Backend
- Bun runtime
- Elysia
- tRPC
- MikroORM + LibSQL
- LangChain
- Client → tRPC Router → Service → Repository → Database
- Changes trigger real-time updates via state management
- Presentational components in
components/
- Business logic in hooks and services
- Global state in
states/
- Entities define data structure
- Repositories handle data access
- MikroORM manages relationships
- NextAuth.js for authentication
- Token-based API access
- Role-based permissions
- Keep locale strings in
languages/
directory - Update entity schemas in
entities/
- Follow component directory structure
- Place new endpoints in appropriate tRPC routers
// Component Pattern
export function ComponentName({ prop1, prop2 }: Props) {
// Use hooks at the top
const someState = useYourHook()
// Business logic in the middle
const handleSomething = () => {
// Implementation
}
// Render at the bottom
return (
// JSX
)
}
// Service Pattern
export class YourService {
constructor(private repository: Repository) {}
async performAction() {
// Implementation with error handling
try {
return await this.repository.action()
} catch (error) {
// Error handling
}
}
}
app/[locale]/layout.tsx
- Root layout with providersserver/trpc.ts
- tRPC configurationmikro-orm.config.ts
- Database configurationstates/*.ts
- Global state managementnext.config.js
- Next.js and build configuration- Internationalization setup
- Production optimizations
- Webpack configurations:
- Memory cache settings
- Node.js polyfills
- ts-morph optimization
components/ui/*
- Base UI components
-
Adding New Features
- Create component(s) in appropriate directory
- Add needed database entities
- Implement tRPC endpoints
- Update translations
-
Modifying Workflows
- Check
entities/workflow.ts
- Update corresponding services
- Consider real-time updates
- Check
-
UI Changes
- Use Radix UI components as base
- Follow TailwindCSS patterns
- Consider mobile responsiveness
-
API Endpoints
- Add to appropriate tRPC router
- Implement service logic
- Add input validation
- Consider error handling
-
Local Development
bun dev # Start all services bun dev:next # Frontend only bun dev:trpc # Backend only
-
Database Changes
bun mikro migration:create # Create migration bun mikro migration:up # Apply migrations
-
Code Quality
bun lint # Run ESLint bun format # Run Prettier
Always use proper error handling patterns:
try {
await someOperation()
} catch (error) {
if (error instanceof KnownError) {
// Handle known error
} else {
// Log and handle unexpected error
}
}
- Use React Query for data fetching
- Implement proper data pagination
- Optimize database queries
- Consider caching strategies
- Lazy load components when possible
- Always validate user input
- Use proper authentication checks
- Implement rate limiting
- Follow CORS policies
- Handle sensitive data properly
This overview should help LLM agents understand the project structure and maintain consistency while working with the codebase.