Spaces:
Sleeping
Frontend Documentation
This document provides an overview of the frontend architecture and components for the AI Maker Space project.
Project Structure
frontend/
βββ public/ # Static assets
βββ src/ # Source code
β βββ components/ # React components
β βββ utils/ # Utility functions
β βββ App.jsx # Main application component
β βββ App.css # Application styles
β βββ index.css # Global styles
β βββ main.jsx # Application entry point
βββ .env # Environment variables (not in repo)
βββ index.html # HTML template
βββ package.json # Dependencies and scripts
βββ vite.config.js # Vite configuration
Core Components
App Component
The App.jsx
component serves as the main container for the application. It manages:
- Application state for file upload status
- Conditional rendering of components based on application state
- Overall layout and structure
FileUploader Component
The FileUploader.jsx
component handles:
- File selection via input element
- File upload to the backend API
- Upload status feedback
- Success callback to trigger chat mode
ChatBox Component
The ChatBox.jsx
component provides:
- Text input for questions
- API endpoint selection (RAG or Agent)
- Streaming response handling
- Response display
Environment Configuration
The application uses environment variables for configuration. See .env.template
for required variables:
VITE_API_URL
- URL of the backend API (defaults to http://localhost:7860)
Development Setup
- Clone the repository
- Create a
.env
file based on.env.template
- Install dependencies:
npm install
- Run the development server:
npm run dev
Building for Production
To build the application for production:
npm run build
This will generate optimized static files in the dist
directory.
Customization Points
The template includes several TODO comments indicating areas for customization:
- Branding: Replace the logo and application title in
App.jsx
- FileUploader: Customize or replace the file upload component
- ChatBox: Modify the chat interface to match your specific use case
- API Endpoints: Update the API endpoints in the components to match your backend
API Integration
The frontend communicates with the backend through the following endpoints:
POST /upload
- Upload documents for processingPOST /ask
- Query the knowledge basePOST /agent
- Execute an agent
Styling
The application uses CSS for styling:
App.css
- Component-specific stylesindex.css
- Global styles and CSS variables
Testing
The application includes data-testid attributes for testing purposes. You can use these with testing libraries like React Testing Library.
Architecture Notes
- The application uses React 19 with Vite for fast development
- Components are functional and use React hooks for state management
- The application supports streaming responses from the backend
- The UI adapts based on whether a file has been uploaded