A modern, full-featured React TypeScript web application for searching and viewing stock information with authentication, advanced filters, pagination, sorting, and real-time autocomplete.
- Smart Search Bar: Real-time autocomplete with debouncing for efficient API calls
- Advanced Filters: Comprehensive filtering by:
- Previous Close Price range
- P/E Ratio (min/max)
- Forward P/E Ratio (min/max)
- Dividend Yield percentage (min/max)
- Market Cap range (min/max)
- Payout Ratio percentage (min/max)
- Pagination & Sorting: Full support for paginated results with customizable page size and multi-column sorting
- Secure Authentication: NeonDB-backed authentication with protected routes
- Responsive Design: Mobile-friendly UI with modern styling
- Type-Safe: Built with TypeScript for better developer experience
- Protected Routes: Route guards for authenticated and public pages
- Data Table Display: Professional table view with all stock metrics
StockInformationWebsiteFrontend/
βββ public/
β βββ index.html
βββ src/
β βββ auth/ # Authentication pages
β β βββ Login.tsx
β β βββ Register.tsx
β β βββ Auth.css
β βββ contexts/ # React Context providers
β β βββ AuthContext.tsx
β βββ hooks/ # Custom React hooks
β β βββ useDebounce.ts
β βββ landingPage/ # Landing page components
β β βββ Landing.tsx
β β βββ Landing.css
β β βββ components/
β β βββ searchBar/
β β β βββ SearchBar.tsx
β β β βββ SearchBar.css
β β βββ filters/
β β βββ Filters.tsx
β β βββ Filters.css
β βββ navigation/ # Navigation components
β β βββ components/
β β βββ Navbar.tsx
β β βββ Navbar.css
β βββ dashboard/ # Dashboard page
β β βββ Dashboard.tsx
β β βββ Dashboard.css
β βββ services/ # API service layer
β β βββ api.ts
β βββ types/ # TypeScript type definitions
β β βββ index.ts
β βββ config/ # Configuration files
β β βββ api.ts
β βββ App.tsx
β βββ App.css
β βββ index.tsx
β βββ index.css
βββ .env.example
βββ package.json
βββ tsconfig.json
βββ server.ts
βββ README.md
- Bun (v1.0 or higher)
- Backend API server running (for authentication and stock data)
bun install-
Configure environment variables
cp .env.example .env.local
-
Update
.env.localwith your backend API URL:VITE_API_BASE_URL=http://localhost:3001/api
Start the development server:
bun run devThe application will be available at http://localhost:3000
Create a production build:
bun run buildThe built files will be in the dist directory.
Your backend should implement the following endpoints matching these specifications:
POST /api/auth/register- User registration- Body:
{ name: string, email: string, password: string } - Returns:
{ success: boolean, token?: string, user?: User, message?: string }
- Body:
POST /api/auth/login- User login- Body:
{ email: string, password: string } - Returns:
{ success: boolean, token?: string, user?: User, message?: string }
- Body:
POST /api/auth/logout- User logoutGET /api/auth/verify- Verify JWT token- Headers:
Authorization: Bearer {token} - Returns:
{ success: boolean, user?: User }
- Headers:
GET /api/stocks/autocomplete?query={query}- Get stock suggestions by company name and ticker- Query params:
query(string) - Returns:
{ suggestions: [{ symbol: string, name: string }] }
- Query params:
GET /api/stocks/search- Search stocks with comprehensive filtering, sorting, and pagination- Query params:
query(string, optional) - Search by symbol or company namepage(number, default: 1) - Page numberpage_size(number, default: 20) - Results per pagesort_by(string, default: 'symbol') - Sort field (symbol, name, previous_close, pe, forward_pe, dividend_yield, market_cap, payout_ratio)sort_order('asc' | 'desc', default: 'asc') - Sort directionmin_previous_close(number, optional) - Minimum previous close pricemax_previous_close(number, optional) - Maximum previous close pricemin_pe(number, optional) - Minimum P/E ratiomax_pe(number, optional) - Maximum P/E ratiomin_forward_pe(number, optional) - Minimum forward P/E ratiomax_forward_pe(number, optional) - Maximum forward P/E ratiomin_dividend_yield(number, optional) - Minimum dividend yield percentagemax_dividend_yield(number, optional) - Maximum dividend yield percentagemin_market_cap(number, optional) - Minimum market capitalizationmax_market_cap(number, optional) - Maximum market capitalizationmin_payout_ratio(number, optional) - Minimum payout ratio percentagemax_payout_ratio(number, optional) - Maximum payout ratio percentage
- Returns:
{ "stocks": [ { "symbol": "AAPL", "name": "Apple Inc.", "previous_close": 150.25, "pe": 28.5, "forward_pe": 25.3, "dividend_yield": 0.52, "market_cap": 2450000000000, "payout_ratio": 15.2 } ], "total": 500, "page": 1, "page_size": 20, "total_pages": 25 }
- Query params:
GET /api/stocks/{symbol}- Get specific stock details- Returns: Stock object with all fields
- Type in the search bar to see autocomplete suggestions (debounced after 300ms)
- Click a suggestion or press Enter to search
- Results display in a paginated table with all stock metrics
- Use the sidebar filters to narrow results:
- Set min/max ranges for price, P/E ratios, dividend yield, market cap, and payout ratio
- Choose sort field and order (ascending/descending)
- Select results per page (10, 20, 50, or 100)
- Filters apply automatically when changed
- Click "Reset Filters" to clear all filters and return to defaults
- Use the pagination controls at the bottom of the results table
- Click "Previous" or "Next" to navigate pages
- Current page and total pages are displayed
- Click "Sign Up" in the navbar to create an account
- Fill in name, email, and password
- Or click "Login" if you have an account
- Access protected Dashboard after login
- Click "Logout" to sign out
The search bar uses a custom useDebounce hook with a 300ms delay to prevent excessive API calls during typing.
All API responses and component props are fully typed using TypeScript interfaces defined in src/types/index.ts:
FilterOptions- All available filter parametersStockSearchResponse- Paginated search response structureStock- Individual stock data with all metricsStockSuggestion- Autocomplete suggestion formatAuthResponse- Authentication response structure
- React Context API (
AuthContext) for global authentication state - Local component state for search, filters, and pagination
- Protected routes using custom
ProtectedRouteandPublicRoutewrappers
Centralized API calls in src/services/api.ts with:
- Automatic JWT token management
- Type-safe request/response handling
- Proper error handling with fallbacks
- React 19 - UI framework
- TypeScript 5 - Type safety
- React Router DOM 7 - Client-side routing
- Bun - Fast JavaScript runtime and package manager
- NeonDB Serverless - PostgreSQL database (backend)
- bcryptjs - Password hashing
- jsonwebtoken - JWT authentication