How cpj-n/stocksnip works
Project Type and Purpose
• Type: Full-stack web application built with Next.js 13 (App Router) and TypeScript.
• Purpose: Let users enter a stock ticker, fetch the latest stock data and news via Alpha Vantage, generate an AI summary using Together Compute, and display results in a responsive React UI.
File Structure
• Top-level config files:
– next.config.ts, tsconfig.json, tailwind.config.ts → Next.js, TypeScript, Tailwind setup.
– .example.env → holds API keys for Alpha Vantage and Together Compute.
• Public assets: public/img/stocksnip.png.
• Application code (src/app):
– layout.tsx, globals.css → site‐wide layout and styles.
– page.tsx → homepage UI.
– /pricing/page.tsx → pricing information.
• API routes (src/app/api):
– getStockData/route.ts → calls Alpha Vantage stock‐price endpoint.
– getStockNews/route.ts → calls Alpha Vantage news endpoint.
– getSummary/route.ts → calls Together Compute for AI summarization.
• UI components (src/components & ui folder) → Shadcn UI building blocks (button, card, chart, etc.).
• Utilities (src/lib/utils.ts) → shared helper functions (e.g., formatting, error handling).
README Insights
• Core integrations: Alpha Vantage for data/news; Together Compute for summaries.
• Styling: Tailwind CSS + Shadcn UI.
• Hosting/deployment on Vercel.
• Next.js features: next/font optimization, SSR/SSG, API routes.
a. Main Components
• Client (Browser)
• Next.js Frontend (React Server + Client Components)
• Next.js API Layer (Serverless route handlers)
• External Services:
– Alpha Vantage API
– Together Compute AI API
• Configuration & Hosting
– Environment Variables
– Vercel Platform
b. Relationships & Data Flows
1. User loads page → HTTP(S) GET to Next.js server → React renders page.
2. On ticker search: Frontend issues fetches to /api/getStockData and /api/getStockNews.
3. API routes forward requests to Alpha Vantage, return JSON to frontend.
4. Frontend stitches data, then POSTs consolidated news to /api/getSummary.
5. getSummary route calls Together Compute with news text, returns AI summary.
6. Frontend displays summary in UI.
c. Architectural Patterns & Principles
• Monolithic Next.js app with clearly separated API routes.
• Serverless functions for backend logic (zero-server maintenance).
• Component-based UI with atomic principles (shadcn components).
• CSS utility-first design (Tailwind).
• Environment-driven configuration (API keys via env vars).
d. Key Technologies & Frameworks
• Next.js 13 App Router (server + client components)
• React & TypeScript
• Tailwind CSS & Shadcn UI
• Node.js serverless API routes
• Alpha Vantage REST API
• Together Compute AI API
• Vercel deployment
Detail
• Every major route handler and its downstream service call.
• Environment variables feeding into API routes.
• Build/config pipeline (next.config.ts, tailwind.config.ts) as a side note.