How prompt-engineering/chat-flow works
Main Components
• Frontend Application (Next.js):
• Pages and Routes: Represented in src/app (e.g. [lang]/chatgpt, click-flow, flow-editor, and error pages).
• I18N: Internationalization support in src/i18n and i18n directories.
• Layout and Navigation: Layout components inside src/layout, NavBar etc.
• API / Backend Services:
• API Routes: Provided in src/api and also under src/pages/api (e.g. chat.ts, conversation.ts, user.ts, and proxy endpoints).
• Serverless functions: Next.js API endpoints that handle chat interactions and possibly middleware (src/middleware.ts).
• Flow Management System:
• Flow Editor: Managed in src/app/[lang]/flow-editor where ReactFlow is used to render the graph data.
• Flows Module: Includes flows/actions, flows/components, flows/functions and react-flow-nodes. These modules use libraries such as dot-parser and dagre for graph layout, and custom modules for handling JSON paths, math expressions, etc.
• Repl Server & UnitMesh: Code in src/flows/unitmesh which handles websocket connections using Rx.js and performs code-as-data handling.
• Data Persistence & External Services:
• Database: Uses a MySQL database that is managed via Prisma (prisma/schema.prisma) and deployed on Planetscale.
• Environment configuration: .env and scripts/scripts (e.g. gen-enc.js) for encryption key generation and environment setups.
• Deployment: Vercel deployment configuration (vercel.json, next.config.js, next-sitemap.config.js) and CI workflows (.github/workflows/ci.yaml).
Relationships and Interactions
• The Frontend connects to the backend API routes to perform chat and conversation functionalities.
• The UI directly interacts with the Flow Editor components, which in turn use the flows modules to generate or interpret the workflow graphs.
• The flows system leverages a separation between user interactions (click-flow, flow-editor pages) and the underlying business logic (flow-actions, flow-functions) to convert chat instructions into automated workflows.
• The API layer mediates database interactions through Prisma (see src/storage for Planetscale integration) and exposes endpoints for chat, conversation, and user management.
• There is a clear coordination between internal asynchronous modules (for example, the ReplService for real-time operations) and external services (Planetscale for data persistence, Vercel for hosting).
Architectural Patterns and Design Principles
• Separation of concerns: Frontend (UI components, pages) is clearly separated from backend API logic and flow processing.
• Modular design: The project is partitioned into small, domain-specific modules (flows, components, API, storage, configurations).
• React and Next.js conventions: Utilizing Next.js routing, serverless functions, and built-in middleware for better scalability.
• Graph-based workflow design: Using flowchart layout libraries (ReactFlow, dagre) and node-based architectures to visually construct chat automation.
• Internationalization (i18n): Language assets and README guidance (README.zh-CN.md, i18n directory) point to a design that supports multi-language deployment.