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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# API Reference

## Overview

The UGA Agentic AI Chatbot API provides comprehensive endpoints for managing conversations, user authentication, student services, and faculty operations. All API endpoints follow RESTful conventions and return JSON responses.

**Base URL**: `http://localhost:5000/api` (development)

## Authentication

All protected endpoints require a valid JWT token in the Authorization header:

```
Authorization: Bearer <token>
```

### Login Flow

1. **Standard Login**: `POST /auth/login`
2. **MyID Login**: `POST /auth/myid-login` 
3. **Token Refresh**: `POST /auth/refresh`
4. **Logout**: `POST /auth/logout`

## Response Format

All API responses follow this standard format:

```json
{
  "success": boolean,
  "data": any,
  "message": string,
  "error": string
}
```

## Endpoints

### Authentication (`/api/auth`)

#### POST /auth/login
Standard username/password authentication.

**Request Body:**
```json
{
  "username": "string",
  "password": "string"
}
```

**Response:**
```json
{
  "success": true,
  "data": {
    "token": "jwt_token",
    "refreshToken": "refresh_token",
    "user": {
      "id": "user_id",
      "email": "user@uga.edu",
      "firstName": "First",
      "lastName": "Last",
      "role": "student|faculty|admin"
    }
  }
}
```

#### POST /auth/myid-login
UGA MyID system authentication.

**Request Body:**
```json
{
  "username": "string",
  "password": "string"
}
```

#### GET /auth/me
Get current authenticated user information.

**Headers:** `Authorization: Bearer <token>`

**Response:**
```json
{
  "success": true,
  "data": {
    "id": "user_id",
    "ugaId": "811123456",
    "email": "user@uga.edu",
    "firstName": "First",
    "lastName": "Last",
    "role": "student",
    "classification": "Senior",
    "major": "Computer Science",
    "college": "Franklin College of Arts and Sciences"
  }
}
```

### Chat (`/api/chat`)

#### GET /chat/conversations
List all conversations for the authenticated user.

**Query Parameters:**
- `limit` (optional): Number of conversations to return (default: 50)
- `offset` (optional): Pagination offset (default: 0)
- `category` (optional): Filter by category

**Response:**
```json
{
  "success": true,
  "data": [
    {
      "id": "conversation_id",
      "title": "Course Registration Help",
      "category": "academics",
      "lastActivity": "2024-03-15T10:30:00Z",
      "messageCount": 12
    }
  ]
}
```

#### POST /chat/conversations
Create a new conversation.

**Request Body:**
```json
{
  "title": "string (optional)",
  "category": "string (optional)"
}
```

#### GET /chat/conversations/:id
Get conversation details including message history.

**Response:**
```json
{
  "success": true,
  "data": {
    "id": "conversation_id",
    "title": "Course Registration Help",
    "messages": [
      {
        "id": "message_id",
        "role": "user|assistant",
        "content": "Message content",
        "timestamp": "2024-03-15T10:30:00Z",
        "metadata": {
          "ugaSystemUsed": "Athena",
          "intent": "course_registration",
          "agentic": true,
          "executionResults": [
            {
              "action": "register_course",
              "success": true,
              "message": "Successfully registered for CSCI 1301"
            }
          ]
        }
      }
    ]
  }
}
```

#### POST /chat/message
Send a message to the chatbot.

**Request Body:**
```json
{
  "conversationId": "conversation_id (optional)",
  "message": "How do I register for CSCI 1301?",
  "metadata": {
    "location": "string (optional)",
    "context": "object (optional)"
  }
}
```

**Response:**
```json
{
  "success": true,
  "data": {
    "userMessage": {
      "id": "message_id",
      "role": "user",
      "content": "How do I register for CSCI 1301?",
      "timestamp": "2024-03-15T10:30:00Z"
    },
    "assistantMessage": {
      "id": "message_id",
      "role": "assistant",
      "content": "I can help you register for CSCI 1301...",
      "timestamp": "2024-03-15T10:30:05Z",
      "metadata": {
        "ugaSystemUsed": "Athena",
        "intent": "course_registration",
        "agentic": true
      }
    },
    "conversationId": "conversation_id"
  }
}
```

### User Management (`/api/users`)

#### GET /users/stats
Get user activity statistics.

**Response:**
```json
{
  "success": true,
  "data": {
    "totalConversations": 15,
    "totalQuestions": 127,
    "favoriteTopics": ["academics", "dining", "housing"],
    "averageResponseTime": 1.2,
    "lastActive": "2024-03-15T10:30:00Z"
  }
}
```

#### PUT /users/profile
Update user profile information.

**Request Body:**
```json
{
  "firstName": "string (optional)",
  "lastName": "string (optional)",
  "email": "string (optional)",
  "phone": "string (optional)",
  "address": "string (optional)"
}
```

#### GET /users/conversations/summary
Get conversation summary for dashboard.

**Query Parameters:**
- `limit`: Number of recent conversations (default: 5)

### Student Services (`/api/students`)

#### GET /students/courses
Get enrolled and available courses.

**Response:**
```json
{
  "success": true,
  "data": {
    "enrolled": [
      {
        "id": "course_id",
        "code": "CSCI 1301",
        "title": "Introduction to Computing and Programming",
        "credits": 4,
        "instructor": "Dr. Smith",
        "schedule": "MWF 10:10-11:00",
        "location": "Boyd GSRC 303"
      }
    ],
    "available": [
      {
        "id": "course_id",
        "code": "CSCI 2720",
        "title": "Data Structures",
        "credits": 4,
        "instructor": "Dr. Johnson",
        "schedule": "TR 2:00-3:15",
        "location": "Boyd GSRC 304",
        "enrolled": 45,
        "capacity": 50,
        "waitlist": 3
      }
    ]
  }
}
```

#### POST /students/courses/register
Register for a course.

**Request Body:**
```json
{
  "courseId": "course_id"
}
```

#### DELETE /students/courses/:courseId
Drop a course.

#### GET /students/financial
Get financial information.

**Response:**
```json
{
  "success": true,
  "data": {
    "balance": 2500.00,
    "dueDate": "2024-04-15",
    "aid": [
      {
        "type": "HOPE Scholarship",
        "amount": 4000.00,
        "status": "Awarded"
      }
    ],
    "paymentHistory": []
  }
}
```

#### GET /students/housing
Get housing information.

#### GET /students/meals
Get meal plan information.

### Faculty Services (`/api/faculty`)

#### GET /faculty/dashboard
Get faculty dashboard data.

**Response:**
```json
{
  "success": true,
  "data": {
    "summary": {
      "totalCourses": 3,
      "totalStudents": 150,
      "pendingGrades": 23,
      "unreadMessages": 5
    },
    "courses": [
      {
        "id": "course_id",
        "name": "CSCI 1301",
        "section": "001",
        "semester": "Spring 2024",
        "enrollment": 50,
        "nextDeadline": "Midterm Grades Due - March 20"
      }
    ],
    "notifications": [
      {
        "message": "Grade submission deadline approaching",
        "type": "deadline",
        "priority": "high"
      }
    ]
  }
}
```

#### GET /faculty/courses
List faculty courses.

#### GET /faculty/analytics
Get student performance analytics.

**Query Parameters:**
- `courseId` (optional): Filter by specific course

**Response:**
```json
{
  "success": true,
  "data": {
    "totalStudents": 127,
    "averageGrade": 84.2,
    "pendingGrades": 23,
    "atRiskStudents": 8,
    "gradeDistribution": [
      { "grade": "A", "count": 15, "percentage": 30 },
      { "grade": "B", "count": 20, "percentage": 40 }
    ],
    "attendanceData": [],
    "performanceData": []
  }
}
```

#### POST /faculty/grades
Submit grades for students.

### Knowledge Base (`/api/knowledge`)

#### GET /knowledge/search
Search knowledge base articles.

**Query Parameters:**
- `q`: Search query
- `category` (optional): Filter by category
- `limit` (optional): Number of results

#### GET /knowledge/articles/:id
Get specific article details.

#### POST /knowledge/articles/:id/bookmark
Toggle bookmark status for an article.

### Settings (`/api/settings`)

#### GET /settings
Get user settings and preferences.

#### PUT /settings
Update user settings.

## WebSocket Events

The chat system supports real-time communication via WebSocket:

### Client to Server Events
- `join_conversation`: Join a conversation room
- `leave_conversation`: Leave a conversation room
- `typing_start`: User started typing
- `typing_stop`: User stopped typing

### Server to Client Events
- `message_received`: New message in conversation
- `typing_indicator`: Someone is typing
- `conversation_updated`: Conversation metadata changed
- `user_joined`: User joined conversation
- `user_left`: User left conversation

## Error Codes

- `400` - Bad Request (validation errors)
- `401` - Unauthorized (authentication required)
- `403` - Forbidden (insufficient permissions)
- `404` - Not Found (resource doesn't exist)
- `429` - Too Many Requests (rate limit exceeded)
- `500` - Internal Server Error

## Rate Limits

- Authentication endpoints: 5 requests per minute
- Chat endpoints: 30 requests per minute
- General API: 100 requests per minute
- File upload: 10 requests per minute

## SDKs and Examples

### JavaScript/TypeScript
```typescript
import { ChatAPI } from './services/api';

// Send a message
const response = await ChatAPI.sendMessage('conv_id', 'Hello!');
console.log(response.data.assistantMessage.content);

// Get conversations
const conversations = await ChatAPI.getConversations();
```

### cURL Examples
```bash
# Login
curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "test@uga.edu", "password": "password"}'

# Send message
curl -X POST http://localhost:5000/api/chat/message \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"message": "What are the library hours?"}'
```