How furkancanzirek/bist-etf-tracking works
Main Components
• Frontend Client: Represented by the Next.js “app” folder containing layout.js, page.js, and dynamic fund pages. This includes UI components (in the “components” folder, with Shadcn UI elements) and hooks for better responsiveness.
• API Endpoints: Inside “app/api”, there are dedicated endpoints (for “etf” and “scrape”) which expose server actions. These endpoints are responsible for processing client requests, interacting with backend services, and triggering scraping functions.
• Business Logic / Service Layer: Distributed in “actions” (e.g., fetchFundChange.js), “services” (for ETF change retrieval), and utility functions under “lib”. These modules encapsulate the core data processing and scraping logic.
• Data Layer: The presence of schema.sql, db.json, and the README’s reference to Cloudflare D1 point to a dedicated database layer (Cloudflare D1). This layer manages persistent storage for funds, stocks, and related scraped data.
• External Services Integration: Cloudflare Workers are evident from “wrangler.toml.example” and “src/index.ts”. This service component likely handles additional tasks such as initiating scraping or offloading some workload to the edge.
• Deployment/Configuration: Files such as next.config.mjs, postcss.config.js, tailwind.config.js, and package.json indicate build and deployment configurations, with Cloudflare Pages handling the hosting environment.
Relationships and Interactions
• User requests go to the Frontend Client (built using Next.js) which interacts with the API endpoints to fetch updated fund/ETF changes.
• API routes (in “app/api/”) call on business logic modules in “actions”, “services”, and “lib” to retrieve, process, or scrape data.
• Data persistence is managed through Cloudflare D1; the API endpoints and server actions write to or query the database (using schema defined in schema.sql).
• Cloudflare Workers (with entry point in “src/index.ts”) may be used to perform asynchronous or periodic scraping tasks using functions from “lib/scrape*.js” and leveraging Cheerio for HTML parsing.
• UI components (in “components” and “components/ui”) are used to render dynamic data on fund pages and incorporate reusable UI patterns.
Architectural Patterns and Key Technologies
• Separation of Concerns: The project clearly segments the presentation layer (Next.js pages and UI components), business logic (actions, services, lib), and data layer (Cloudflare D1).
• Serverless and Edge Functions: Integration with Cloudflare Workers showcases the use of edge computing to handle intensive tasks such as data scraping.
• API-Driven Communication: The Next.js Server Actions and API endpoints form a RESTful (or action-based) interaction layer between the client and backend logic.
• Modern Frontend Stack: Utilization of Next.js 14, Shadcn UI, and Tailwind CSS (configured via tailwind.config.js) helps maintain a responsive design.
Detailed Elements
• Clear labels for each component, ensuring that both high-level blocks (Frontend, API/Business Logic, Cloudflare services) and sub-components (e.g., specific API endpoints or utility modules) are visible.
• Request flow: From the client (Next.js UI) → API Endpoints → Business Logic → Data Storage.
• Asynchronous updates: From Cloudflare Workers → Database (Cloudflare D1) and possibly back to API endpoints.