How roarnald/bread-tracker works
Project Type and Purpose
• This is a frontend-only Single Page Application (SPA) built with React, Parcel, TypeScript, Tailwind CSS and React Router.
• It consumes the CoinGecko public API to display real-time cryptocurrency prices.
• It persists a user’s custom token list in localStorage or encodes it in the URL.
High-Level Architectural Components
a. Client Application (Browser)
• React SPA served by Parcel development/build tools.
• Routes managed by React Router.
• UI styled with Tailwind CSS.
b. State Management
• A HomeContext/HomeProvider (React Context + Hooks) that holds the user’s token list and current prices.
c. API Layer
• src/api: Coins.ts and Simple.ts wrap calls to CoinGecko REST endpoints.
• src/utils/request.ts handles HTTP requests (fetch wrappers, error handling).
d. Persistence Layer
• LocalStorage or URL query params (via Utility HOC ProviderHOC.tsx) to persist/rehydrate the user’s token list.
e. External Service
• CoinGecko public API.
Relationships & Data Flow
1. User opens the SPA → index.html loads bundle → React renders the root <App> (src/components/index.tsx).
2. <HomeProvider> initializes state by reading localStorage or URL params.
3. Home UI components (HomeSearchBar, HomeTokenList, PinTitleButton, etc.) dispatch actions or call context methods.
4. Context calls src/api methods (Coins.list, Simple.price) via src/utils/request, awaiting JSON from CoinGecko.
5. On success, context updates its internal state and re-renders UI.
6. On list changes, context writes back to localStorage or updates the URL.
Key Architectural Patterns & Principles
• Component-based UI (React) separated into presentational (HomeTokenList, Footer) vs container/provider (HomeContext).
• Single source of truth in React Context.
• External API isolation in dedicated modules (src/api).
• Utility layers for HTTP requests and lazy loading.
• CSS-in-JS approach using Tailwind (via postcss, tailwind.config.js).
• Browser / Client
• React SPA (subdivide into “UI Components,” “React Router,” “Context Providers,” “Utils”)
• Persistence (LocalStorage / URL)
• External Service (CoinGecko API)
• User → UI Components
• UI Components → Context Provider → API Layer → External Service
• API responses back up the chain → UI
• Context → Persistence layer (read/write)
• UI: React, TypeScript, Tailwind CSS
• Routing: React Router
• Bundler: Parcel
• API Layer: src/api, fetch utils
• Persistence: localStorage / URL Params
• External Service: CoinGecko REST
• Blue rectangles for in-browser components (UI, Context, Utils)