4.6 KiB
Frappe React Frontend
A modern React frontend application built with TypeScript, Vite, and TailwindCSS that connects to your existing Frappe backend.
Features
- 🔐 Authentication: Seamless integration with Frappe's authentication system
- 🎨 Modern UI: Beautiful, responsive interface built with TailwindCSS
- 🚀 Fast Development: Hot module replacement with Vite
- 📱 Mobile Ready: Responsive design that works on all devices
- 🔌 API Integration: Comprehensive API client for Frappe backend
- 🛡️ Type Safety: Full TypeScript support
- 🧭 Routing: Client-side routing with React Router
Tech Stack
- Frontend: React 19 + TypeScript + Vite
- Styling: TailwindCSS 4
- Routing: React Router DOM
- HTTP Client: Axios
- Backend: Frappe Framework (Python)
Quick Start
Prerequisites
- Node.js 18+
- npm or yarn
- Running Frappe backend
Installation
-
Clone or download this project
-
Install dependencies:
npm install -
Configure environment variables:
cp .env.example .env # Edit .env with your Frappe backend details -
Start development server:
npm run dev -
Open http://localhost:3000 in your browser
Project Structure
src/
├── api/
│ └── frappeClient.ts # API client for Frappe backend
├── pages/
│ ├── Login.tsx # Login page
│ ├── Dashboard.tsx # Dashboard page
│ └── UsersList.tsx # Users list page
├── components/ # Reusable React components
├── hooks/ # Custom React hooks
├── types/ # TypeScript type definitions
├── utils/ # Utility functions
├── App.tsx # Main app component
└── main.tsx # App entry point
Configuration
Environment Variables
Create a .env file in the root directory:
# Frappe Backend Configuration
VITE_FRAPPE_BASE_URL=http://localhost:8000
VITE_FRAPPE_SITE_NAME=your_site_name
# Development Configuration
VITE_DEV_MODE=true
VITE_API_TIMEOUT=10000
Frappe Backend Setup
- Add the custom API endpoints to your Frappe app (see
python_api_examples.py) - Restart your Frappe backend
- Ensure CORS is configured for your frontend domain
Available Scripts
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLint
API Integration
The app includes a comprehensive API client (frappeClient.ts) that handles:
- Authentication (login/logout)
- DocType operations (CRUD)
- File uploads
- Error handling
- Session management
Example Usage
import frappeAPI from './api/frappeClient';
// Login
const user = await frappeAPI.login({ usr: 'username', pwd: 'password' });
// Get records
const users = await frappeAPI.getDocTypeRecords('User');
// Create record
const newUser = await frappeAPI.createDocTypeRecord('User', {
email: 'user@example.com',
first_name: 'John',
last_name: 'Doe'
});
Deployment
See DEPLOYMENT_GUIDE.md for detailed deployment instructions.
Quick Deployment
-
Build the app:
npm run build -
Copy
dist/contents to your Frappe app'spublic/folder -
Restart Frappe:
bench restart
Customization
Adding New Pages
- Create a new component in
src/pages/ - Add route in
src/App.tsx - Update navigation as needed
Styling
The app uses TailwindCSS. You can:
- Modify
tailwind.config.jsfor custom themes - Add custom CSS in
src/index.css - Use Tailwind utility classes in components
API Endpoints
Add new API methods in src/api/frappeClient.ts and corresponding Python endpoints in your Frappe app.
Troubleshooting
Common Issues
- CORS Errors: Check Frappe CORS configuration
- Authentication Issues: Verify session cookies
- API Not Found: Ensure API files are deployed and Frappe is restarted
- Build Errors: Check Node.js version compatibility
Debug Mode
Enable debug logging by setting VITE_DEV_MODE=true in your .env file.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
License
This project is licensed under the MIT License.
Support
For issues and questions:
- Check the Deployment Guide
- Review the Frappe Documentation
- Open an issue in this repository