How iaavas/nepalbynumbers works
Project Type and Purpose
• Nepal By Numbers is a full-stack, server-rendered web application built with Next.js/React.
• Purpose: Interactive map visualizations of Nepal’s socio-economic data (GDP, HDI, etc.), real-time CSV/Excel imports, theming, and project saving via Firebase.
File Structure Analysis
• Top-level:
• app/ – Next.js “app router” pages, server-side API routes, global CSS, layout, and loading/error handlers
• components/ – Two sets: reusable UI primitives (components/ui) and page-specific widgets (app/components)
• context/, hooks/, utils/, constants/ – State management (React Context), custom hooks, utility functions, and constants
• libs/ – Third-party integrations: Firebase setup (libs/firebase) and OpenPixel tracker (lib/openpixel)
• assets/ – Static GeoJSON data for provinces, districts, world map
• public/ – Static images and marketing assets
• next.config.js, tailwind.config.ts, tsconfig.json – Build and style configuration
README Insights
• Architecture summary:
• Frontend: Next.js + React + D3.js + Leaflet
• Server/API: Next.js serverless routes under app/api (log-fingerprint, track)
• Database: Firebase (Auth + Firestore/Realtime on projects)
• Styling: Tailwind CSS
a. Main Components
1. Client Browser (User’s UI)
• Next.js pages & React components (app/pages, components/ui, map widgets)
• Context Providers & Hooks (AuthContext, Data hooks)
• D3.js & Leaflet for map rendering
2. Next.js Server (Server-Side Rendering & API Layer)
• SSR/ISR for initial page loads
• Serverless API routes (app/api/log-fingerprint, track)
3. Firebase
• Authentication (login/save projects)
• Firestore/Realtime DB (persist user projects and settings)
4. Static Data Storage
• GeoJSON files in assets/data
5. External Service: OpenPixel
• Usage via lib/openpixel/tracker for analytics/tracking
b. Relationships & Data Flows
• Client → Next.js API → Firebase (CRUD on projects)
• Client directly reads static assets under /assets (districts, provinces JSON)
• Client invokes lib/openpixel/tracker → External OpenPixel endpoint
• SSR fetches initial data (if any) via hooks on server
• React Contexts orchestrate state between UI components
c. Architectural Patterns & Principles
• Separation of Concerns: UI layer, state layer (Contexts/hooks), data layer (API + Firebase), static assets
• File-system routing (Next.js app router)
• Context API for global state
• Serverless functions for “backend” endpoints
• Component-based UI with atomic design (primitives in components/ui, composites in app/components)
d. Key Technologies & Frameworks
• Next.js / React / TypeScript
• Tailwind CSS
• D3.js & Leaflet
• Firebase Auth & Firestore
• OpenPixel analytics
• GitHub Actions / Vercel (implied hosting/CI)