A Next.js application that displays countries data, allows users to filter by text search, and view detailed country pages including bordering countries. It features responsive UI, dynamic routing, and efficient data fetching for smooth navigation across country information.Built in February 2021. Inspired by Thu Nghiem's world ranks tutorial and project. The project was created as a learning exercise to practice Next.js fundamentals, API integration, routing patterns, and building scalable frontend architecture with clean code structure.
- List of all countries with flags, population, area, and Gini index
- Client-side filtering by country name, region, or subregion
- Sortable table columns (name, population, area, Gini)
- Dynamic country detail page (
/country/[id]) - Border countries preview on country details
- Light/dark theme toggle persisted in
localStorage - Static generation with Next.js
getStaticProps/getStaticPaths
graph TB
User[Browser User]
NextApp[Next.js App]
HomePage[Index Page]
CountryPage[Country Details Page]
Components[Reusable Components]
RestCountries[REST Countries API]
User --> NextApp
NextApp --> HomePage
NextApp --> CountryPage
HomePage --> Components
CountryPage --> Components
HomePage --> RestCountries
CountryPage --> RestCountries
sequenceDiagram
participant U as User
participant N as Next.js
participant API as restcountries.eu
Note over U,API: Home Page Build
N->>API: GET /rest/v2/all (build time)
API-->>N: Countries array
N-->>U: Pre-rendered home page
Note over U,API: Country Detail Build
N->>API: GET /rest/v2/all (build time paths)
API-->>N: alpha3Code list
N->>API: GET /rest/v2/alpha/{id} (per country)
API-->>N: Country details
N-->>U: Static detail page
Note over U,N: Runtime Interaction
U->>N: Type in search input
N-->>U: Filtered table rows
U->>N: Click sortable column
N-->>U: Reordered rows
- Node.js 14+ (or any version compatible with Next.js 10)
- npm
- Clone the repository:
git clone https://github.com/orassayag/countries-ranks-github.git
cd countries-ranks-github- Install dependencies:
npm install- Run development server:
npm run dev- Open:
http://localhost:3000
npm run devStarts local development server.
npm run buildBuilds optimized production output.
npm run startRuns production server from built assets.
countries-ranks-github/
├── src/
│ ├── components/
│ │ ├── CountriesTable/
│ │ ├── Layout/
│ │ └── SearchInput/
│ ├── pages/
│ │ ├── country/
│ │ │ ├── [id].js
│ │ │ └── Country.module.css
│ │ ├── _app.js
│ │ └── index.js
│ └── styles/
│ ├── globals.css
│ └── Home.module.css
├── .github/
├── package.json
├── CONTRIBUTING.md
├── INSTRUCTIONS.md
└── README.md
The app currently fetches countries data from:
https://restcountries.eu/rest/v2/allhttps://restcountries.eu/rest/v2/alpha/{id}
Note: if this API is unavailable, static generation may fail during build.
- Advanced Filtering: Filter countries by name, region, or subregion in real-time.
- Dynamic Sorting: Multi-column sorting for population, area, and Gini index.
- Detail Exploration: Deep-dive into specific country data with border country navigation.
- Theme Customization: Persistent dark/light mode for user preference.
- Next.js Ecosystem: Utilizing the power of Next.js for hybrid rendering.
- Responsive UI: Fully functional across mobile, tablet, and desktop.
- Clean Code: Adherence to modern JavaScript and React patterns.
- Hot Reloading: Instant feedback during development with Next.js.
- Standardized Tooling: ESLint and Prettier for code consistency.
- Simple Deployment: Optimized for Vercel or any static hosting provider.
- Browse the list of countries on the home page.
- Use the search bar to find specific countries.
- Click on table headers to sort the data.
- Click on a country row to view its details and bordering countries.
- Component-Driven Development: UI is built using small, isolated components in
src/components. - Static Site Generation (SSG): Leveraging Next.js
getStaticPropsfor optimal performance. - Client-Side Interactivity: Filtering and sorting are handled efficiently on the client side.
- Modular Styling: CSS Modules are used to ensure style encapsulation.
- Performance: Static generation ensures fast TTI (Time to Interactive).
- Accessibility: Semantic HTML and clear navigation patterns.
- Maintainability: Clear separation between components and page logic.
- State Management: Using React state for localized UI interactions (filtering/sorting).
- Container/Presenter: Pages act as containers fetching data, while components handle presentation.
- Higher-Order Components/Hooks: React patterns for shared logic.
- SSG with Dynamic Routes: Using
getStaticPathsfor generating country-specific pages.
The application connects to the REST Countries API. Configuration is primarily handled through the API endpoints defined in the page files:
https://restcountries.eu/rest/v2/allhttps://restcountries.eu/rest/v2/alpha/{id}
src/
├── components/ # Reusable UI components
├── pages/ # Next.js routes and data fetching
└── styles/ # Global and component-specific styles
For support, please open an issue on the GitHub repository or contact the author directly at orassayag@gmail.com.
- Delete
node_modulesandpackage-lock.json, then runnpm installagain.
- Verify internet access.
- Confirm REST Countries endpoint availability.
- Retry
npm run build.
- Ensure browser allows
localStorage. - Check private/incognito restrictions.
Contributions are welcome. See CONTRIBUTING.md for contribution guidelines and INSTRUCTIONS.md for setup and implementation notes.
- Thu Nghiem tutorial: https://www.youtube.com/watch?v=v8o9iJU5hEA
- Original project inspiration: https://github.com/nghiemthu/world-ranks
- Or Assayag - Initial work - orassayag
- Or Assayag orassayag@gmail.com
- GitHub: https://github.com/orassayag
- StackOverflow: https://stackoverflow.com/users/4442606/or-assayag?tab=profile
- LinkedIn: https://linkedin.com/in/orassayag
This application has an MIT license - see the LICENSE file for details.
- Built for educational and research purposes
- Respects robots.txt and implements rate limiting
- Uses user-agent rotation to avoid detection
- Implements polite crawling practices