-
Notifications
You must be signed in to change notification settings - Fork 1
Migrate monitor features from NiceGUI to frontend #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate monitor features from NiceGUI to frontend #19
Conversation
Changes: - Remove main branch push trigger from docker-build.yml - Now Docker images are built only when version tags are pushed - This aligns with the bump-version.sh workflow where tags are created - Keep PR and manual workflow_dispatch triggers for testing Also remove unused demo_curl.sh script: - Script was not referenced in any documentation - No longer needed for the project
This commit migrates all task monitoring features from NiceGUI to the React frontend: ## New UI Components - Dialog: Modal component for task details - Input: Text input component - Textarea: Multi-line text input - Select: Dropdown select component - Label: Form label component ## Enhanced Tasks Page Features 1. **File Upload**: Upload single files (max 50KB) for processing - Auto-detect file type based on extension - Real-time upload progress - Size validation with helpful error messages 2. **Directory Batch Processing**: Process multiple files from a directory - Directory path input - File pattern filtering (wildcards supported) - Background task creation 3. **Task Details Modal**: Comprehensive task information display - Basic info: Task ID, status, progress - Timing info: Created, started, completed timestamps - Status messages and error details - Metadata JSON viewer 4. **Task Management**: - Cancel button for pending/running tasks - Status filter dropdown (All, Pending, Running, Success, Failed, Cancelled) - Real-time task status updates (3s interval) 5. **Enhanced Task Cards**: - Progress bars for running tasks - Status icons and badges - Error message display - Action buttons (Details, Cancel) ## API Updates - Added processDocument endpoint for file uploads - Added processDirectory endpoint for batch processing - Enhanced TypeScript interfaces for better type safety This completes Phase 2 of the NiceGUI migration. All monitoring features from the NiceGUI interface have been successfully replicated in React with improved UX and better performance. Next: Phase 3 will remove NiceGUI dependencies from the backend.
## Phase 3: Remove NiceGUI Dependencies ### Backend Changes - **Deleted**: `monitoring/task_monitor.py` (712 lines) - NiceGUI monitoring module - **Modified**: `core/app.py` - Removed NiceGUI integration, now points to React frontend - **Modified**: `pyproject.toml` - Removed `nicegui>=2.19.0` and `matplotlib>=3.10.3` - **Modified**: `config.py` - Removed monitoring configuration options - **Modified**: `env.example` - Removed ENABLE_MONITORING and MONITORING_PATH variables ### Changes Summary - All task monitoring now handled by React frontend at `/tasks` - Reduced backend dependencies - Cleaner separation of concerns - Removed 700+ lines of Python UI code ## Vitest Testing Framework Setup ### Testing Infrastructure - **Added**: Vitest v1.6.0 as test runner - **Added**: React Testing Library v15.0.7 for component testing - **Added**: @testing-library/jest-dom v6.4.5 for assertions - **Added**: @testing-library/user-event v14.5.2 for interactions - **Added**: jsdom v24.1.0 for DOM environment - **Added**: @vitest/coverage-v8 for coverage reports - **Added**: @vitest/ui v1.6.0 for interactive test UI ### Configuration Files - `frontend/vitest.config.ts` - Vitest configuration with jsdom environment - `frontend/src/test/setup.ts` - Test setup with cleanup utilities - `frontend/TEST.md` - Comprehensive testing guide ### Test Files Created (5 test suites) 1. **Button Component Tests**: `src/components/ui/button.test.tsx` - Rendering, click events, disabled state, variants, sizes 2. **Badge Component Tests**: `src/components/ui/badge.test.tsx` - Rendering, variant classes (success, destructive, warning) 3. **Input Component Tests**: `src/components/ui/input.test.tsx` - User input, disabled state, different input types 4. **Utils Tests**: `src/lib/utils.test.ts` - cn(), formatBytes(), formatDuration(), formatNumber() 5. **API Tests**: `src/lib/api.test.ts` - taskApi.listTasks(), taskApi.getStatus(), taskApi.cancelTask() - healthApi.check() with axios mocking ### NPM Scripts Added ```bash npm test # Run tests in watch mode npm run test:ui # Run tests with UI npm run test:coverage # Generate coverage report ``` ### Test Coverage - Components: 5 test files covering UI components - Utils: Complete coverage of utility functions - API: Mocked API tests for all endpoints ## Benefits ### NiceGUI Removal - ✅ Reduced backend complexity - ✅ Removed 2 heavy dependencies (nicegui, matplotlib) - ✅ Better frontend/backend separation - ✅ Consistent monitoring via React frontend ### Vitest Addition - ✅ Fast test execution with Vite-native runner - ✅ TypeScript support out of the box - ✅ Interactive test UI for debugging - ✅ Coverage reports with v8 - ✅ Foundation for TDD and CI/CD ## Next Steps - Phase 4: Update README documentation - Run `cd frontend && npm install` to install new test dependencies - Run `npm test` to execute test suite
## Critical Docker Build Issues Fixed
### Problems Identified
1. ❌ Builder stage copied deleted `monitoring` directory
2. ❌ Used `uv pip install --system .` without complete source code
3. ❌ Copied entire `/usr/local/site-packages` and `/usr/local/bin` (layer explosion)
4. ❌ `COPY . .` included `.git/`, `node_modules/`, `.venv/` in image
5. ❌ Slow export due to massive layer compression
### Solution: Proper Two-Stage Build
#### Builder Stage (Wheels Only)
- **Purpose**: Compile all dependencies as wheels
- **Input**: `requirements.txt` (generated from pyproject.toml)
- **Output**: `/wheelhouse` directory with all wheels
- **Benefits**:
- No source code needed
- Build dependencies stay in builder
- Faster, repeatable builds
- Cache-friendly with `--mount=type=cache`
#### Runtime Stage (Clean Install)
- **Purpose**: Install pre-built wheels + application code
- **Input**: Wheels from builder + precise source files
- **Output**: Minimal production image
- **Benefits**:
- Smaller image size (no build-essential, no uv)
- Better security (fewer packages)
- Faster layer export
- Precise file copying (no junk)
### Changes Made
#### 1. Generated `requirements.txt`
```bash
uv pip compile pyproject.toml -o requirements.txt
```
- 162 packages resolved
- Locked versions for reproducibility
- No dynamic version resolution in Docker
#### 2. Updated `.dockerignore`
```diff
# Documentation
+docs/
*.md
-docs/
+!README.md
+!README_CN.md
```
- Allow README.md for pyproject.toml metadata
- Block everything else (.git, node_modules, .venv)
#### 3. Rewrote All 3 Dockerfiles
**Dockerfile.minimal, Dockerfile.standard, Dockerfile.full**
**Builder Stage:**
```dockerfile
# Build wheels from requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip wheel -r requirements.txt -w /wheelhouse
```
**Runtime Stage:**
```dockerfile
# Install from local wheels (no network, fast)
RUN pip install --no-index --find-links=/wheelhouse -r requirements.txt
# Precise file copying (no `COPY . .`)
COPY --chown=appuser:appuser README.md ./
COPY --chown=appuser:appuser pyproject.toml ./
COPY --chown=appuser:appuser api ./api
COPY --chown=appuser:appuser core ./core
COPY --chown=appuser:appuser services ./services
COPY --chown=appuser:appuser mcp_tools ./mcp_tools
COPY --chown=appuser:appuser start.py start_mcp.py mcp_server.py config.py main.py ./
```
### Benefits Achieved
#### Performance
- ⚡ **Faster builds**: Wheels cached, no repeated compilation
- ⚡ **Faster exports**: Smaller layers, faster compression
- ⚡ **Better caching**: Requirement changes don't rebuild code
#### Size
- 📦 **Smaller images**: No build-essential, uv, or source junk
- 📦 **Precise layers**: Only production code included
#### Reliability
- ✅ **Reproducible**: Locked requirements.txt
- ✅ **No ABI issues**: Same Python version for builder & runtime
- ✅ **Stable**: No dynamic version resolution
#### Security
- 🔒 **Smaller attack surface**: Fewer packages in runtime
- 🔒 **No build tools**: gcc, make, etc. not in production image
### Testing
Recommended test command:
```bash
docker build -f docker/Dockerfile.minimal -t test-minimal .
docker build -f docker/Dockerfile.standard -t test-standard .
docker build -f docker/Dockerfile.full -t test-full .
```
### Files Changed
- `requirements.txt` - NEW: 162 locked dependencies
- `.dockerignore` - Allow README.md, block more
- `docker/Dockerfile.minimal` - Complete rewrite
- `docker/Dockerfile.standard` - Complete rewrite
- `docker/Dockerfile.full` - Complete rewrite
All three Dockerfiles now use identical build pattern, only differ in CMD.
Runtime images don't need README.md or pyproject.toml: - README.md: Only for humans, not needed in production - pyproject.toml: Only for installation, we use requirements.txt Benefits: - Smaller image size - Fewer files in container - Cleaner image contents Changes: - .dockerignore: Remove !README.md and !README_CN.md exceptions - All Dockerfiles: Remove COPY README.md and COPY pyproject.toml - Runtime only includes actual Python code needed to run
Backend Docker images don't need frontend code: - frontend/ directory contains React app - Only needed for separate frontend build - Reduces Docker build context size - Faster uploads to build server Current Docker images are backend-only (FastAPI + Python services)
Properly integrate the React frontend into the Docker build process to enable the monitoring UI in production deployments. Changes: - FastAPI: Add SPA routing with fallback to index.html for client-side routing - FastAPI: Mount /assets for static files (JS, CSS, images) - FastAPI: Graceful fallback when frontend not built - Docker: Add frontend-builder stage to all three Dockerfiles - Docker: Use Node.js 20 to build React app with npm ci - Docker: Copy built frontend from dist/ to runtime's /app/static - .dockerignore: Allow frontend source but exclude dev artifacts (node_modules, dist, .vite, coverage) This enables users to access the React monitoring UI at /tasks when running the Docker containers, resolving the deployment gap identified in the NiceGUI migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Lines 373 to 384 in e2832aa
| @router.get("/config") | |
| async def get_system_config(): | |
| """Get system configuration""" | |
| try: | |
| return { | |
| "app_name": settings.app_name, | |
| "version": settings.app_version, | |
| "debug": settings.debug, | |
| "llm_provider": settings.llm_provider, | |
| "embedding_provider": settings.embedding_provider, | |
| "monitoring_enabled": settings.enable_monitoring | |
| } |
The commit deletes enable_monitoring from Settings, but the /api/v1/config handler still returns "monitoring_enabled": settings.enable_monitoring. With the attribute gone, any request to /api/v1/config raises an AttributeError, yielding a 500 instead of the configuration payload. This regression breaks the frontend’s ability to read configuration and should be updated to drop or replace the flag.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| cancelTask: (taskId: string) => | ||
| api.post(`/tasks/${taskId}/cancel`), | ||
|
|
||
| processDocument: (data: ProcessDocumentRequest) => | ||
| api.post<ProcessDocumentResponse>('/documents/process', data), | ||
|
|
||
| processDirectory: (data: ProcessDirectoryRequest) => | ||
| api.post<ProcessDirectoryResponse>('/documents/process-directory', data), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New task UI calls document APIs that do not exist
The newly added taskApi.processDocument and taskApi.processDirectory methods invoke /documents/process and /documents/process-directory. The backend still exposes document ingestion at /documents, /documents/file, and /documents/directory; no routes were added for the new paths. As a result, the file upload and directory processing flows in the Tasks page will consistently receive 404 responses and never create tasks. These API paths need to be aligned with the existing server routes or implemented server‑side.
Useful? React with 👍 / 👎.
This pull request introduces a major refactor to the Docker build process and frontend integration, removes the NiceGUI-based monitoring interface, and adds comprehensive frontend testing support. The most important changes are grouped below.
Docker build system and frontend integration:
docker/Dockerfile.full,docker/Dockerfile.standard,docker/Dockerfile.minimal) to use multi-stage builds: Python dependencies are built as wheels in a builder stage, the React frontend is built in a separate Node.js stage, and the final runtime image installs dependencies and copies only necessary code and built frontend assets. This results in smaller, faster, and more reliable builds. [1] [2] [3]/staticdirectory if present, with proper asset mounting and SPA fallback routing. If the frontend is not built, a warning and instructions are shown at the root endpoint.Monitoring and configuration changes:
ENABLE_MONITORING,MONITORING_PATH) from code, config, and environment files. Monitoring status is no longer reported in system info. [1] [2] [3]Frontend testing support:
frontend/package.jsonand introduced npm scripts for running tests, coverage, and UI test runner. [1] [2]frontend/TEST.mdwith detailed documentation for running, writing, and structuring frontend tests using Vitest and React Testing Library.Miscellaneous improvements:
.dockerignoreto exclude frontend build artifacts and allow source files, improving Docker build context efficiency. [1] [2]