How manuelnavarro7/country-app works
Project Type and Purpose
• This is a full-stack web application (“Country Info App”) whose goal is to display country data (population trends, border countries, flags) to end users.
• Frontend: Next.js (React) single-page app with server- and client-components (app directory) and Tailwind CSS for styling.
• Backend: Express.js REST API server responsible for fetching data from two public external services (Nager.Date API, CountriesNow API) and exposing it to the frontend.
File-Structure Analysis
Top-level:
• backend/
– app.js (Express server setup, CORS configuration)
– src/controllers (countryController.js handles API logic)
– src/routes (countryRoutes.js defines endpoints)
– .env for PORT
– package.json/npm scripts
• frontend/
– src/app/… (Next.js app folder using new app router)
· country-list/[code]/page.js, layout.js (dynamic route for country detail)
· page.js (home listing)
· globals.css, Tailwind config, postcss.config.mjs
– next.config.mjs, jsconfig.json, .eslintrc.json
– package.json/npm scripts
README Insights
• Backend exposes two GET endpoints: /api/countries/available and /api/countries/info/:countryCode
• Frontend uses NEXT_PUBLIC_BACKEND_URL to call backend on port 5001 from port 3000
• Chart.js is used for rendering historical population data
• No internal database; all country data comes from external REST APIs
• CORS is enabled in Express for localhost:3000
a. Main Components
• Browser/Client (User’s web browser)
• Next.js Frontend (app server + client runtime)
• Express.js Backend (REST API server)
• External APIs – Nager.Date API, CountriesNow API
b. Relationships/Interactions
1. User requests frontend (port 3000) → Next.js server
2. Frontend calls Express backend via REST (NEXT_PUBLIC_BACKEND_URL/api/…)
3. Express controllers route request → fetch data from external APIs
4. External APIs return JSON → Express aggregates and returns to frontend
5. Frontend renders data (country list, detail page, Chart.js chart)
c. Architectural Patterns
• Separation of concerns: distinct frontend and backend tiers
• MVC-style on backend (routes → controllers)
• Next.js app router with server vs. client components
• Environment-based configuration (PORT, NEXT_PUBLIC_BACKEND_URL)
• CORS for cross-origin communication
d. Key Technologies/Libraries
• Frontend: Next.js 13 (app router), React, Tailwind CSS, Chart.js
• Backend: Node.js, Express.js, cors, dotenv
• External dependencies: Nager.Date API, CountriesNow API