React Install
- create
FinShark
folder
Required
- npm
- download node.js
- restart your computer
- run
npm
on visual studio code
- React
- run
npm install create-react-app
to create react app
- run
npx create-react-app frontend --template typescript
to create react frontend
- open extensions in visual studio code
- download
ES7+ React/Redux/React-Native snippets
to use react snippets
JSX(JavaScript XML)
- a syntax extension for JavaScript primatily used in React.
- allows to write HTML-like code directly within JavaScript.
Image
- create
assets
folder in src folder - create
image
folder in assets folder - download any iphone image and save it in image folder
- name it to
iphone.jpg
Card
- create
components
folder in src folder - create
Card
folder in components - create
Card.tsx
andCard.css
files in card folder
- Card.tsx
- type
tsrafce
to use snippets
App
-
App.tsx
andApp.css
are already in src folder -
App.tsx
- App.css
Run
- type
cd frontend
in terminal - type
npm run start
Props
- means properties.
- are used to pass data from one component to another; Data Flow.
- are
read-only
.
Interface vs Type
-
In TypeScript, both
interface
andtype
are used to define the structure of objects - interface
- Extensibility: interfaces can be extended using the
extends
keyword to create more complex types. -
Declaration merging: If there is more than two interfaces with same name, TypeScript will merge them together.
- type
- Cannot extend: type cannot be extended.
- No delaration merging: If there is more than two types with same name, it occurs error.
CardList
- create
CardList
folder in components folder -
create
CardList.tsx
andCardList.css
files in CardList folder - CardList.tsx
- Card.tsx
App
- App.tsx
Function Components
React.FC
- React Function Component
- Automatic typing of childern: React.FC component can implicitly accept children.
- Prop types enforcement: React.FC ensures that props passed to the component match the specified interface.
JSX.Element
-
JSX.Element
is the standard return type for functional components in React that use JSX to render UI elements -
JSX.Element
is essentially the type definition for a React element, such as an HTML tag, a React component, or a fragment
Card
- Card.tsx
CardList
- CardList.tsx
Hook
- React hooks are special function that enable stateful logic and side-effects in functional components.
- Hooks allow to use features like state and lifecycle events without converting the component to a class component.
useState
- a function that allows to update the state value: initialization and updating.
Search
- create
Search
folder in components folter -
create
Search.tsx
andSearch.css
in search folder - Search.tsx
App
- App.tsx
Event Handler
ChangeEvent
-
ChangeEvent
helps strongly type the event object for form elements such as<input>
,<textarea>
, or<select>
. -
ChangeEvent
ensures that TypeScript can provice autocomplete and type safety when accessing event properties likeevent.target.value
.
SyntheticEvent
- Different browsers handle slightly diffrently, but
SyntheticEvent
abstracts those differences. React can be worked with a consistent event object across all browers. - React pools event objects to improve performance. Instead of creating a new event object for every event, React reuses them, reducing memory consumption.
Search
- Search.tsx
Modeling
axios
- returns promises, making it easy to work with asynchronous code using
.then()
and.catch()
, or withasync/await
. - can make requests using
get
,post
,put
anddelete
. - provides a straightforward mechanism to handle errors, such as failed requests or responses with error status codes.
dotenv
- allows to define environment variables in a
.env
file and load them intoprocess.env
, making them accessible within your Node.js application. - keeps sensitive information, such as API keys or database passwords, out of your codebase.
Required
- type
npm install axios --save
in terminal - type
npm install --save-dev @types/axios
in terminal - type
npm install dotenv --save
in terminal
Environment
-
open financial modeling prep to get your api key.
- .env
- create
.env
file on frontend folder - open
.env
file and typeREACT_APP_API_KEY=
with your api key.
Company Model
-
create
company.d.tsx
file on src folder -
company.d.tsx
API
-
create
api.tsx
file on src folder -
api.tsx
index
- index.tsx
Data Flow
App
- App.tsx
Search
- Search.tsx
Type Narrowing
- for type checking with
if-else
. - when type is different with the expectation, it occurs error.
App
- App.tsx
Conditional Rendering
-
A === B ? C : D
renders C when it is true, D when it is false. -
A === B ?? C
renders C when it is true
App
- App.tsx
map()
- does not modify the original array.
- creates a new array based on the transformation applied to each element.
- is often used for iterating over arrays to transform or process each item.
uuid(Universally Unique Identifier)
- is typically represented as a 32-character hexadecimal string, separated by hyphens into five groups.(8-4-4-4-12)
Required
- type
npm install uuid
in terminal - type
npm install --save-dev @types/uuid
in terminal
App
- App.tsx
CardList
Card
Forms
Portfolio
- create
Portfolio
folder in components folder - create
AddPortfolio
folder in Portfolio folder -
create
AddPortfolio.tsx
andAddPortfolio.css
in AddPortfolio folder - AddPortfolio.tsx
Card
- Card.tsx
CardList
- CardList.tsx
App
- App.tsx
Search
- Search.tsx
Arrays
preventDefault()
- stops form submission to handle it with JavaScript(e.g. forms, links and etc)
- is a method used to prevent the default behavior of an event
…
- creates a copy without modifying the original
- combines multiple arrays into a single array
- adds new elements to an array at the beginning, middle, or end
- passes array elements as individual arguments to functions
- captures the first elements or the rest of an array using destructuring.
CardPortfolio
- create
CardPortfolio
in Portfoilo folder -
create
CardPortfolio.tsx
andCardPortfolio.css
in CardPortfolio folder - CardPortfolio.tsx
ListPortfolio
- ListPortfolio.tsx
App
- App.tsx
Delete
App
- App.tsx
ListPortfolio
- ListPortfolio.tsx
CardPortfolio
- CardPortfolio.tsx
DeletePortfolio
- create
DeletePortfolio
folder in Portfoilo folder -
create
DeletePortfolio.tsx
andDeletePortfolio.css
in DeletePortfolio folder - DeletePortfolio.tsx
Tailwind
- type
npm install -D tailwindcss
in terminal - type
npx tailwindcss init
in terminal -
check document in tailwindcss
- tailwind.config.js
- index.css
Title
- open
public
folder in frontend folder - open
index.html
and change<title>React App</title>
to<title>FinShark</title>
images
- add
hero.png
andlogo.png
in images folder
App
- App.tsx
Search
- Search.tsx
ListPortfolio
- ListPortfolio.tsx
DeletePortfolio
- DeletePortfolio.tsx
CardPortfolio
- CardPortfolio.tsx
AddPortfolio
- AddPortfolio.tsx
Navbar
- Navbar.tsx
Hero
- create
Hero
folder in components folder -
create
Hero.tsx
andHero.css
in Hero folder - Hero.tsx
CardList
- CardList.tsx
Card
- Card.tsx
React Router
- type
npm install -save react-router
in terminal - type
npm install -save react-router-dom
in terminal - type
npm install -save @types/react-router
in terminal - type
npm install -save @types/react-router-dom
in terminal
Outlet
- is a component in React Router used to render child within a parent route.
- acts as a placeholder whrer the content of nested routes will be displayed.
Router
- create
routes
folder in src folder -
create
Routes.tsx
- Routes.tsx
- index.tsx
HomePage
- create
pages
folder in src folder - create
HomePage
folder in pages folder -
create
HomePage.tsx
andHomePage.css
in HomePage folder - HomePage.tsx
SearchPage
- create
SearchPage
folder in pages folder -
create
SearchPage.tsx
andSearchPage.css
in SearchPage folder - SearchPage.tsx
Hero
- create
Hero
folder in components folder -
create
Hero.tsx
andHero.css
in Hero folder - Hero.tsx
Navbar
- Navbar.tsx
CardPortfolio
- CardPortfolio.tsx
CardList
- CardList.tsx
Card
- Card.tsx
App
- App.tsx
useEffect
- is a React hook used for side effects.
- runs after the first render by default and can re-run based on changes to dependencies.
useParams
- is a React Router hook used to access the dynamic parameters in the current URL.
- returns an object with key-value pairs corresponding to the named parameters in the route path.
- works with nested routes or multiple parameters and makes it easy to build dynamic, URL-driven applications.
Api
- api.tsx
Card
- Card.tsx
CompanyPage
- create
CompanyPage
folder in page folder -
create
CompanyPage.tsx
andCompanyPage.css
in CompanyPage folder - CompanyPage.tsx
Router
- Routes.tsx
Dashboard
useParams
react-icons
- type
npm install react-icons --save
in terminal - check icons in react-icons
CompanyProfile
- create
CompanyProfile
folder in components folder -
create
CompanyProfile.tsx
andCompanyProfile.css
in CompanyProfile folder - CompanyProfile.tsx
Router
- Routes.tsx
CompanyDashboard
- create
CompanyDashboard
folder in components folder -
create
CompanyDashboard.tsx
andCompanyDashboard.css
in CompanyDashboard folder - CompanyDashboard.tsx
CompanyPage
- CompanyPage.tsx
Sidebar
- Sidebar.tsx
Tile
- Tile.tsx
Table
- create
Table
folder in components folder -
create
testData.tsx
,Table.tsx
andTable.css
in Table folder - testData.tsx
- Table.tsx
DesignPage
- create
DesginPage
folder in pages folder -
create
DesignPage.tsx
andDesignPage.css
in DesignPage folder - DesignPage.tsx
Router
- Routes.tsx
RatioList
- create
RatioList
folder in components folder -
create
RatioList.tsx
andRatioList.css
in RatioList folder - RatioList.tsx
DesignPage
- DesignPage.tsx
Company Profile
useOutletContext
-
is a hook provided by React Router to access context data passed through
Outlet
. -
CompanyProfile.tsx
CompanyDashboard
- CompanyDashboard.tsx
RatioList
- RatioList.tsx
Company Model
- company.d.ts
Api
- api.tsx
CompanyPage
- CompanyPage.tsx
DesignPage
- DesignPage.tsx
Income Statement
- create
IncomeStatement
folder in components folder -
create
IncomeStatement.tsx
andIncomeStatement.css
in IncomeStatement folder - IncomeStatement.tsx
Sidebar
- Sidebar.tsx
Table
- Table.tsx
DesignPage
- DesignPage.tsx
Routes
- Routes.tsx
Api
- api.tsx
Balance Sheet
- create
BalanceSheet
folder in components folder -
create
BalanceSheet.tsx
andBalanceSheet.css
in BalanceSheet folder - BalanceSheet.tsx
Api
- api.tsx
Routes
- Routes.tsx
Sidebar
- Sidebar.tsx
- RatioList.tsx
- RatioList.tsx
Cash Flow Statement
- create
CashFlowStatement
folder in components folder -
create
CashFlowStatement.tsx
andCashFlowStatement.css
in CashFlowStatement folder - CashFlowStatement.tsx
Api
- api.tsx
Routes
- Routes.tsx
Routes
- Routes.tsx
Routes
- Sidebar.tsx
Spinner
- type
npm install react-spinners
- create
Spinner
folder in components folder -
create
Spinner.tsx
andSpinner.css
in Spinner folder - Spinner.tsx
BalanceSheet
- BalanceSheet.tsx
CashFlowStatement
- CashFlowStatement.tsx
CashFlowStatement
- CompanyProfile.tsx
IncomeStatement
- IncomeStatement.tsx
CompanyPage
- CompanyPage.tsx
Formatting
Number Formatting
- create
Helpers
folder in components folder -
create
NumberFormatting.tsx
in Helpers folder - NumberFormatting.tsx
BalanceSheet
- BalanceSheet.tsx
CashFlowStatement
- CashFlowStatement.tsx
CompanyProfile
- CompanyProfile.tsx
IncomeStatement
- IncomeStatement.tsx
Api
- create
Api
application as.net Asp Core Web Api
with visual studio
SQL Server Management Studio
- download SQL Server
- download SQL Server Management Studio
Models
- create
Model
folder in Api project
Stock.cs
Comment.cs
Entity Framework
- open
Nuget Package Manager
in Api project - download
Microsoft.EntityFrameworkCore.Design
- download
Microsoft.EntityFrameworkCore.Tools
- download
Microsoft.EntityFrameworkCore.SqlServer
SQL Server Management Studio
- create new
finshark
database
DBContext
- create
Data
folder in Api project -
create
ApplicationDBContext.cs
in Data folder - ApplicationDBContext.cs
Program
- Program.cs
- appsettigs.json
Database
- open
Developer Power Shell
in visual studio - type
doenet ef migrations add init
- type
doenet ef database update
SQL Server Management Studio
- right click
dbo.Stocks
table in finshark database - click
Edit Top 200 Rows
- insert some values
Stock
Controller
-
create
StockController.cs
in Controllers folder -
StockController.cs
DTOs
- create
Dtos
folder in Api folder - create
Stock
folder in Dtos folder -
create
StockDto.cs
in Stock folder - StockDto.cs
-
create
CreateStockRequestDto.cs
in Stock folder -
CreateStockRequestDto.cs
-
create
UpdateStockRequestDto.cs
in Stock folder -
UpdateStockRequestDto.cs
Mapper
- create
Mappers
folder in Api folder -
create
StockMappers.cs
in Mappers folder - StockMappers.cs
Interfaces
- create
Interfaces
folder in Api folder -
create
IStockRepository.cs
in Interfaces folder - IStockRepository.cs
Repository
- create
Repository
folder in Api folder -
create
StockRepository.cs
in Repository folder - StockRepository.cs
Program
- Program.cs
Comment
Controller
-
create
CommentController.cs
in Controllers folder -
CommentController.cs
DTOs
- create
Stock
folder in Dtos folder -
create
CommentDto.cs
in Comment folder - StockDto.cs
-
create
CreateCommentRequestDto.cs
in Comment folder -
CreateCommentRequestDto.cs
-
create
UpdateCommentRequestDto.cs
in Comment folder -
UpdateCommentRequestDto.cs
Mapper
-
create
CommentMapper.cs
in Mappers folder -
CommentMapper.cs
Interfaces
-
create
ICommentRepository.cs
in Interfaces folder -
ICommentRepository.cs
Repository
-
create
CommentRepository.cs
in Repository folder -
CommentRepository.cs
Program
- Program.cs
Data Validation
Controller Validation
- You can set route’s type with
:{type}
-
If you use data annotation in Dtos, you can alert to user with error message by
ModelState
- StockController.cs
- CommentController.cs
Data Annotations
- CreateCommentRequestDto.cs
- UpdateCommentRequestDto.cs
- CreateStockRequestDto.cs
- UpdateStockRequestDto.cs
Filtering
Program
- Download
Newtonsoft.Json
in Nuget Package Manager -
Download
Microsoft.AspNetCore.Mvc.NewtonsoftJson
in Nuget Package Manager - Program.cs
Program
- Download
Newtonsoft.Json
in Nuget Package Manager -
Download
Microsoft.AspNetCore.Mvc.NewtonsoftJson
in Nuget Package Manager - Program.cs
Helpers
- create
Helpers
folder in Api folder -
create
QueryObject.cs
in Helpers folder - QueryObject.cs
Interfaces
- IStockRepository.cs
Repository
- StockRepository.cs
Controller
- StockController.cs
Identify
IdentityDbContext
- is a specialized DbContext provided by the Entity Framework (EF) to handle authentication and authorization.
- includes several built-in DbSets (tables) that support the default identity functionality, like users, roles and claims.
IdentityRole
- is the built-in role model from ASP.NET Core Identity, representing user roles in the application.
- allows to define roles like “Admin”, “User” and etc.
Authentication
- in an ASP.NET Core application can use JWT (JSON Web Token) Bearer Authentication.
-
JwtBearerDefaults.AuthenticationScheme
uses the JWT Bearer token approach.
TokenValidationParameters
- ensures that only valid and authorized tokens are accepted.
app.useAuthentication()
- is a middleware that enables the authentication system within the request pipeline.
- should be placed before
app.UseAuthorization()
Nuget Packages
- Download
Microsoft.AspNetCore.Authentication.JwtBearer
in Nuget Package Manager - Download
Microsoft.AspNetCore.Identity.EntityFrameworkCore
in Nuget Package Manager - Download
Microsoft.Extensions.Identity.Core
in Nuget Package Manager
Data
- ApplicationDBContext.cs
Models
-
create
AppUser.cs
in Models folder -
AppUser.cs
appsettigs
- appsettigs.json
Program
- Program.cs
Database
- type
dotnet ef migrations add Identity
in developer power shell - type
dotnet ef database update
in developer power shell
Registration
UserManager
- provides a high-level API for managing user-related operations in applications that use ASP.NET Identity for authentication and authorization.
OnModelCreating
- provides a place to customize the model created by Entity Framework Core before generateing the database.
DTOs
-
create
RegisterDto.cs
in Dtos folder -
RegisterDto.cs
Controller
-
create
AccountController.cs
in Controllers folder -
AccountController.cs
ApplicationDBContext
- ApplicationDBContext.cs
Database
- type
dotnet ef migrations add SeedRole
in developer power shell - type
dotnet ef database update
in developer power shell
Token
JWT (Json Web Token)
- is used in applications to securely transmit information for stateless, secure and cross-platform authentication.
- allows applications to manage user sessions without relying on centralized server-side session.
- you can decode your JWT in https://jwt.io/
DTOs
-
create
NewUserDto.cs
in Dtos folder -
NewUserDto.cs
Interfaces
-
create
ITokenService.cs
in Interfaces folder -
ITokenService.cs
Services
- create
Services
folder -
create
TokenService.cs
in Services folder - TokenService.cs
Controllers
- AccountController.cs
Program
- Program.cs
appsettigs
- appsettigs.json
Login
DTOs
-
create
LoginDto.cs
in Dtos folder -
LoginDto.cs
Program
- Program.cs
Controllers
- AccountController.cs
- CommentController.cs
- StockController.cs
Portfolio
Database Relationship
- means like n:n, 1:n, n:1 and 1:1.
-
HasOne
sets up 1:1 or 1:n relationships between entities. -
WithMany
sets up n:1 or n:n relationships between entities. -
HasKey
sets a primary key from a composite key in an entity -
HasForeignKey
sets a foreign key to refer an entity
Models
-
create
Portfolio.cs
in Models folder -
Portfolio.cs
- AppUser.cs
- Comment.cs
- Stock.cs
Data
- ApplicationDBContext.cs
Extensions
- create
Extensions
folder in Api folder -
create
ClaimsExtensions.cs
in Extensions folder - ClaimsExtensions.cs
Interfaces
-
create
IPortfolioRepository.cs
in Interfaces folder -
IPortfolioRepository.cs
- IStockRepository.cs
Repository
-
create
PortfolioRepository.cs
in Repository folder -
IPortfolioRepository.cs
- StockRepository.cs
Program
- Program.cs
PortfolioController
- PortfolioController.cs
Database
- type
dotnet ef migrations add ManyToMany
- type
dotnet ef database update
Comment
DTOs
- CommentDto.cs
Models
- Comment.cs
Mappers
- CommentMapper.cs
Repository
- CommentRepository.cs
- StockRepository.cs
Controllers
- CommentController.cs
- StockController.cs
Database
- type
dotnet ef migrations CommentOneToOne
- tpye
dotnet ef database update
HttpClient
DTOs
-
create
FinancialModelingPrepStock.cs
in Dtos folder -
FinancialModelingPrepStock.cs
Interfaces
-
create
IFinancialModelingPrepService.cs
in Interfaces folder -
IFinancialModelingPrepService.cs
Services
-
create
FinancialModelingPrepService.cs
in Services folder -
FinancialModelingPrepService.cs
appsettigs
- appsettigs.json
Mappers
- StockMapper.cs
Program
- Program.cs
Controllers
- PortfolioController.cs
- CommentController.cs
OrderBy
Helpers
-
create
CommentQueryObject.cs
in Helpers folder -
CommentQueryObject.cs
Interfaces
- ICommentRepository.cs
Repository
- CommentRepository.cs
Controllers
- CommentController.cs
CORS(Cross-Origin Resource Sharing)
- is a browser security feature that restricts web pages from making requests to a different origin.
- APIs are hosted on different domains than the websites that consume them.
- CORS allows controlled access to these APIs.
Program
- Program.cs
CommentController
- CommentController.cs
AuthService
- type
npm install react-toastify
in terminal for toasting.
App
- App.tsx
ErrorHandler
- create
helpers
folder in src -
create
ErrorHandler.tsx
in helpers folder - ErrorHandler.tsx
- Array of errors (Array.isArray): Handles multiple errors and displays each one as a warning.
- Object of errors (typeof === ‘object’): Iterates through the object’s keys and displays the first error message for each key.
- General error message (err?.data): Displays a single error message.
- Authentication error (401 status): Prompts the user to log in and redirects them to the login page.
- Unexpected errors: Displays the raw error object as a warning.
User
- create
models
folder in src -
create
User.tsx
in models folder - User.tsx
AuthService
- create
services
folder in src -
create
AuthService.tsx
in services folder - AuthService.tsx
Context
- a component with no JSX that is global
- is can be shared
User
- User.tsx
useAuth
- create
contexts
folder in src -
create
useAuth.tsx
in contexts folder - useAuth.tsx
App
- App.tsx
Login
- type
npm install react-hook-form yup @hookform/resolvers
in terminal to use form
useForm
- is a popular utility in libraries like React Hook Form, allowing developers to manage form state, handle validation, and submit logic in React applications.
LoginPage
- create
LoginPage
folder in pages -
create
LoginPage.tsx
andLoginPage.css
files in LoginPage folder - LoginPage.tsx
Routes
- Routes.tsx
Register
RegisterPage
- create RegisterPage folder in pages folder
-
create
RegisterPage.tsx
andRegisterPage.css
in RegisterPage folder - RegisterPage.tsx
Routes
- Routes.tsx
Protected Routes
- is for protecting to show pages with authorization.
- navigates directly to login page when the page is protected.
ProtectedRoute
-
create
ProtectedRoute.tsx
in routes folder -
ProtectedRoute.tsx
Routes
- Routes.tsx
Logout
Navbar
- Navbar.tsx
Comment
{…register()}
- is same with
value={title} onChange={(e) => setTitle(e.target.value)}
. - is making easy to use validation and to manage value.
Comment
-
create
Comment.tsx
in models folder -
Comment.tsx
CommentService
-
create
CommentService.tsx
in services folder -
CommentService.tsx
StockComment
- create StockComment folder in components folder
-
create
StockComment.tsx
andStockComment.css
in StockComment folder - StockComment.tsx
StockCommentForm
- create StockCommentForm folder in StockComment folder
-
create
StockCommentForm.tsx
andStockCommentForm.css
in StockCommentForm folder - StockCommentForm.tsx
CompanyProfile
Comment List
Comment
- Comment.ts
CommentService
- CommentService.tsx
StockComment
- StockComment.tsx
StockCommentList
- create
StockCommentList
folder in components folder -
create
StockCommentList.tsx
andStockCommentList.css
files in StockCommentList folder - StockCommentList.tsx
StockCommentListItem
- create
StockCommentListItem
folder in components folder -
create
StockCommentListItem.tsx
andStockCommentListItem.css
files in StockCommentListItem folder - StockCommentListItem.tsx
Portfolio Service
Portfolio
-
create
Portfolio.ts
in models folder -
Portfolio.ts
PortfolioService
-
create
PortfolioService.ts
in services folder -
PortfolioService.tsx
CardPortfolio
- CardPortfolio.tsx
DeletePortfolio
- DeletePortfolio.tsx
ListPortfolio
- ListPortfolio.tsx
SearchPage
- SearchPage.tsx