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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# TalimBot - سیسΨͺΩ… Ϊ―Ψ±ΩˆΩ‡β€ŒΨ¨Ω†Ψ―ΫŒ Ω‡ΩˆΨ΄Ω…Ω†Ψ― Ψ―Ψ§Ω†Ψ΄β€ŒΨ’Ω…ΩˆΨ²Ψ§Ω†

A full-stack intelligent student grouping system using AI-powered analysis with FastAPI backend and GitHub Pages frontend.

## 🎯 Overview

TalimBot groups 30 real students based on MBTI personality types, learning styles, math grades, and peer preferences using AI (GPT-4o-mini via OpenRouter). Teachers control when students can view their group assignments.

### Real Student Data
- **30 Students** from class 1061 (Ψ―Ω‡Ω… Ψͺجربی)
- **Persian Names**: Full Persian names from actual class roster
- **National Code Authentication**: Students login with their national ID
- **Math Grades**: Real grades from student records

---

## πŸš€ Quick Start (Local Development)

### Prerequisites
- Python 3.8+ installed
- Modern web browser
- Internet connection (for AI grouping)

### Step 1: Start Backend (30 seconds)

```powershell

# Navigate to backend folder

cd backend



# Install dependencies (first time only)

pip install -r requirements.txt



# Start the server

python main.py

```

**Server runs on:** `http://localhost:8000`

**Keep this terminal running!**

### Step 2: Open Frontend (10 seconds)

**Option A - Direct Open (Easiest):**
- Double-click `index.html` in File Explorer

**Option B - Local Server (Recommended):**
```powershell

# In a NEW terminal window

python -m http.server 3000

```
Then visit: `http://localhost:3000`

---

## πŸ‘₯ Login Credentials

### Students (30 students available)
Login with:
- **Student Number:** S001, S002, ..., S030
- **National Code:** Each student's 10-digit national ID

**Example:**
- Student Number: `S001`
- National Code: `929986644`
- Name: Ψ’Ψ―ΫŒΩ†Ω‡ پور - ΫŒΨ§Ψ³Ω…Ω†

### Teacher
- **Password:** `teacher123`

---

## πŸ“‹ How It Works

### For Students:

1. **Login**
   - Enter student number (S001-S030)
   - Enter your 10-digit national code
   - System displays your Persian name

2. **Complete Profile**
   - Take MBTI test (link provided)
   - Take VARK learning style test (link provided)
   - Fill out AMS and Cooperative preferences
   - Select up to 4 preferred groupmates
   - Save your information

3. **View Group** (after teacher enables)
   - See your group number
   - View all group members
   - Read AI reasoning in Persian

### For Teachers:

1. **Monitor Progress**
   - View dashboard with statistics
   - See which students completed profiles
   - Check readiness for grouping

2. **Perform Grouping**
   - Enter course name
   - Click "Start Grouping"
   - AI analyzes all data (10-30 seconds)
   - Review generated groups with Persian reasoning

3. **Control Visibility**
   - Groups are hidden by default
   - Click "Show Results to Students"
   - Toggle visibility on/off anytime

4. **Manage Data**
   - View all student information
   - Edit student data if needed
   - Reset grouping when necessary

---

## 🌐 Deployment to GitHub Pages

### Part 1: Deploy Frontend to GitHub Pages

1. **Create GitHub Repository**
   ```bash

   # Initialize git (if not already done)

   git init

   git add .

   git commit -m "Initial commit with real student data"

   

   # Create repo on GitHub and push

   git remote add origin https://github.com/talimbot/talimbot.git

   git branch -M main

   git push -u origin main

   ```

2. **Enable GitHub Pages**
   - Go to repository Settings β†’ Pages
   - Source: Deploy from branch `main`
   - Folder: `/ (root)`
   - Click Save

3. **Your site will be live at:**
   `https://talimbot.github.io/talimbot/`

### Part 2: Deploy Backend to Render.com (Free)

1. **Create Render Account**
   - Visit [render.com](https://render.com)
   - Sign up with GitHub

2. **Create New Web Service**
   - Click "New +" β†’ "Web Service"
   - Connect your GitHub repository
   - Settings:
     - **Name:** `talimbot-backend`
     - **Environment:** `Python 3`
     - **Build Command:** `pip install -r backend/requirements.txt`
     - **Start Command:** `cd backend && uvicorn main:app --host 0.0.0.0 --port $PORT`
     - **Plan:** Free

3. **Add Environment Variable**
   - In Render dashboard β†’ Environment
   - Add: `OPENROUTER_API_KEY` = `your-api-key`
   - Optionally: `TEACHER_PASSWORD` = `your-password`

4. **Get Your Backend URL**
   - Copy the URL (e.g., `https://talimbot-backend.onrender.com`)

### Part 3: Update Frontend to Use Deployed Backend

Update `API_BASE_URL` in BOTH files:
- `assets/js/data.js`
- `assets/js/grouping.js`

```javascript

// Change from:

const API_BASE_URL = 'http://localhost:8000/api';



// To:

const API_BASE_URL = 'https://talimbot-backend.onrender.com/api';

```

Commit and push changes:
```bash

git add .

git commit -m "Update API URL for production"

git push

```

GitHub Pages will auto-deploy in ~1 minute.

---

## πŸ”§ Configuration

### API Key (OpenRouter)
Located in `backend/grouping_logic.py`:
```python

OPENROUTER_API_KEY = 'sk-or-v1-...'

```

### Teacher Password
Located in `backend/main.py` (SystemData model):
```python

teacherPassword: str = "teacher123"

```

Change as needed for security.

### Student Data
Students are initialized in `backend/main.py` in the `load_data()` function.
All 30 real students with Persian names and national codes are pre-loaded.

---

## πŸ“ Project Structure

```

talimbot/

β”œβ”€β”€ backend/

β”‚   β”œβ”€β”€ main.py              # FastAPI server with real student data

β”‚   β”œβ”€β”€ grouping_logic.py    # AI grouping with OpenRouter

β”‚   β”œβ”€β”€ requirements.txt     # Python dependencies

β”‚   β”œβ”€β”€ README.md            # Backend documentation

β”‚   └── data/

β”‚       └── students.json    # Auto-created data storage

β”‚

β”œβ”€β”€ assets/

β”‚   β”œβ”€β”€ css/

β”‚   β”‚   └── styles.css

β”‚   └── js/

β”‚       β”œβ”€β”€ data.js          # API client for student data

β”‚       └── grouping.js      # API client for grouping

β”‚

β”œβ”€β”€ pages/

β”‚   β”œβ”€β”€ login.html           # Login with national code

β”‚   β”œβ”€β”€ student-dashboard.html

β”‚   β”œβ”€β”€ student-data.html

β”‚   β”œβ”€β”€ teacher-dashboard.html

β”‚   └── group-view.html

β”‚

β”œβ”€β”€ Icons/                   # UI icons

β”œβ”€β”€ index.html              # Redirects to login

β”œβ”€β”€ README.md               # This file

β”œβ”€β”€ .gitignore              # Git ignore rules

└── start-backend.ps1       # Windows startup script

```

---

## 🎯 Features

### βœ… Implemented
- **Real Student Data**: 30 actual students with Persian names
- **National Code Authentication**: Secure login using national IDs  
- **Persistent Storage**: JSON database on backend
- **AI-Powered Grouping**: OpenRouter GPT-4o-mini integration
- **Persian Language**: Full RTL support with Persian reasoning
- **Teacher Controls**: Show/hide results, reset grouping
- **Math Grades**: Real grades from class records
- **MBTI & Learning Styles**: Comprehensive personality analysis
- **Peer Preferences**: Students select preferred groupmates

### 🎨 UI Features
- Modern, responsive design with Tailwind CSS
- Persian (RTL) interface
- Real-time validation
- Progress indicators

---

## πŸ› Troubleshooting

### "Failed to fetch" errors
**Problem:** Backend not running or wrong URL
**Solution:**
1. Check backend is running: Visit `http://localhost:8000`
2. Should see: `{"message":"TalimBot API is running"}`
3. Check `API_BASE_URL` in JS files matches backend

### Students can't login
**Problem:** Wrong national code
**Solution:**
- National code must be exactly 10 digits
- Must match the code in backend database
- Check `backend/main.py` for correct codes

### Students can't see groups
**Problem:** Teacher hasn't enabled visibility
**Solution:**
- Teacher must click "Show Results to Students"
- Button appears after grouping is complete

### Grouping fails
**Problem:** API error or no internet
**Solution:**
1. Check internet connection
2. Verify OpenRouter API key is valid
3. Check backend logs for errors
4. System has fallback random grouping if AI fails

---

## πŸ“Š Student List (Sample)

| # | Student Number | Name | National Code | Math Grade |
|---|----------------|------|---------------|------------|
| 1 | S001 | Ψ’Ψ―ΫŒΩ†Ω‡ پور - ΫŒΨ§Ψ³Ω…Ω† | 929986644 | 16.0 |
| 2 | S002 | Ψ§Ψ­Ω…Ψ―Ψ²Ψ§Ψ―Ω‡ - پریا | 980085330 | 12.0 |
| 3 | S003 | Ψ§Ϊ©Ψ¨Ψ±Ψ²Ψ§Ψ―Ω‡ - فاطمه | 970154550 | 11.0 |
| 4 | S004 | Ψ§Ω„Ω‡ΫŒ Ω…Ω‡Ψ± - Ψ’Ω†Ψ§Ω‡ΫŒΨͺΨ§ | 26425955 | 17.0 |
| 5 | S005 | Ψ§Ω…ΫŒΨ±ΫŒ - Ω…Ψ±ΫŒΩ… | 980093341 | 18.0 |
| ... | ... | ... | ... | ... |
| 30 | S030 | وحدΨͺی - Ψ¨Ψ§Ψ±Ψ§Ω† | 929916913 | 12.0 |

*Full list available in `backend/main.py`*

---

## πŸ” Security Notes

### Current (Demo/Development):
- βœ… Simple password authentication
- βœ… CORS allows all origins
- βœ… National codes as passwords

### Recommended for Production:
- πŸ”’ Use environment variables for secrets
- πŸ”’ Implement JWT token authentication
- πŸ”’ Enable HTTPS only
- πŸ”’ Add rate limiting
- πŸ”’ Use PostgreSQL instead of JSON
- πŸ”’ Hash national codes
- πŸ”’ Implement proper session management

---

## πŸ“ž API Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/` | GET | Health check |
| `/api/students` | GET | Get all students |
| `/api/student/{id}` | GET | Get one student |
| `/api/student/{id}` | PUT | Update student |
| `/api/auth/student` | POST | Authenticate student |
| `/api/auth/teacher` | POST | Authenticate teacher |
| `/api/grouping/perform` | POST | Run AI grouping |
| `/api/grouping/status` | GET | Get stats |
| `/api/grouping/toggle-visibility` | POST | Show/hide results |
| `/api/grouping/reset` | POST | Clear grouping |
| `/api/student/{id}/group` | GET | Get student's group |

---

## πŸŽ“ Technologies Used

### Backend
- **FastAPI** - Modern Python web framework
- **Uvicorn** - ASGI server
- **Pydantic** - Data validation
- **aiohttp** - Async HTTP client
- **OpenRouter API** - AI integration

### Frontend
- **HTML5 / CSS3** - Structure and styling
- **Tailwind CSS** - Utility-first CSS
- **JavaScript (Async/Await)** - Modern JS
- **Fetch API** - HTTP requests

### Deployment
- **GitHub Pages** - Frontend hosting (free)
- **Render.com** - Backend hosting (free)

---

## πŸ“ License

This project is for educational purposes.

---

## πŸ™ Credits

- Student data from class 1061 (Ψ―Ω‡Ω… Ψͺجربی)
- AI grouping powered by OpenRouter (GPT-4o-mini)

---

## βœ… Pre-Launch Checklist

- [ ] Backend running locally
- [ ] Students can login with national codes
- [ ] Teacher can login with password
- [ ] Grouping works with AI
- [ ] Visibility toggle works
- [ ] All 30 students load correctly
- [ ] Persian names display properly
- [ ] Math grades show correctly
- [ ] Backend deployed to Render
- [ ] Frontend deployed to GitHub Pages
- [ ] API URLs updated for production

---

**Live URL:** `https://talimbot.github.io/talimbot/pages/login.html`

**Last Updated:** December 2025