The frontend and backend have been fully integrated. The frontend now communicates with the Django REST API backend using JWT authentication.
-
Django REST Framework Setup
- JWT authentication with SimpleJWT
- CORS configuration for frontend access
- Custom User model
- Models: Document, Summary, Flashcard
- OpenAI integration for summaries and flashcards
-
API Endpoints
/api/auth/register/- User registration/api/auth/login/- User login/api/auth/refresh/- Token refresh/api/auth/profile/- User profile/api/documents/- Document CRUD/api/documents/{id}/generate_summary/- Generate summary/api/documents/{id}/generate_flashcards/- Generate flashcards/api/summaries/- Summary CRUD/api/summaries/{id}/generate_flashcards/- Generate flashcards from summary/api/flashcards/- Flashcard CRUD/api/flashcards/{id}/review/- Mark flashcard as reviewed/api/dashboard/stats/- Dashboard statistics
-
API Service (
src/services/api.ts)- Centralized API client with JWT token management
- All API endpoints wrapped in TypeScript interfaces
- Error handling and token refresh logic
-
Updated Components
- SignInDialog: Now uses backend login API
- SignUpDialog: Now uses backend registration API
- Router: Uses JWT tokens instead of localStorage boolean
- DashboardView: Fetches real data from backend
- DocumentSummarizationView: Uploads documents and generates summaries via API
- FlashcardCreationView: Full CRUD operations with backend
-
Navigate to backend directory:
cd backend -
Create virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables:
export SECRET_KEY="your-secret-key-here" export OPENAI_API_KEY="your-openai-api-key-here"
Or create a
.envfile in the backend directory. -
Run migrations:
python manage.py makemigrations python manage.py migrate
-
Create superuser (optional):
python manage.py createsuperuser
-
Start the server:
python manage.py runserver
Backend will run on
http://localhost:8000
-
Navigate to frontend directory:
cd front_end -
Install dependencies:
npm install
-
Create
.envfile (optional):VITE_API_BASE_URL=http://localhost:8000/api
If not set, defaults to
http://localhost:8000/api -
Start the development server:
npm run dev
Frontend will run on
http://localhost:5173(or another port if 5173 is busy)
- User registers/logs in through SignUpDialog or SignInDialog
- Backend returns JWT tokens (access and refresh)
- Tokens are stored in localStorage
- All subsequent API requests include the access token in the Authorization header
- Router checks for token presence to determine authentication status
- User uploads a document in DocumentSummarizationView
- File is sent to
/api/documents/endpoint - Backend extracts text from the document (PDF, DOCX, TXT)
- User can generate summary via
/api/documents/{id}/generate_summary/ - OpenAI generates summary and key points
- Summary is displayed in the UI
- User can generate flashcards from a document or summary
- Backend sends document/summary content to OpenAI
- OpenAI generates flashcards with questions and answers
- Flashcards are saved to the database
- User can view, edit, and delete flashcards
All API endpoints (except registration and login) require JWT authentication. The frontend automatically includes the token in requests:
Authorization: Bearer <access_token>
Tokens expire after 1 day. The refresh token can be used to get a new access token.
SECRET_KEY: Django secret keyOPENAI_API_KEY: OpenAI API key for AI features
VITE_API_BASE_URL: Backend API base URL (default:http://localhost:8000/api)
- Start the backend server
- Start the frontend server
- Open the frontend in your browser
- Register a new account
- Upload a document
- Generate a summary
- Generate flashcards
- View dashboard statistics
- Ensure backend CORS settings include your frontend URL
- Check that
CORS_ALLOWED_ORIGINSinsettings.pyincludes your frontend URL
- Check that tokens are being stored in localStorage
- Verify token expiration
- Check backend logs for authentication errors
- Verify backend is running on the correct port
- Check
VITE_API_BASE_URLenvironment variable - Verify CORS settings allow your frontend origin
- Ensure
OPENAI_API_KEYis set correctly - Check OpenAI API quota/limits
- Verify API key has necessary permissions
- Add error handling for network failures
- Implement token refresh on 401 errors
- Add loading states for better UX
- Implement pagination for large datasets
- Add file validation on frontend before upload
- Implement study session tracking
- Add flashcard review scheduling