src/. Each directory has a single, well-defined responsibility, making it straightforward to locate code and add new features.
Directory tree
Directory responsibilities
| Directory | Responsibility |
|---|---|
src/components/ | Reusable UI components used across multiple pages |
src/pages/ | Route-level page components rendered by React Router |
src/services/ | All external API calls and the localStorage cache layer |
src/hooks/ | Custom React hooks that encapsulate stateful logic |
src/context/ | React context providers for global app state |
src/utils/ | Pure utility functions for formatting and calculations |
src/components/
Contains all reusable UI components. These are not tied to any single route and can be composed across different pages.| File | Description |
|---|---|
cryptoCard.jsx | Card component displaying a single cryptocurrency’s name, price, and 24h change |
converterCrypto.jsx | Interactive form that converts an amount between two selected cryptocurrencies |
cryptoGrafics.jsx | Recharts-powered price history chart for a selected asset |
cryptoNews.jsx | Renders a single news article card with headline and source |
navbar.jsx | Top navigation bar with links to all routes and a dark/light mode toggle |
text.jsx | Shared typography component for consistent heading and body text styles |
src/pages/
Each file maps directly to a route defined inApp.jsx. Pages are responsible for fetching data (via services) and composing components into a full view.
| File | Route | Description |
|---|---|---|
home.jsx | / | Lists the top 20 cryptocurrencies by market cap |
converter.jsx | /converter | Full-page crypto-to-crypto converter |
grafics.jsx | /grafics | Price history charts with selectable time ranges |
news.jsx | /news | Latest cryptocurrency market news |
favorites.jsx | /favs | User’s saved favorite cryptocurrencies |
src/services/
All external API communication lives here. Each file is responsible for a single data domain. Thecache.js module wraps every API function with a localStorage cache that expires after 5 minutes, reducing unnecessary network requests.
| File | Description |
|---|---|
cryptoApi.js | Fetches the top 20 coins by market cap from the CoinGecko /coins/markets endpoint |
priceApi.js | Retrieves current USD prices for multiple coins in a single request |
historyApi.js | Fetches historical OHLC or price data for a given coin and time range |
newsApi.js | Retrieves the latest crypto news articles from a public news API |
cache.js | Wraps each API function with a localStorage cache; re-fetches only when data is older than 5 minutes |
src/hooks/
Custom React hooks that separate stateful logic from component rendering.useFavorites.jsx — manages a list of favorite coin IDs persisted to localStorage. Exposes addFavorite, removeFavorite, and isFavorite helpers so any component can read or update the favorites list without prop drilling.
src/context/
React context providers that make shared state available throughout the component tree without passing props manually.useContext.jsx exports two providers:
FavoritesProvider— wraps theuseFavoriteshook and provides favorites state globally viaFavoritesContext.ColorModeProvider— manages dark/light mode state, persists the preference tolocalStorage, and toggles thedarkclass on<html>for Tailwind’s dark mode utilities.
App.jsx, wrapping all routes.
src/utils/
Pure utility functions with no side effects or React dependencies.formatNumbers.js — exports two Intl.NumberFormat instances:
formatter— formats a number as a USD currency string with two decimal places (e.g.$42,150.00).formatterCrypto— formats a raw crypto quantity with two decimal places, without a currency symbol.
Entry points
| File | Description |
|---|---|
src/main.jsx | Renders the React app into #root, wrapping <App> in <BrowserRouter> and <StrictMode> |
src/App.jsx | Defines all routes via <Routes>, wraps the tree in FavoritesProvider and ColorModeProvider |
vite.config.js | Configures Vite with the React SWC plugin and Tailwind CSS v4 Vite plugin |