Repository navigation
CLI serve mode - #6
Merged
Merged
Conversation
Add optional serve mode dependencies gated by the "serve" feature flag: - axum 0.8 for HTTP server - tower-http 0.6 for CORS and static file serving - rust-embed 8 for embedding static assets - notify-debouncer-mini 0.5 for file watching - mime_guess 2 for content-type detection - open 5 for browser opening
Add --serve, --port, --watch, and --open flags for serve mode. All arguments are gated behind the serve feature flag.
Create the foundational server module with: - mod.rs: main server loop and file scanning - assets.rs: rust-embed static file serving with SPA fallback - state.rs: AppState with RwLock for files and schema - api.rs: REST API handlers for all endpoints - watcher.rs: file system watcher with debouncing Also adds walkdir and chrono dependencies for serve feature.
Task 4 completed - WebAssets struct with rust-embed for static files: - Embeds app/dist/ with include patterns for html, js, css, wasm, svg, png, ico, json - static_handler serves embedded assets with MIME type detection - SPA fallback routes non-asset paths to index.html
Task 5 was already implemented in a previous iteration. Verified that: - AppState has RwLock<Vec<FileSource>> for files - AppState has RwLock<Option<SchemaMetadata>> for schema - ServerConfig struct has dialect, watch_dirs, metadata_url, port - AppState::new() loads initial files and schema
Task 6 API handlers were already implemented in a previous commit. All endpoints are working: - GET /api/health - health check with version - POST /api/analyze - lineage analysis - POST /api/completion - code completion items - POST /api/split - statement splitting - GET /api/files - list watched files - GET /api/schema - schema metadata - POST /api/export/:format - export to json/mermaid/html/csv/xlsx - GET /api/config - server configuration
Add logging of specific file paths when SQL files change, improving debugging experience in serve mode.
Add run_serve_mode() function that: - Checks args.serve flag at CLI entry point - Builds ServerConfig from parsed CLI arguments - Creates tokio runtime and calls server::run_server() The server URL printing and browser opening are handled by run_server() which was implemented in Task 4.
Add abstraction layer for analysis backends: - BackendAdapter interface with REST and WASM implementations - createBackendAdapter() factory with health check fallback - Update useAnalysis to support optional adapter injection - Add BackendProvider context for app-wide backend state
- Add useBackendFiles() hook to fetch /api/files and /api/schema - Integrate BackendProvider with ProjectProvider for serve mode - Create virtual backend project from server files - Make files read-only in backend mode (editor, file tree) - Show backend schema in read-only mode via SchemaEditor - Add schemaMetadataToSQL utility for displaying backend schema
- Add build-cli-serve and build-cli-serve-debug justfile targets - Add test-cli-serve target for testing with serve feature - Add cli-serve CI job that builds app then CLI with embedded UI - Document CLI serve mode build order in AGENTS.md
- Add unit tests for all API endpoints with mock state - Add integration tests for server startup and health endpoint - Add integration tests for analyze endpoint with sample SQL - Add integration tests for file watcher functionality - Create lib.rs to expose server module for testing - Add tower and reqwest dev dependencies for test infrastructure
- Add --serve usage examples to CLI README with server options table - Document REST API endpoints available in serve mode - Add build instructions for serve feature - Add troubleshooting section for common issues (port conflicts, permissions) - Document serve mode in main README for discoverability - Format generated code files
- Wire backend adapter into useAnalysis in EditorArea (CRITICAL: without this, REST mode fell back to WASM) - Add missing fields to server AnalyzeRequest (hide_ctes, enable_column_lineage, template_mode) and use them in handler - Log watcher blocking_send failures instead of silently ignoring - Add CHANGELOG entry for serve mode feature
- Bind to port before opening browser to prevent broken page if port unavailable - Fetch dialect from /api/config for backend project instead of hardcoding 'generic' - Remove unused dialect/schema_sql fields from REST analyze request - Remove unused backendType prop from Workspace component
Add ability to serve specific files or stdin input without file watching: - flowscope --serve file1.sql file2.sql (static files) - cat query.sql | flowscope --serve (stdin input) Changes: - Add static_files field to ServerConfig for non-watched files - Update run_serve_mode to read from positional args or stdin - Skip file watcher and reload for static files mode - Name stdin files as <stdin>.sql to pass frontend .sql filter - Show "Static Files" indicator in UI when watch_dirs is empty - Fix READ ONLY badge overlapping scrollbar (right-2 -> right-5) - Update tests with new ServerConfig fields
When switching projects, nodes were stacking at position (0,0) because the Stage 1 layout logic tried to preserve positions from the old project's nodes. Since new projects have different node IDs, position lookup failed and nodes kept their default (0,0) position. The fix detects project switches by checking node ID overlap: - If <50% of nodes have existing positions, treat as new graph - For incremental updates, use fast layout positions as fallback - Optimizes case where all nodes already have positions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLI Serve Mode - Embedded Web UI
This PR adds a new
--servemode to the FlowScope CLI that runs a local HTTP server with the full web UI embedded. This enables single-binary deployment where all SQL lineage analysis happens locally without requiring external services.Features
Embedded Web UI Server
flowscope --serverust-embed- no external files neededMultiple Input Modes
REST API
All analysis runs locally via REST endpoints:
/api/health/api/analyze/api/completion/api/split/api/files/api/schema/api/export/:format/api/configFile Watching
.sqlfile changes with 100ms debouncingArchitecture
Backend (Rust)
server/mod.rs- Axum HTTP server with CORS and request limitsserver/api.rs- REST API handlers using flowscope-coreserver/state.rs- Shared application state with RwLock-protected filesserver/watcher.rs- File system watcher using notify-debouncer-miniserver/assets.rs- Embedded static assets served via rust-embedFrontend (TypeScript)
BackendAdapterpattern to abstract REST vs WASM backendsuseBackendFileshook for polling/api/fileswith delta detectionBackendContextprovider for mode detection and file syncCLI Options
All existing options work in serve mode:
-d/--dialect- SQL dialect for analysis--metadata-url- Live database schema introspection-s/--schema- DDL schema file--template- Jinja/dbt template preprocessingBuild System
New justfile targets:
just build-cli-serve- Build CLI with serve feature (release)just build-cli-serve-debug- Debug build for developmentjust test-cli-serve- Run serve mode testsThe serve feature requires building the frontend first (handled automatically by justfile):
Testing
serve_api.rs) - API handler tests with mock stateserve_integration.rs) - Full HTTP request/response testingSecurity Considerations
UI Behavior
The UI in serve mode shows:
--watchTest Plan
just test-cli-servepassesflowscope --serve --watch ./sqlflowscope --serve file.sqlecho "SELECT 1" | flowscope --serveflowscope --serve --watch ./sql -d postgres --openflowscope --servewith no input shows error