0% found this document useful (0 votes)
8 views7 pages

CrunchyBanana: Key Software Themes

The video script presents an exploration of the CrunchyBanana project through four key software themes: software design principles, event-driven programming, interoperability, and virtual identity. It details the game's structure, user interface, and backend architecture, highlighting the use of OOP principles, event handling in React, and session management for user identity. The presenter emphasizes the importance of these themes in creating maintainable, efficient, and user-friendly software.

Uploaded by

xanjv.exotrac
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

CrunchyBanana: Key Software Themes

The video script presents an exploration of the CrunchyBanana project through four key software themes: software design principles, event-driven programming, interoperability, and virtual identity. It details the game's structure, user interface, and backend architecture, highlighting the use of OOP principles, event handling in React, and session management for user identity. The presenter emphasizes the importance of these themes in creating maintainable, efficient, and user-friendly software.

Uploaded by

xanjv.exotrac
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Video Script: Exploring CrunchyBanana Through Four Key Software Themes

Presenter: "Hello I’m Sanjeev Kumar Shrestha and my UoB Registration Number is
2146514. Today, I’m going to explore the project, focusing on four key software
themes: software design principles (OOP), event-driven programming, interoperability,
and virtual identity."

Presenter: " Let's start with a short demonstration of the game. Here's my game UI.
As you can see, it's a straightforward and engaging interface. Users can login or
register if don’t have login credentials. Now I am creating Sanjeev as a username and
password and login to the game portal. The main menu provides options to start a
new game with three difficulty levels with a timer and without a timer where players
can enjoy the game with challenges. When Enable Timer is checked Timer difficulty is
increased and Timer will have low amount of time. 3 minutes for Easy, 2 minutes for
Medium and 1 minute for Hard, I am choosing Easy with timer. Lives system where
players have 9 attempts to answer. Players lose a life for each incorrect answer. The
game also includes timeout-based events, such as the countdown timer in the game
and if the timer runs out, the game will be over. Also, games have Leaderboard which
shows the user highest score with difficulty level achieved as score history and current
score board."

Presenter: "Now, let’s talk about the project and how it runs. CrunchyBanana is
structured using the three-tier architecture, which includes the database (MySQL), the
server ([Link]), and the client (React TypeScript)."

Presenter: " Here’s my main server file, [Link]."

[Highlighting lines 19-22 in [Link]]

// server/[Link]

[Link](cors({

credentials: true,

origin: ["[Link] "*"],

}));

Presenter: "Here, I’ve enabled CORS on lines 19 to 22 to allow my server to handle


HTTP requests from any site. And Line 20 Allows credentials (cookies, headers, etc.) to
be sent with requests.

[Highlighting lines 32-42 in [Link]]

// server/[Link]

[Link]('/api/auth', auth);

Page | 1
[Link]('/api/user', users);

[Link]('/api/games', authorize, game);

Presenter: "Also From lines 32 to 42, I’ve defined various endpoints or routes to
handle different HTTP requests, such as authentication, user management, and game
records."

[Switching to client directory and showing [Link]]

Presenter: "Now let’s see On the client side, in [Link], I manage page loading
states using the isLoading state. If the user is already logged in and their session
hasn't expired, they’re redirected to the dashboard. Otherwise, they’re taken to the
Authpage where user need to provide credentials username and password or register."

[Highlighting lines 10-20 in [Link]]

// client/src/[Link]

if (isLoading) {

return <div>Loading...</div>;

if (user) {

return <Dashboard />;

return <AuthPage />;

[Scene switches back to presenter]

Presenter: "Now, let’s dive deeper into the four main themes, starting with software
design principles (OOP). My project is divided into modules like models, views,
controllers, services, and hooks, making it highly modular and maintainable."

Page | 2
OOP
[Server directory: [Link]]

Presenter: "In my server directory, controllers like [Link] handle HTTP


requests and responses, while models contain data and business logic. This separation
of concerns is a hallmark of good object-oriented design."

[Highlighting lines 32-35 in [Link]]

// server/controllers/[Link]

[Link]('/register', async (req, res) => {

const { username, password, fullname } = [Link];

// Registration logic...

});

[Highlighting lines 45 in [Link]]

// server/controllers/[Link]

[Link]('/login', async (req, res) => {

const { username, password } = [Link];

// Login logic...

});

Another example Client directory SignupPage Line 4 code

Another example, In this code, I can see an example of the Single Responsibility
Principle (SRP) in action.

const SignUpForm = () => {

// ...

Here, I have a single function SignUpForm that is responsible for rendering the sign-
up form and handling its submission. This follows the SRP principle, which states that
a function should have only one reason to change.

Line 5 and 8

Another principle I can see here is the Don't Repeat Yourself (DRY) principle. I’m using
React hooks like useState and useRef to manage state and references, which helps
us avoid duplicating code.

const [error, setError] = useState<string | null>(null);

const fullNameRef = useRef<HTMLInputElement>(null);


Page | 3
EVENT-DRIVEN PROGRAMMING
Presenter: "Next, let’s discuss event-driven programming. My client-side React
components, such as [Link], utilize event handlers like handleSubmit to
respond to user actions and Handles the form submission event."

[Client directory: [Link]]

[Highlighting lines 12 in [Link]]

const handleOnSubmit = (e: FormEvent<HTMLFormElement>) => {

Presenter: "Here On lines 12, I’m defining a function handleOnSubmit that will be
called when the form is submitted. This function will handle the submission event and
perform the necessary actions. "

Another example of event-driven programming is the use of React's useState hook to


manage state changes.

[Highlighting lines 8 in [Link]]

const [error, setError] = useState<string | null>(null);

Client/src/components/[Link]

Another example is Handling Timer Events Line 12 - 25

In the Timer component, I have a timer that triggers an event every second:

useEffect(() => {

const timer = setInterval(() => {

// Handle timer event logic here

}, 1000);

return () => clearInterval(timer);

}, []);

This is an example of Event-Driven Programming, where I define a function that will be


called every second (1000 milliseconds). The function is called with no arguments,
and it will handle the timer event logic.

Page | 4
INTEROPERABILITY
[Scene switches back to presenter]

Client/src/services/[Link]

Presenter: "Interoperability is another key aspect. My service layer, particularly


[Link], manages HTTP requests and responses. This refers to the ability of
different systems or components like frontend and backend to work together and
communicate seamlessly."

[Client directory: [Link]]

Presenter: "In [Link], located at client/src/services/[Link], I configure the


base URL and create methods to interact with my backend APIs."

[Highlighting lines 10-20 in [Link]]

// client/src/services/[Link]

const apiClient = [Link]({

baseURL: '[Link]

withCredentials: true,

});

Presenter: "Lines 4-9 set up my API client to handle HTTP requests with the correct
parameters."

Another example

Client/src/pages/[Link] Line 1-2

Here, I’m importing React hooks and a custom hook useSignUp from another file.
This shows how React and TypeScript can work together to provide a robust and
maintainable codebase.

Another example of interoperability is the use of CSS classes to style my components.

Line 42 SignupPage

Page | 5
VIRTUAL IDENTITY
[Scene switches back to presenter]

Presenter: "Finally, let's discuss virtual identity. I’ve used session cookies to maintain
user identity across multiple requests, ensuring a consistent and secure user
experience."

[Server directory: [Link] handling session cookies]

Presenter: "In [Link], lines 25-28, I’ve managed session cookies to keep users
authenticated across different parts of the application."

[Highlighting lines 25-28 in [Link]]

// server/[Link]

[Link](cookieParser());

[Link]([Link]({ limit: '2048mb' }));

Presenter: "These lines handle the session cookies, ensuring that each user remains
logged in during their session."

[Client directory: [Link] showing session handling]

Presenter: "My [Link] hook, located at client/src/hooks/[Link], sends


user credentials to the server and manages the session cookie, maintaining the user's
virtual identity."

[Highlighting lines 4-34 in [Link]]

// client/src/hooks/[Link]

const useSignin = () => {

const [isLoading, setLoading] = useState(false);

const signIn = async ({ username, password }) => {

setLoading(true);

const response = await [Link]('/auth/login', { username,


password });

setLoading(false);

return [Link];

};

return { signIn, loading };

};

Presenter: "Lines 4-34 in [Link] show how it handle user sign-in and manage
their session."

Page | 6
[Link] Line 17 - 24

Another example In this code, I can see an example of virtual identity in the way it is
handling user input and validation.

const fullName = [Link]!.value;

const username = [Link]!.value;

const password = [Link]!.value;

if (!/^[A-Za-z]+\s[A-Za-z]+$/.test(fullName)) {

setError("Full name must contain at least two words.");

return;

Here, I’m using references to access user input values and performing validation on
those values. This shows how my code is managing user identity and data.

[Closing Scene: Presenter summarizing]

Presenter: "In summary, I've shown how the four themes of software design
principles, interoperability, event-driven programming, and virtual identity are
reflected in this project. By following software design principles, I can write
maintainable and efficient code. Interoperability allows us to work with different
systems and components seamlessly. Event-driven programming helps us handle user
interactions and drive the flow of my program. And finally, virtual identity helps us
manage user data and identity effectively.

Thanks for watching, and I hope this video has helped you understand these
important themes in software design!"

Page | 7

Common questions

Powered by AI

CrunchyBanana utilizes virtual identity management by implementing session cookies that maintain user authentication across multiple requests . This is enabled in the server.ts file where session cookies are managed, ensuring users stay logged in during their session . Additionally, the useSignin hook sends user credentials to the server, managing session cookies to maintain the user's virtual identity .

CrunchyBanana addresses security concerns in its login and registration functionalities by employing secure handling of user credentials. The userController.ts file contains specific logic for registering and logging in users with username and password which are crucial points for security . Additionally, session cookies are managed to maintain secure authentication across multiple user requests, thereby preventing unauthorized access and ensuring data integrity .

The CrunchyBanana project employs Object-Oriented Programming principles by dividing its architecture into modules such as models, views, controllers, services, and hooks, ensuring high modularity and maintainability. This modular approach allows for a separation of concerns where each module handles specific responsibilities, which is a hallmark of good object-oriented design . Examples include using controllers like userController.ts to handle HTTP requests and responses while models contain the data and business logic .

CrunchyBanana's leaderboard feature enhances the gaming experience by providing users with a way to view high scores alongside associated difficulty levels, motivating players to improve their performance and engage more with the game . By creating a competitive environment, users are encouraged to earn higher scores and beat their previous records, thereby increasing return play and overall engagement .

CrunchyBanana implements the Single Responsibility Principle by ensuring that each component in its design has a single responsibility. For instance, in the client directory, the SignUpForm function is dedicated solely to rendering the signup form and processing its submission, reflecting SRP adherence . This principle is crucial as it reduces the complexity of each component, making the codebase easier to maintain and less prone to errors, as changes in one responsibility do not affect others .

CORS (Cross-Origin Resource Sharing) plays a crucial role in CrunchyBanana's server setup by allowing the server to handle HTTP requests from different origins securely. In the server.ts file, CORS is enabled to permit requests with credentials from specified origins, thereby balancing security and accessibility . This setup ensures that the application can perform cross-domain requests smoothly without exposing the server to unauthorized access, thus maintaining security while optimizing performance .

React hooks play a significant role in maintaining the state and behavior of CrunchyBanana's user interface by providing a functional way to manage state and lifecycle methods in React components. For example, useState and useRef hooks are utilized to manage state and DOM references, respectively, which helps in avoiding code duplication and maintaining DRY principles . Similarly, components like Timer.tsx leverage hooks like useEffect to trigger events and maintain responsive UI behavior .

CrunchyBanana employs a three-tier architecture consisting of a database (MySQL), server (Node.js), and client (React TypeScript) which enhances scalability and organization by separating the application into distinct layers . This separation allows each layer to scale independently, manage its own operations, and facilitates debugging and maintenance while keeping the overall structure organized and streamlined .

CrunchyBanana ensures interoperability by configuring the API client in apiClient.ts to handle HTTP requests with parameters such as a base URL and credentials across systems . Additionally, it uses a service layer to manage these interactions, ensuring that the frontend React application communicates effectively with the backend Node.js server . The use of CSS classes for styling components further demonstrates seamless cooperation between technologies .

CrunchyBanana demonstrates event-driven programming through its client-side React components that use event handlers like handleOnSubmit to manage user actions and form submissions . Additionally, it employs the useState hook to manage state changes, and includes a Timer component which triggers an event every second using setInterval, illustrating the dynamic response to user interactions and time-based events in the interface .

You might also like