How saxenabhishek/pulse works
Project Type and Purpose
• This is a full-stack “Newspaper” application named pulse.
• Frontend: a React + TypeScript SPA built with Vite (in the client folder).
• Backend: a Go HTTP server exposing REST endpoints for news and IP lookup (in the server folder).
File Structure Analysis
• client/
• src/service/news.tsx → defines functions like fetchLatestNews() that call /api/news.
• src/service/mocks.tsx → mock implementations of the same API calls.
• src/components → UI components (Article, ContentSection, Header, Footer, etc.).
• Vite config, tsconfig, .env for dev/prod.
• server/
• controller.go → HTTP handlers (e.g., GetNewsHandler, GetIPHandler).
• internal/news/news.go → business logic function GetLatestNews().
• internal/ip/ip.go → function GetClientIP().
• internal/common/common.go → shared utilities.
• main.go → routes setup:
– http.HandleFunc("/api/news", GetNewsHandler)
– http.HandleFunc("/api/ip", GetIPHandler)
Key Architectural Patterns
• Controller-Service separation:
– Handlers in controller.go delegate to internal/... packages.
• Clear API boundary: frontend uses a thin service layer (fetchLatestNews(), fetchClientIP()).
• Environment-based configs via Vite .env files and Go’s module system.
Main System Components
a. Frontend (Browser)
• Components: Header, Content, Article, Footer
• Service Layer:
• fetchLatestNews() → calls GET /api/news
• fetchClientIP() → calls GET /api/ip
b. API Gateway / Controller (Go HTTP Server)
• GetNewsHandler(w, r)
• GetIPHandler(w, r)
c. Business Logic Services
• news.GetLatestNews() → encapsulates logic to fetch or aggregate news
• ip.GetClientIP() → extracts client IP from request
• common utilities for error handling, logging, etc.
d. External Systems (if any)
• Third-party news APIs or databases (not explicitly in code, but implied)
Interactions & Data Flow
1. User interacts with UI → triggers a component (e.g., Content) to call fetchLatestNews().
2. fetchLatestNews() issues HTTP GET to /api/news.
3. Go server’s GetNewsHandler receives request → calls internal/news.GetLatestNews().
4. GetLatestNews() fetches data (mock, file system, or external API) → returns JSON.
5. Handler writes JSON response → frontend component receives and renders articles.
6. Similar flow for IP lookup via /api/ip → GetIPHandler → internal/ip.GetClientIP().