This document explains how Help2Study works under the hood, with diagrams showing how data flows through the system.
π Note on Diagrams: The diagrams in this document use Mermaid syntax, which automatically renders as visual diagrams on GitHub. No extension needed! If you're viewing locally in a text editor, you'll see the code - view this file on GitHub to see the rendered diagrams.
graph LR
A[User<br/>Browser] -->|1. Action| B[React<br/>Frontend]
B -->|2. HTTP Request| C[Django<br/>Backend]
C -->|3. Save/Query| D[(Database)]
C -->|4. Process| E[AI<br/>Gemini]
E -->|5. Result| C
C -->|6. JSON Response| B
B -->|7. Update UI| A
style A fill:#87CEEB
style B fill:#90EE90
style C fill:#FFD700
style D fill:#DDA0DD
style E fill:#FFA07A
Let's trace what happens when a user uploads a document to create flashcards.
File: frontend/src/components/FileUploadForm.jsx
sequenceDiagram
participant User
participant React
participant EventHandler
User->>React: Clicks "Create Flashcards"
React->>EventHandler: Triggers handleSubmit()
EventHandler->>EventHandler: Collect form data
Note over EventHandler: File + Topic name
What happens:
- User fills form and clicks submit
- React event handler captures the click
- Form data (file + topic name) is collected
- Ready to send to backend
Key concepts: Event Handling, Form Data, User Interface
File: frontend/src/api.js
sequenceDiagram
participant Frontend
participant Axios
participant Network
Frontend->>Axios: api.post('/api/flashcards/', data)
Axios->>Axios: Add JWT token to headers
Axios->>Network: HTTP POST request
Note over Network: Traveling to backend...
What happens:
- Axios prepares an HTTP POST request
- JWT token added to Authorization header
- Request body contains file and topic name
- Sent to
http://localhost:8000/api/flashcards/
Key concepts: HTTP Request, HTTP Method (POST), Authentication (JWT), Endpoint
Files: backend/backend/urls.py β backend/api/urls.py
graph LR
A[Request arrives<br/>:8000/api/flashcards/] --> B[Main urls.py]
B --> C[API urls.py]
C --> D[TopicListCreate View]
style D fill:#90EE90
What happens:
- Django receives request on port 8000
- Main
urls.pyroutes/api/to the api app - API
urls.pymatches/flashcards/pattern - Request directed to
TopicListCreateview
Key concepts: Routing, URL Patterns, Server
File: backend/api/views.py:20-36
sequenceDiagram
participant View
participant Serializer
participant Model
participant AI
View->>View: Check authentication
View->>Serializer: Validate data
Serializer->>Model: Create Topic object
Model->>Model: Save to database
View->>AI: Process file with Gemini
AI-->>View: Return flashcard data
View->>Model: Create Flashcard objects
Model->>Model: Save flashcards
What happens:
- View checks if user is authenticated (JWT token)
- Serializer validates the incoming data
- Topic model instance created and saved
- File extracted and sent to Gemini AI
- AI returns flashcard questions/answers
- Multiple Flashcard objects created and saved
- Response prepared
Key concepts: View, Permissions, Validation, ORM, CRUD Operations
File: backend/api/models.py
erDiagram
User ||--o{ Topic : creates
User ||--o{ Flashcard : owns
Topic ||--o{ Flashcard : contains
User {
int id
string username
string email
}
Topic {
int id
string name
datetime created_at
int user_id
}
Flashcard {
int id
text question
text answer
datetime created_at
int topic_id
int user_id
}
What happens:
- Django ORM translates Python to SQL
Topic.objects.create()βINSERT INTO topics...Flashcard.objects.filter()βSELECT * FROM flashcards WHERE...- No raw SQL needed
Key concepts: Models, ORM, Foreign Keys, Database Relationships
File: backend/api/serializers.py
sequenceDiagram
participant Django
participant Serializer
participant Network
participant Frontend
Django->>Serializer: Convert Topic object
Serializer->>Serializer: Python β JSON
Serializer->>Network: HTTP 201 Created
Note over Network: Response travels back
Network->>Frontend: JSON data received
What happens:
- Serializer converts Python objects to JSON
- HTTP response created with status code 201 (Created)
- Response includes the new topic data
- Sent back through the network
Key concepts: Serialization, HTTP Response, Status Codes, JSON
File: frontend/src/components/FileUploadForm.jsx
sequenceDiagram
participant Axios
participant React
participant DOM
participant User
Axios->>React: Response received
React->>React: Update state
React->>DOM: Re-render component
DOM->>User: Show success message
What happens:
- Axios receives the response
- React component state updated
- Component re-renders automatically
- User sees confirmation message
- New flashcards appear in the UI
Key concepts: Asynchronous JavaScript, State Management, Component Re-rendering
flowchart LR
A[1. User Action] --> B[2. React Event]
B --> C[3. HTTP Request]
C --> D[4. Django View]
D --> E[5. Database]
D --> F[6. AI Process]
F --> G[7. Response]
G --> H[8. Update UI]
style A fill:#87CEEB
style B fill:#90EE90
style D fill:#FFD700
style E fill:#DDA0DD
style F fill:#FFA07A
The full cycle:
- User clicks button
- React captures event
- HTTP request sent to backend
- Django view processes request
- Data saved to database
- AI generates flashcards
- JSON response sent back
- React updates the UI
User Interface
β
React Components (JSX)
β
React Router (Navigation)
β
Axios (HTTP Client)
β
HTTP Request β Backend
HTTP Request arrives
β
Django URL Router
β
View (Request Handler)
β
Serializer (Validation)
β
Model (ORM)
β
Database (SQL)
sequenceDiagram
participant User
participant Frontend
participant Backend
participant DB
Note over User,DB: Registration
User->>Frontend: Enter credentials
Frontend->>Backend: POST /api/user/register/
Backend->>DB: Create user
Backend-->>Frontend: Success
Note over User,DB: Login
User->>Frontend: Enter credentials
Frontend->>Backend: POST /api/token/
Backend->>DB: Verify credentials
Backend-->>Frontend: Access + Refresh tokens
Frontend->>Frontend: Store tokens
Note over User,DB: Authenticated Request
Frontend->>Backend: Request + JWT token
Backend->>Backend: Validate token
Backend-->>Frontend: Protected data
How JWT works:
- User logs in with username/password
- Backend validates and returns JWT tokens
- Frontend stores tokens (localStorage)
- Every request includes token in Authorization header
- Backend validates token before processing
Here's where to find each piece in the codebase:
Frontend:
- Entry point:
frontend/src/main.jsx - Routing:
frontend/src/App.jsx - File upload:
frontend/src/components/FileUploadForm.jsx - API client:
frontend/src/api.js - API services:
frontend/src/services/topicService.js,flashcardService.js
Backend:
- Main settings:
backend/backend/settings.py - URL routing:
backend/backend/urls.pyβbackend/api/urls.py - Request handlers:
backend/api/views.py - Database models:
backend/api/models.py - Data serialization:
backend/api/serializers.py - AI integration:
backend/api/geminiapi.py - Utility functions:
backend/api/utils/text_extractors.py
New in this version: The codebase now includes a service layer for API calls (frontend) and utility functions for text extraction (backend). See ADVANCED_PATTERNS.md to learn why these were added and how to use them!
β Separation of concerns: Frontend, backend, and database each have clear responsibilities
β Request/response cycle: All web interactions follow this pattern
β RESTful design: Endpoints use standard HTTP methods (GET, POST, DELETE)
β Authentication: JWT tokens secure API endpoints
β ORM abstraction: Django handles database operations without SQL
β State management: React automatically updates UI when data changes
To understand the code:
- Read through
views.pyto see request handlers - Check
models.pyto see database structure - Look at
FileUploadForm.jsxto see how requests start - Trace a request through the system using browser DevTools
To modify the system:
- Add new model β Run migrations
- Create new view β Add URL route
- Build frontend component β Connect to API
- Test with browser Network tab
See CONCEPTS_GUIDE.md for term definitions and learning resources