Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions docs/src/08_concepts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,50 +65,40 @@ include::./diagrams/Domain_Model.puml[]
[cols="2,5",options="header"]
|===
| Entity | Description
| **User** | Represents a player, a stakeholder that will make use of the application. Contains the user's name, email, password, and the list of games played. It represents as well the actions that the user may perform once entering the application, like registering, logging in, playing a game, consulting the statistics.
| **UserStats** | Represents the statistics of a user. Contains the number of games played, the number of questions answered correctly, the number of questions answered wrong, the number of hints used, and other statistics of the user that may be recorded to generate a ranking based on performance.
| **Game** | Represents a game played by a user. Contains the game's mode, the user who played it, the questions, and the answers. It models the main interaction class or entity of the application, as it represents the game itself, the core of the project.
| **GameConfiguration** | Represents the configuration of a game. Contains the number of questions, the time limit, the hints available, and other configurations that may be set by the user before starting a game.
| **Question** | Represents a question in a game. Contains the question's text, the image, the possible answers, and the correct answer.
| **Answer** | Represents an answer to a question. Contains the answer's text and a flag indicating if it is the correct answer.
| **AIChat** | Represents the AI chat that will provide hints to the user.
| **GameMode (Enum)** | Represents the different game modes available in the application. Among the available modes it is possible to find some widely recognized like "Each wise man with his subject", "Travel with us" or "The hot question".
| **QuestionCategory (Enum)** | Represents the different categories of questions available in the application. Some of them are "Science", "Literature", "Famous People", "Sports" or "History".
| **User** | Represents a registered player with a unique username and password.
| **Score** | Stores gameplay results, including game mode, accuracy, and performance.
| **Question** | Contains the quiz question, possible answers, correct answer, and image of the question.
|===

=== Design Patterns and Architectural Styles

The application will be developed following a layered architecture based in the Model-View-Controller (MVC) architectural pattern. This pattern is widely used in web applications and will help to separate the concerns of the application, making it easier to maintain and extend. The MVC pattern divides the application into three interconnected components:
The application will be developed following a microservices Architecture. It will have the following microservices:

- Model: Represents the data of the application, the business logic, and the rules to manage the data. It acts as an intermediary between the external sources of data (persistence systems, APIs, etc.) and the internal structure of the application.
- View: Represents the user interface of the application, the way the data is presented to the user and the way the user interacts with the application.
- Controller: Represents the logic of the application, the way the user input is handled, the way the data is retrieved from the model and the way the view is updated.

Regarding design patterns, the application will make use of the following patterns:

- Singleton: The application will use this pattern to ensure that a class has only one instance and provide a global point of access to it. For example, to ensure that only one instance of the AI chat is created and used to provide hints to the user.
- Factory: The application will use this pattern to create different types of questions and answers based on the game mode selected by the user in an automated and extensible way.
- Observer: The application will use this pattern to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- Strategy: This pattern will be used to define a family of algorithms, encapsulate each one, and make them interchangeable. This will help to promote modularity and maintainability. For example, it will be used to define different strategies for generating questions and answers, and for providing hints to the user.
- Template: This pattern may be used to define the skeleton of an algorithm in any superclass, letting the subclasses override specific steps of the algorithm without changing its structure. This will help to promote code reuse and extensibility, and can be used in different concerns of the application. For example, when defining the different types (categories) of questions or the game modes available in the application.
- Auth Service: It will manage the user login and the creation of the user token.
- User Service: It will manage the signup of new users into the system.
- Question Service: It will manage the generation of questions of different topics that the user will answer.
- Game Service: It will store the game information on the database once the game has finished.
- LLM Service: It will manage the interaction with the AI and it will generate the hints for the user.
- Gateway Service: It will communicate with the rest of microservices to send the information to the frontend.

=== Persistence Layer

The application will rely its data persistence dependencies presumably on a MongoDB database that will manage the data of the application related to the game sessions (questions, answers, game configurations) or related to the user (user session, user statistics...), with the possibility to incorporate another database of the same type and with similar features to treat any of those concerns.
The application will rely its data persistence dependencies on a MongoDB database that will manage the data of the application related to the game sessions (questions, answers, game configurations) or related to the user (user session, user statistics...).

In the future we will change the MongoDB that stores the users to a sqlite database, because with a relational database the user scheme will be more well defined. And several MongoDB instances will be used in the future to avoid the fall of one to affect all microservices.

MongoDB is a NoSQL database that stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time. This flexibility will help to manage the data of the application, as the structure of the data may change over time as the application evolves. It is not a definite decission, but it is a good starting point to consider.

**NOTE:** The persistence layer is susceptible for change at this point. Using MongoDB is not a final decision.

=== Ensuring a wealthy user experience

==== User Interface

The idea of the development team regarding the final application is to make it specially atractive to the final user, with a clean and intuitive design that will make the user experience as pleasant as possible. The application will be developed using a responsive design, so it can be used in different devices, like smartphones, tablets, or desktop computers, enhancing usability, accesibility and adaptability at the maximum possible level. For this reason, the internazionalization of the application will be a key point to consider, as the application is intended to be used by any kind of users of a wide variety of ages and genders and from different countries and cultures.
The development team have designed the application catering to the final user, with a clean and intuitive design that will make the user experience as pleasant as possible. They have developed the application using a responsive design, so it can be used in different devices, like smartphones, tablets, or desktop computers, enhancing usability, accesibility and adaptability at the maximum possible level. For this reason, the internazionalization of the application was a key point to consider, as the application is intended to be used by any kind of users of a wide variety of ages and genders and from different countries and cultures. Right now the application is available in English and Spanish.

==== Session handling and Security

The application will incorporate a basic session handling mechanism to manage the user sessions and to provide a secure environment for the users. The session handling mechanism will be based on the use of JSON Web Tokens (JWT) to authenticate the users and to manage the user sessions.
The application has incorporated a basic session handling mechanism to manage the user sessions and to provide a secure environment for the users. The session handling mechanism is be based on the use of JSON Web Tokens (JWT) to authenticate the users and to manage the user sessions.

==== Error handling

Expand All @@ -120,14 +110,20 @@ The application will have a logging system to monitor the activity of the applic

==== Testing

The application is expected to be tested using a combination of unit tests, integration tests, and end-to-end tests.
The application is tested using a combination of unit tests, end-to-end tests, load test and usability tests.

- **Unit tests** are used to test individual components of the application, mainly based on testing backend functionality to ensure that the internal part of the applications works as expected. Since the application is Dockerized in containers, unit tests can be executed within a container or in a separate testing container that has access to the application's code and dependencies, ensuring that the tests run in an environment identical to production.

- **Unit tests** will be used to test individual components of the application, mainly based on testing backend functionality to ensure that the internal part of the applications works as expected. Since the application will be Dockerized in containers, unit tests can be executed within a container or in a separate testing container that has access to the application's code and dependencies, ensuring that the tests run in an environment identical to production.
- **End-to-end tests** are used to test the application as a whole, simulating the user interaction with the application. They are be performed using containers running the full application stack. This helps to ensure that the application works as expected from the user's perspective.

- **Integration tests** will be used to test the interaction between different components of the application. They can be executed by running multiple service containers in a Docker setup, allowing the test environment to closely mimic the production deployment.
- **Load tests** are used to test the performance of the application using Gattling.

- **End-to-end tests** will be used to test the application as a whole, simulating the user interaction with the application. They can be performed using containers running the full application stack. This will help to ensure that the application works as expected from the user's perspective.
- **Usability tests** are used to test with real users that the application works as expected.

=== Deployment

The application will be deployed using Docker containers. Docker is a platform that allows developers to develop, ship, and run applications in containers. Containers are lightweight, standalone, and executable packages of software that include everything needed to run an application: code, runtime, system tools, system libraries, and settings. This will help to ensure that the application runs consistently in different environments, and that the deployment process is as smooth as possible.
The application is deployed using Docker containers. Docker is a platform that allows developers to develop, ship, and run applications in containers. Containers are lightweight, standalone, and executable packages of software that include everything needed to run an application: code, runtime, system tools, system libraries, and settings. This ensures that the application runs consistently across different environments and that the deployment process remains smooth.

To enable secure HTTPS connections, a reverse proxy such as Nginx is used. Nginx handles SSL termination and routes incoming HTTPS traffic to the appropriate Docker containers. This setup ensures secure communication between clients and the application and simplifies the management of certificates and routing.


137 changes: 36 additions & 101 deletions docs/src/diagrams/Domain_Model.puml
Original file line number Diff line number Diff line change
@@ -1,103 +1,38 @@
@startuml Domain_Model

' Define entities (classes)
class User {
+String userId
+String username
+String email
+String password

+void register()
+void login()
+void play()
+void viewStats()
+void logout()
}

class UserStats {
+int totalGamesPlayed
+int totalQuestionsAnswered
+int totalCorrectAnswers
+int totalIncorrectAnswers
+int totalHintsUsed
+double averageTimePerQuestion

+void updateStats()
}

class Game {
+String gameId
+User player
+GameMode gameMode
+GameConfiguration gameConfig
+List<Question> questions

+void startGame()
+void endGame()
+void obtainQuestions()
+void answerQuestion()
+void askForHint()
}

enum GameMode {
"Each wise man with his subject"
"Travel with us"
"The hot question"
"Discovering cities"
etc.
}

class GameConfiguration {
+int numberOfQuestions
+int timeLimit
+bool hintsEnabled

+void configureGame()
}

class Question {
+String questionId
+String imageUrl
+String questionText
+String wikiDataReference
+QuestionCategory category
+List<AnswerOption> answerOptions

+void validateAnswer()
+void provideHint()
}

enum QuestionCategory {
"Entertainment"
"Science"
"Sports"
"Geography"
"History"
"Literature"
etc.
}

class AnswerOption {
+String optionId
+String optionText
+bool isCorrect
}

class AIChat {
+String sessionId
+String chatHistory
+String wikiDataReference
}


' Define relationships
User "1" --> "0..*" Game : plays
User "1" --> UserStats : has
Game "1" --> "1..*" Question : contains
Game "1" --> GameConfiguration : has
Game "1" --> GameMode : has
Game "1" --> AIChat : includes
Question "1" --> "1..*" AnswerOption : has
Question "1" --> QuestionCategory : belongs to

@enduml
entity "User" {
* username: String
- required, unique, regex: /^[a-zA-Z0-9_]+$/, 3–30 chars
* password: String
- required
* createdAt: Date = now
}

entity "Score" {
* userId: String
- references User._id
* score: Number = 0
* gameMode: String ['basicQuiz', 'expertDomain', 'timeAttack', 'endlessMarathon', 'custom']
- required
* questionsPassed: Number = 0
* questionsFailed: Number = 0
* accuracy: Number = 0
* meanTimeToAnswer: Number = 0
* createdAt: Date = now
}

entity "Question" {
* question: String
- required
* answers: [Object]
- required
* correctAnswerId: Number
- required
* type: String
- required
* image: String
- optional
* createdAt: Date = now (expires in 30 min)
}

@enduml