How atikp/apst_frontend works
Project Type and Purpose
• This is a frontend-only single-page application (SPA) built with React and Vite.
• Its purpose is to simulate a stock trading environment: it provides UI components for authentication, portfolio management, real‐time charts, news, buy/sell operations, and user rewards.
High‐Level Architecture Components
a. Client (Browser)
• Hosts the React/Vite SPA (served via Netlify).
• Renders UI using TailwindCSS for styling, ApexCharts for charts, Framer Motion for animations, React-Toastify for notifications.
b. Firebase Services (Client SDK)
• Firebase Authentication: email/password login.
• Firestore Database: stores user portfolios, transactions, accolades.
c. Express Backend (Deployed on Render)
• Acts as a secure proxy to external stock/data APIs.
• Implements buy/sell logic, portfolio updates (writes to Firestore).
• Protects secret API keys (Alpha Vantage, FMP, Finnhub).
d. External Data Providers
• Alpha Vantage: real-time and historical stock data.
• Financial Modeling Prep (FMP): company profiles.
• Finnhub: news feed and quote WebSocket stream.
Relationships and Data Flows
• User interacts with the React SPA in browser.
• SPA ↔ Firebase Auth SDK: handles signup/login, obtains user token.
• SPA ↔ Firestore SDK: reads/writes user portfolio, holdings, transactions, accolades.
• SPA ↔ Express API (via src/utils/api.js): for buy/sell operations and proxying data requests.
• The SPA passes the user’s Firebase token in Authorization headers.
• Express API → External Providers: fetches market data, news, profiles.
• Express API → Firestore (using Firebase Admin SDK): updates user portfolio on buy/sell.
Architectural Patterns and Principles
• Clear separation of concerns:
• UI layer (React components under src/components)
• State & Context (src/context/UserContext.jsx)
• Data access layer (src/utils/api.js, firebase.js)
• Reusable custom hooks (src/hooks)
• Proxy pattern: Express API secures secrets and centralizes business logic.
• Componentization: small, focused React components and directories (ChartComponents, SmallerComponents).
• Single source of truth: UserContext handles auth state and shares across app.