This application is a comprehensive countries explorer built with React for the frontend and a custom backend for user management. It integrates with the REST Countries API to provide detailed information about countries worldwide, allowing users to search, filter, and view specific details about any country.
- Framework: React (with functional components)
- Language: JavaScript
- CSS Framework: Tailwind CSS
- Testing: Jest and React Testing Library
- Hosting: Vercel
- Framework: Node.js with Express
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens)
- Hosting: Railway
- Country Information Display: View comprehensive details about countries including name, population, region, languages, flag, and capital.
- Search Functionality: Search for countries by name.
- Filtering Options: Filter countries by region and language.
- Detailed View: Click on any country to view expanded information.
- User Authentication: Register and login to access personalized features.
- Favorites System: Authenticated users can save countries to their favorites list.
- Responsive Design: Optimized viewing experience across all device types.
The application integrates with the REST Countries API using the following endpoints:
GET /all- Retrieves a list of all countriesGET /name/{name}- Searches for countries by nameGET /region/{region}- Filters countries by regionGET /alpha/{code}- Gets detailed information about a specific country using its code
- Node.js (v16 or higher)
- npm or yarn
- Clone the repository:
git clone https://github.com/SE1020-IT2070-OOP-DSA-25/af-2-dasundu.git
- Navigate to the frontend directory:
cd frontend - Install dependencies:
npm install
- Create a
.envfile and add the following environment variables:REACT_APP_API_URL=http://localhost:5000/api - Start the development server:
The application will be available at
npm start
http://localhost:3000
- Navigate to the backend directory:
cd backend - Install dependencies:
npm install
- Create a
.envfile with the following variables:PORT=5000 MONGODB_URI=[your-mongodb-connection-string] JWT_SECRET=[your-jwt-secret] - Start the server:
The server will run on
npm start
http://localhost:5000
The project includes comprehensive tests for the frontend components and functions.
To run the tests:
cd frontend
npm testFor test coverage report:
npm test -- --coverage- User registers with email and password
- Backend validates the data and creates a new user in the database
- User logs in with credentials
- Backend validates credentials and issues a JWT token
- Frontend stores the token in localStorage for subsequent requests
- Protected routes verify the token before granting access
The application implements real-time search functionality, allowing users to find countries by name instantly. Additionally, users can filter countries by region and language, with the filters being combinable to narrow down results.
Authenticated users can add countries to their favorites list. This information is stored in the backend database, allowing users to access their favorites across devices and sessions.
Using Tailwind CSS, the application provides a seamless experience across mobile, tablet, and desktop devices. The layout adapts intelligently based on screen size.
Problem: The REST Countries API occasionally enforced rate limits during development.
Solution: Implemented caching mechanisms to store API responses and reduce the number of requests. Also added error handling to gracefully handle rate limit errors.
Problem: Managing global state across components became complex as the application grew.
Solution: Utilized React Context API for global state management, particularly for authentication and favorites functionality, simplifying data flow throughout the application.
Problem: Initial loading of all countries caused performance issues.
Solution: Implemented lazy loading and pagination to load countries in smaller batches as needed, significantly improving initial load times.
- Add dark mode toggle
- Implement more detailed country statistics and visualizations
- Add language translation features
- Enhance the favorites system with categories and notes
- Implement offline functionality using service workers