docs(frontend): add comprehensive README with setup instructions
- Installation and development guide - Project structure documentation - API endpoints reference - Troubleshooting section
This commit is contained in:
@@ -1,73 +1,157 @@
|
|||||||
# React + TypeScript + Vite
|
# AgenticRAG Frontend
|
||||||
|
|
||||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
Modern React-based web interface for AgenticRAG - Agentic Retrieval System powered by datapizza-ai.
|
||||||
|
|
||||||
Currently, two official plugins are available:
|
## 🚀 Features
|
||||||
|
|
||||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
- **Authentication**: API Key-based login
|
||||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
- **Dashboard**: System overview with stats and recent documents
|
||||||
|
- **Documents**: Drag & drop upload, document management
|
||||||
|
- **Chat**: Conversational interface with RAG and source citations
|
||||||
|
- **Settings**: Theme toggle (light/dark), LLM provider selection
|
||||||
|
- **Responsive**: Mobile-friendly design
|
||||||
|
|
||||||
## React Compiler
|
## 🛠️ Tech Stack
|
||||||
|
|
||||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
- **React 18** - UI library
|
||||||
|
- **TypeScript** - Type safety
|
||||||
|
- **Vite** - Build tool
|
||||||
|
- **Tailwind CSS** - Styling
|
||||||
|
- **shadcn/ui** - UI components
|
||||||
|
- **Zustand** - State management
|
||||||
|
- **Axios** - HTTP client
|
||||||
|
- **React Router** - Routing
|
||||||
|
|
||||||
## Expanding the ESLint configuration
|
## 📦 Installation
|
||||||
|
|
||||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
```bash
|
||||||
|
cd frontend
|
||||||
```js
|
npm install
|
||||||
export default defineConfig([
|
|
||||||
globalIgnores(['dist']),
|
|
||||||
{
|
|
||||||
files: ['**/*.{ts,tsx}'],
|
|
||||||
extends: [
|
|
||||||
// Other configs...
|
|
||||||
|
|
||||||
// Remove tseslint.configs.recommended and replace with this
|
|
||||||
tseslint.configs.recommendedTypeChecked,
|
|
||||||
// Alternatively, use this for stricter rules
|
|
||||||
tseslint.configs.strictTypeChecked,
|
|
||||||
// Optionally, add this for stylistic rules
|
|
||||||
tseslint.configs.stylisticTypeChecked,
|
|
||||||
|
|
||||||
// Other configs...
|
|
||||||
],
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
||||||
tsconfigRootDir: import.meta.dirname,
|
|
||||||
},
|
|
||||||
// other options...
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
## 🔧 Development
|
||||||
|
|
||||||
```js
|
```bash
|
||||||
// eslint.config.js
|
# Start development server
|
||||||
import reactX from 'eslint-plugin-react-x'
|
npm run dev
|
||||||
import reactDom from 'eslint-plugin-react-dom'
|
|
||||||
|
|
||||||
export default defineConfig([
|
# Server runs at http://localhost:3000
|
||||||
globalIgnores(['dist']),
|
|
||||||
{
|
|
||||||
files: ['**/*.{ts,tsx}'],
|
|
||||||
extends: [
|
|
||||||
// Other configs...
|
|
||||||
// Enable lint rules for React
|
|
||||||
reactX.configs['recommended-typescript'],
|
|
||||||
// Enable lint rules for React DOM
|
|
||||||
reactDom.configs.recommended,
|
|
||||||
],
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
||||||
tsconfigRootDir: import.meta.dirname,
|
|
||||||
},
|
|
||||||
// other options...
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 🔨 Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build for production
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Preview production build
|
||||||
|
npm run preview
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌐 Environment Variables
|
||||||
|
|
||||||
|
Create `.env` file in frontend directory:
|
||||||
|
|
||||||
|
```env
|
||||||
|
VITE_API_URL=http://localhost:8000
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📁 Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
frontend/
|
||||||
|
├── src/
|
||||||
|
│ ├── components/
|
||||||
|
│ │ ├── layout/ # Layout components
|
||||||
|
│ │ └── ui/ # shadcn/ui components
|
||||||
|
│ ├── pages/ # Route pages
|
||||||
|
│ │ ├── Login.tsx
|
||||||
|
│ │ ├── Dashboard.tsx
|
||||||
|
│ │ ├── Documents.tsx
|
||||||
|
│ │ ├── Chat.tsx
|
||||||
|
│ │ └── Settings.tsx
|
||||||
|
│ ├── api/
|
||||||
|
│ │ └── client.ts # API client
|
||||||
|
│ ├── stores/
|
||||||
|
│ │ ├── authStore.ts
|
||||||
|
│ │ ├── chatStore.ts
|
||||||
|
│ │ └── settingsStore.ts
|
||||||
|
│ ├── types/
|
||||||
|
│ │ └── index.ts # TypeScript types
|
||||||
|
│ ├── lib/
|
||||||
|
│ │ └── utils.ts # Utility functions
|
||||||
|
│ ├── App.tsx
|
||||||
|
│ └── main.tsx
|
||||||
|
├── public/
|
||||||
|
├── index.html
|
||||||
|
├── package.json
|
||||||
|
├── tailwind.config.js
|
||||||
|
├── tsconfig.json
|
||||||
|
└── vite.config.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔐 Authentication
|
||||||
|
|
||||||
|
The frontend supports API Key authentication:
|
||||||
|
|
||||||
|
1. Enter your API key on the login page
|
||||||
|
2. The key is stored in localStorage
|
||||||
|
3. Sent with every request via `X-API-Key` header
|
||||||
|
|
||||||
|
## 🎨 Customization
|
||||||
|
|
||||||
|
### Themes
|
||||||
|
- Edit `src/index.css` for CSS variables
|
||||||
|
- Toggle between light/dark/system in Settings
|
||||||
|
|
||||||
|
### API Configuration
|
||||||
|
- Update `vite.config.ts` proxy settings
|
||||||
|
- Or set `VITE_API_URL` environment variable
|
||||||
|
|
||||||
|
### Adding Components
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install shadcn/ui component
|
||||||
|
npx shadcn-ui@latest add button
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📝 Available Scripts
|
||||||
|
|
||||||
|
| Script | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| `npm run dev` | Start dev server |
|
||||||
|
| `npm run build` | Build for production |
|
||||||
|
| `npm run preview` | Preview production build |
|
||||||
|
| `npm run lint` | Run ESLint |
|
||||||
|
|
||||||
|
## 🔗 API Endpoints
|
||||||
|
|
||||||
|
The frontend connects to these API endpoints:
|
||||||
|
|
||||||
|
- `GET /api/health` - Health check
|
||||||
|
- `GET /api/v1/documents` - List documents
|
||||||
|
- `POST /api/v1/documents` - Upload document
|
||||||
|
- `DELETE /api/v1/documents/:id` - Delete document
|
||||||
|
- `POST /api/v1/query` - Query with RAG
|
||||||
|
- `POST /api/v1/chat` - Chat endpoint
|
||||||
|
- `GET /api/v1/providers` - List providers
|
||||||
|
- `GET /api/v1/config` - Get config
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### Build Errors
|
||||||
|
If you see TypeScript errors about unused variables:
|
||||||
|
```bash
|
||||||
|
# Check for unused imports
|
||||||
|
npm run lint
|
||||||
|
```
|
||||||
|
|
||||||
|
### API Connection Issues
|
||||||
|
Make sure the backend is running on port 8000, or update the proxy in `vite.config.ts`.
|
||||||
|
|
||||||
|
### CORS Errors
|
||||||
|
The Vite dev server proxies `/api` requests to the backend. For production, ensure CORS is configured on the backend.
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
Same as the main project.
|
||||||
|
|||||||
Reference in New Issue
Block a user