-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumentation.tex
1607 lines (1404 loc) · 46.4 KB
/
documentation.tex
1
2
3
4
5
6
7
8
9
10
11
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\hypertarget{finance-friends-documentation}{%
\section{Finance Friends
Documentation}\label{finance-friends-documentation}}
\hypertarget{final-deployment}{%
\subsection{Final Deployment}\label{final-deployment}}
Finance Friends is now live and accessible! Here's how you can explore
the platform and learn more about the project.
\hypertarget{introduction}{%
\subsection{Introduction}\label{introduction}}
Finance Friends is a revolutionary platform designed to make learning
about financial literacy a fun, interactive, and engaging experience for
children. By leveraging advanced AI technology alongside a captivating
narrative and interactive gameplay, Finance Friends introduces children
to fundamental financial concepts and practical knowledge.
\hypertarget{overview}{%
\subsubsection{Overview}\label{overview}}
At its core, Finance Friends is a gamified learning platform where
children embark on a journey through various thematic locations. Each
location is meticulously designed to focus on different aspects of
financial literacy, including financial mathematics, credits, savings,
investments, taxes, and free conversation. This approach not only makes
learning about finance more relatable but also ensures a comprehensive
educational experience.
\hypertarget{key-features}{%
\subsubsection{Key Features}\label{key-features}}
\begin{itemize}
\tightlist
\item
\textbf{Gamified Learning Experience:} A journey with 6 main
characters across 6 unique locations, each meticulously crafted to
focus on different financial modules.
\item
\textbf{Interactive Chatbot Education:} An intelligent chatbot,
powered by the latest technologies such as Node.js, MongoDB, and
Python scripts using LangChain, guides children through predefined
lessons in an understandable and engaging manner.
\item
\textbf{On-Demand Learning:} Recognizing the dynamic nature of
learning, Finance Friends allows children to interact with the chatbot
at their own pace, encouraging them to ask questions and seek
clarifications whenever needed.
\end{itemize}
\hypertarget{target-audience}{%
\subsubsection{Target Audience}\label{target-audience}}
The primary audience for Finance Friends is children who are at the
beginning of their educational journey. The platform is designed to be
intuitive and user-friendly, making it accessible for children with
varying degrees of familiarity with technology and finance.
Through this documentation, you will gain a comprehensive understanding
of the platform, its features, and detailed guides on installation,
configuration, and usage, along with the API documentation for further
customization and integration.
Join us as we embark on this journey to make financial literacy an
accessible, enjoyable, and essential part of every child's education.
\hypertarget{key-features-1}{%
\subsection{Key Features}\label{key-features-1}}
Finance Friends is not just a learning platform; it's an interactive,
engaging, and comprehensive journey into financial literacy for
children. Here are some of the standout features that make Finance
Friends an essential tool for learning:
\hypertarget{comprehensive-user-management}{%
\subsubsection{1. Comprehensive User
Management}\label{comprehensive-user-management}}
\begin{itemize}
\tightlist
\item
\textbf{Seamless Registration and Login:} Ensures an easy and secure
entry into the world of financial learning.
\item
\textbf{Personalized User Profiles:} Users have their own profiles,
capturing their learning progress, preferences, and achievements,
allowing for a tailored learning experience.
\end{itemize}
\hypertarget{engaging-personalized-experiences}{%
\subsubsection{2. Engaging Personalized
Experiences}\label{engaging-personalized-experiences}}
\begin{itemize}
\tightlist
\item
\textbf{Custom Welcome Messages:} Users are welcomed with messages
that make them feel recognized and valued, setting a positive tone for
their learning journey.
\item
\textbf{Interactive Learning Sessions:} Each session is an adventure,
with content tailored to the user's pace and style, making complex
financial concepts more understandable and engaging.
\end{itemize}
\hypertarget{dynamic-learning-modules}{%
\subsubsection{3. Dynamic Learning
Modules}\label{dynamic-learning-modules}}
\begin{itemize}
\tightlist
\item
\textbf{Diverse Financial Topics:} A wide array of modules ensures a
well-rounded understanding of financial literacy, from savings and
investments to taxes and financial mathematics.
\item
\textbf{Real-time Interactive Chatbot:} An intelligent chatbot
accompanies users, ready to answer questions, clarify doubts, and
provide guidance.
\end{itemize}
\hypertarget{innovative-assessment-tools}{%
\subsubsection{4. Innovative Assessment
Tools}\label{innovative-assessment-tools}}
\begin{itemize}
\tightlist
\item
\textbf{Quizzes and Knowledge Checks:} Regular quizzes and assessments
help reinforce learning, ensuring that key concepts are understood and
retained.
\item
\textbf{AI-Powered Quiz Evaluation:} Quizzes are evaluated instantly
with AI, providing immediate feedback and explanations, enhancing the
learning process.
\end{itemize}
\hypertarget{motivation-and-progress-tracking}{%
\subsubsection{5. Motivation and Progress
Tracking}\label{motivation-and-progress-tracking}}
\begin{itemize}
\tightlist
\item
\textbf{Leaderboards:} Friendly competition is fostered through
leaderboards, motivating users to engage more with the content and
strive for improvement.
\item
\textbf{Progress Tracking:} Users can track their learning journey,
see their progress in different modules, and set personal learning
goals.
\end{itemize}
Finance Friends combines these features to provide an educational
experience that's not just informative but also engaging, interactive,
and tailored to each user's needs. The platform ensures that learning
about finance is a fun, rewarding, and enriching experience for every
child.
\hypertarget{getting-started}{%
\subsection{Getting Started}\label{getting-started}}
This section guides you through setting up your development environment
for both the backend and frontend components of Finance Friends.
\hypertarget{backend-setup}{%
\subsubsection{Backend Setup}\label{backend-setup}}
\hypertarget{prerequisites}{%
\paragraph{Prerequisites}\label{prerequisites}}
Before setting up the backend, ensure you have the following installed:
- Node.js - npm (Node Package Manager) - MongoDB (local setup or MongoDB
Atlas URI) - Python 3 (with Pip)
\hypertarget{installing}{%
\paragraph{Installing}\label{installing}}
Follow these steps to set up your backend development environment:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
\textbf{Clone the Repository}:
\texttt{git\ clone\ https://github.com/FinanceFriend/backend.git}
\item
\textbf{Navigate to the Directory}: \texttt{cd\ backend}
\item
\textbf{Install Dependencies}: \texttt{npm\ install}
\item
\textbf{Set Up Environment Variables}:
\end{enumerate}
\begin{itemize}
\item
Create a \texttt{.env} file in the root of your project.
\item
Add your MongoDB URI and other necessary environment variables.
Example:
\begin{verbatim}
MONGODB_URI=your_mongodb_uri
OPENAI_API_KEY=your_api_key
PORT=3001
\end{verbatim}
\end{itemize}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{4}
\item
\textbf{Start the Server}: \texttt{npm\ start}
\item
\textbf{Verify Installation}:
\end{enumerate}
\begin{itemize}
\tightlist
\item
Open \texttt{http://localhost:3001} in your web browser. You should
see a confirmation message indicating that the server is running.
\end{itemize}
\hypertarget{setting-up-python-environment}{%
\paragraph{Setting Up Python
Environment}\label{setting-up-python-environment}}
To run the Python script with \texttt{langchain}, follow these steps:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
\textbf{Create a Virtual Environment}:
\texttt{python3\ -m\ venv\ venv}
\end{enumerate}
\begin{itemize}
\tightlist
\item
This will create a directory called \texttt{venv} in your project
folder.
\end{itemize}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
\textbf{Activate the Virtual Environment}:
\end{enumerate}
\begin{itemize}
\item
On Windows:
\begin{verbatim}
venv\Scripts\activate
\end{verbatim}
\item
On macOS and Linux:
\begin{verbatim}
source venv/bin/activate
\end{verbatim}
\item
Your command prompt should now indicate that you are in a virtual
environment.
\end{itemize}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\item
\textbf{Install Python Dependencies}:
\texttt{pip\ install\ -r\ requirements.txt}
\item
\textbf{Run the Python Script}:
\end{enumerate}
\begin{itemize}
\tightlist
\item
With the dependencies installed, you can now run your Python script
within the virtual environment.
\end{itemize}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{4}
\tightlist
\item
\textbf{Deactivate the Virtual Environment}:
\end{enumerate}
\begin{itemize}
\item
Once you're done, you can deactivate the virtual environment by
running:
\begin{verbatim}
deactivate
\end{verbatim}
\end{itemize}
\hypertarget{frontend-setup}{%
\subsubsection{Frontend Setup}\label{frontend-setup}}
This is a Next.js project bootstrapped with \texttt{create-next-app}.
\hypertarget{getting-started-1}{%
\paragraph{Getting Started}\label{getting-started-1}}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
\textbf{Install Necessary npm Dependencies}:
\texttt{npm\ install\ -\/-force}
\item
\textbf{Run the Development Server}: \texttt{npm\ run\ dev} or
\texttt{yarn\ dev}
\item
\textbf{Verify Installation}:
\end{enumerate}
\begin{itemize}
\tightlist
\item
Open \texttt{http://localhost:3000} with your browser to see the
result.
\end{itemize}
Follow these steps to get your backend and frontend up and running. If
you encounter any issues, refer to the FAQs or reach out to the support
team.
\hypertarget{api-documentation}{%
\subsection{API Documentation}\label{api-documentation}}
This section provides a comprehensive guide to the API of Finance
Friends, detailing the available endpoints, their functionalities, and
how to interact with them.
\hypertarget{overview-of-the-api}{%
\subsubsection{Overview of the API}\label{overview-of-the-api}}
The Finance Friends API is designed to provide a seamless and secure way
to interact with the platform, enabling users to access and manage
resources programmatically. It is built with RESTful principles in mind,
ensuring a predictable and consistent way to access the platform's data
and services.
\hypertarget{backend-endpoints}{%
\subsubsection{Backend endpoints}\label{backend-endpoints}}
\hypertarget{user-registration}{%
\paragraph{1. User Registration}\label{user-registration}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/register}
\item
\textbf{Method}: \texttt{POST}
\item
\textbf{Description}: This endpoint is used to create a new user
account.
\item
\textbf{Request Body}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String (required) - The desired username of the
user.
\item
\texttt{email}: String (required) - The user's email address.
\item
\texttt{password}: String (required) - The user's password.
\item
\texttt{dateOfBirth}: Date (required) - The user's date of birth.
\item
\texttt{countryOfOrigin}: String (required) - The user's country of
origin.
\item
\texttt{preferredLanguage}: String (required) - The user's preferred
language.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{message}: String - A message describing the outcome.
\item
\texttt{user}: Object - Contains user information (excluding
password).
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{400\ Bad\ Request} if the username already exists,
the email already exists, or the email format is incorrect.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\item
\textbf{Security Notes}:
\begin{itemize}
\tightlist
\item
Passwords are hashed before being stored.
\item
Email validation is performed to check the format.
\end{itemize}
\end{itemize}
\hypertarget{user-login}{%
\paragraph{2. User Login}\label{user-login}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/login}
\item
\textbf{Method}: \texttt{POST}
\item
\textbf{Description}: This endpoint is used for user authentication.
\item
\textbf{Request Body}:
\begin{itemize}
\tightlist
\item
\texttt{login}: String (required) - The user's username or email
address.
\item
\texttt{password}: String (required) - The user's password.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{message}: String - A message describing the outcome.
\item
\texttt{user}: Object - Contains user information (username and
email).
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{400\ Bad\ Request} if either field is missing or if
the user is not found.
\item
Returns \texttt{401\ Unauthorized} if the password does not match.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\item
\textbf{Security Notes}:
\begin{itemize}
\tightlist
\item
Password verification is performed using bcrypt.
\end{itemize}
\end{itemize}
\hypertarget{fetch-user-profile}{%
\paragraph{3. Fetch User Profile}\label{fetch-user-profile}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/user/:username}
\item
\textbf{Method}: \texttt{GET}
\item
\textbf{Description}: Fetches the profile details of a specific user
by their username.
\item
\textbf{URL Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String (required) - The username of the user
whose profile is being requested.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{user}: Object - Contains the requested user's information
(excluding password).
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{404\ Not\ Found} if the user does not exist.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\end{itemize}
\hypertarget{fetch-all-users}{%
\paragraph{4. Fetch All Users}\label{fetch-all-users}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/users}
\item
\textbf{Method}: \texttt{GET}
\item
\textbf{Description}: Retrieves a list of all users. This endpoint is
intended for admin use.
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{users}: Array - A list of user objects, each containing user
information (excluding passwords).
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{401\ Unauthorized} if the user is not authorized
(non-admin).
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\end{itemize}
\hypertarget{update-user-information}{%
\paragraph{5. Update User Information}\label{update-user-information}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/user/:username}
\item
\textbf{Method}: \texttt{PUT}
\item
\textbf{Description}: Allows users to update their account
information.
\item
\textbf{URL Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String (required) - The current username of the
user whose profile is being updated.
\end{itemize}
\item
\textbf{Request Body} (Any or all of the following):
\begin{itemize}
\tightlist
\item
\texttt{newUsername}: String (optional) - The new username for the
user.
\item
\texttt{email}: String (optional) - The new email address for the
user.
\item
\texttt{dateOfBirth}: Date (optional) - The new date of birth for
the user.
\item
\texttt{countryOfOrigin}: String (optional) - The new country of
origin for the user.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{message}: String - A message describing the outcome.
\item
\texttt{user}: Object - Contains the updated user's information.
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{400\ Bad\ Request} if the new username or email
already exists, or if the email format is incorrect.
\item
Returns \texttt{404\ Not\ Found} if the original user is not found.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\item
\textbf{Security Notes}:
\begin{itemize}
\tightlist
\item
Ensure this endpoint is accessible only to the authenticated user or
users with admin privileges.
\item
Validate the email format before processing updates.
\end{itemize}
\end{itemize}
\hypertarget{delete-user}{%
\paragraph{6. Delete User}\label{delete-user}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/user/:username}
\item
\textbf{Method}: \texttt{DELETE}
\item
\textbf{Description}: Deletes a specific user's account.
\item
\textbf{URL Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String (required) - The username of the user to
be deleted.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{message}: String - A message describing the outcome.
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{404\ Not\ Found} if the user does not exist.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\end{itemize}
\hypertarget{fetch-user-stats}{%
\paragraph{7. Fetch User Stats}\label{fetch-user-stats}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/stats/:username}
\item
\textbf{Method}: \texttt{GET}
\item
\textbf{Description}: Retrieves the statistics associated with a
specific user.
\item
\textbf{URL Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String (required) - The username of the user
whose stats are being requested.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{data}: Object - Contains the user's statistics.
\begin{itemize}
\tightlist
\item
\texttt{username}: String - The username of the user.
\item
\texttt{completionPercentages}: Array of Numbers - An array of
completion percentages.
\item
\texttt{points}: Array of Numbers - An array of points.
\item
\texttt{correctAnswers}: Number - The count of correct answers.
\item
\texttt{incorrectAnswers}: Number - The count of incorrect
answers.
\item
\texttt{totalCompletion}: Number - The average of all completion
percentages.
\item
\texttt{totalPoints}: Number - The sum of all points.
\item
\texttt{correctAnswersPercentage}: Number - The percentage of
correct answers.
\item
\texttt{progress}: Array of Objects - Each object contains
\texttt{blockId} and \texttt{minilessonId} representing the user's
progress.
\end{itemize}
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{404\ Not\ Found} if the stats for the given username
are not found.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\end{itemize}
\hypertarget{update-user-stats}{%
\paragraph{8. Update User Stats}\label{update-user-stats}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/stats/:username}
\item
\textbf{Method}: \texttt{PUT}
\item
\textbf{Description}: Updates the statistics associated with a
specific user.
\item
\textbf{URL Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String (required) - The username of the user
whose stats are to be updated.
\end{itemize}
\item
\textbf{Request Body} (Any or all of the following):
\begin{itemize}
\tightlist
\item
\texttt{newPoints}: Number (optional) - The new points to be added
to the user's total on the index of \texttt{locationId}.
\item
\texttt{locationId}: Number (optional) - Identifier of location
where \texttt{newPoints} are to be increased.
\item
\texttt{correctAnswers}: Number (optional) - The amount to increase
total correctAnswers of a user.
\item
\texttt{incorrectAnswers}: Number (optional) - The amount to
increase total incorrectAnswers of a user.
\item
\texttt{progress}: Object (optional) - An object containing the
progress update. When this field is updated, the completion
percentages are automatically recalculated and updated. The object
should have the following structure:
\begin{itemize}
\tightlist
\item
\texttt{locationName}: String (required for progress update) - The
name of the location.
\item
\texttt{locationId}: Number (required for progress update) - The
index in the progress array to update.
\item
\texttt{lessonId}: Number (required for progress update) - The new
lesson ID to set.
\item
\texttt{minilessonId}: Number (required for progress update) - The
new minilesson ID to set.
\item
\texttt{blockId}: Number (required for progress update) - The new
block ID to set.
\end{itemize}
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{message}: String - A message describing the outcome.
\item
\texttt{data}: Object - Contains the updated stats for the user.
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
Returns \texttt{400\ Bad\ Request} if the provided data is invalid
or if required fields are missing.
\item
Returns \texttt{404\ Not\ Found} if no stats are found for the given
username.
\item
Returns \texttt{500\ Internal\ Server\ Error} for any server-side
errors.
\end{itemize}
\end{itemize}
\hypertarget{general-leaderboard}{%
\paragraph{9. General Leaderboard}\label{general-leaderboard}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/leaderboard}
\item
\textbf{Method}: \texttt{GET}
\item
\textbf{Description}: This method provides a leaderboard of the first
100 users, sorted by their total points. It supports optional
filtering based on the user's age and country of origin. Each user's
entry includes their username, country, age, total points, and rank.
\item
\textbf{Query Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{age} (optional): Integer - Specifies the age to filter the
leaderboard.
\item
\texttt{country} (optional): String - Specifies the country to
filter the leaderboard.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{leaderboard}: Array of Objects - List of user rankings, each
containing:
\begin{itemize}
\tightlist
\item
\texttt{username}: String - The user's username.
\item
\texttt{countryOfOrigin}: String - The user's country of origin.
\item
\texttt{age}: Number - The user's age, calculated from their date
of birth.
\item
\texttt{totalPoints}: Number - The total points accumulated by the
user.
\item
\texttt{rank}: Number - The user's rank in the leaderboard. Users
with the same number of points share the same rank.
\end{itemize}
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
On server-side errors, returns \texttt{500\ Internal\ Server\ Error}
with an error message.
\end{itemize}
\end{itemize}
\hypertarget{get-leaderboard-by-user}{%
\paragraph{10. Get Leaderboard By User}\label{get-leaderboard-by-user}}
\begin{itemize}
\tightlist
\item
\textbf{Endpoint}: \texttt{/api/leaderboard/:username}
\item
\textbf{Method}: \texttt{GET}
\item
\textbf{Description}: Retrieves the ranking information of a specific
user across different leaderboards (general, age-based, and
country-based). This method finds the user's rank in each of these
categories. If the user is not found, a 404 error is returned.
\item
\textbf{Path Parameters}:
\begin{itemize}
\tightlist
\item
\texttt{username}: String - The username of the user for whom to
retrieve leaderboard data.
\end{itemize}
\item
\textbf{Response}:
\begin{itemize}
\tightlist
\item
\texttt{success}: Boolean - Indicates if the operation was
successful.
\item
\texttt{userData}: Object - Contains the ranking information of the
user in different leaderboards. It includes:
\begin{itemize}
\tightlist
\item
\texttt{username}: String - The user's username.
\item
\texttt{age}: Number - The user's age, calculated from their date
of birth.
\item
\texttt{country}: String - The user's country of origin.
\item
\texttt{generalRank}: Number - The user's rank in the general
leaderboard.
\item
\texttt{ageRank}: Number - The user's rank in the age-specific
leaderboard.
\item
\texttt{countryRank}: Number - The user's rank in the
country-specific leaderboard.
\end{itemize}
\end{itemize}
\item
\textbf{Error Handling}:
\begin{itemize}
\tightlist
\item
If the user is not found, returns \texttt{404\ Not\ Found} with an
appropriate error message.
\item
On server-side errors, returns \texttt{500\ Internal\ Server\ Error}
with an error message.
\end{itemize}
\end{itemize}
\hypertarget{langchain-endpoints}{%
\subsubsection{Langchain endpoints}\label{langchain-endpoints}}
\hypertarget{get-welcome-message}{%