A React-based web application that allows users to search for GitHub profiles using GraphQL and Apollo Client. The application displays user details such as their name, bio, avatar, followers, and repositories. It handles various states like loading, error, and no results, providing a responsive and user-friendly interface.
- Overview
- Key Technologies
- Installation
- Usage
- Environment Variables
- Design Decisions
- Trade-offs
- Testing Strategy
- Future Improvements
The GitHub Profile Viewer is designed to fetch and display GitHub user profiles based on the username input by the user. It uses Material-UI for styling and layout, Apollo Client for managing GraphQL queries and state, and React for building the UI components.
- React: A JavaScript library for building user interfaces.
- Apollo Client: A state management library that enables you to manage both local and remote data with GraphQL.
- GraphQL: A query language for your API, which allows fetching only the necessary data.
- Material-UI (MUI): A popular React UI framework for designing responsive and consistent interfaces.
- Jest and React Testing Library: Testing frameworks used for unit and integration testing.
-
Clone the repository:
git clone https://github.com/sirius829/github-profile-viewer.git
-
Navigate to the project directory:
cd github-profile-viewer -
Install the dependencies:
npm install
-
Start the development server:
npm start
-
Open your browser and navigate to
http://localhost:5173to use the application.
To run the application, you need a GitHub Personal Access Token with the appropriate permissions to access GitHub's GraphQL API. Follow these steps to set it up:
-
Create a GitHub Personal Access Token:
- Go to GitHub Settings.
- Click on "Generate new token".
- Select the scopes that you need, usually, you need
read:useranduser:emailscopes. - Generate the token and copy it.
-
Set Up the
.envFile:- Create a file named
.envin the root directory of your project. - Add the following line to the
.envfile, replacingYOUR_GITHUB_TOKENwith your actual GitHub token:
REACT_APP_GITHUB_TOKEN=YOUR_GITHUB_TOKEN
- Create a file named
-
Restart the Development Server:
- After setting up the
.envfile, restart the development server to apply the changes.
- After setting up the
- Modular Components: The app is broken down into reusable components such as
GitHubUserProfile,UserListItem, andStatusMessagefor clarity and maintainability. - Separation of Concerns: Each component has a distinct responsibility, making the code easier to manage and extend.
- Data Management: Apollo Client is used for managing data fetching and state management, providing efficient data handling and caching.
- GraphQL: Allows querying specific fields, reducing over-fetching of data compared to REST APIs.
- Consistency: Using Material-UI ensures a consistent and professional look across the application.
- Responsive Design: Built-in responsive design features help adapt the UI to different screen sizes.
- User Feedback: Error messages and loading states provide feedback to users, improving the user experience.
- StatusMessage Component: Centralizes the display of various application states (e.g., welcome message, errors, no results).
- Performance vs. Simplicity: The use of Apollo Client and Material-UI increases ease of development but may impact the bundle size and performance.
- Flexibility vs. Consistency: Material-UI offers consistent design but may limit customization options without additional configuration.
- Testing in Mocked Environment: Using mocks for testing provides isolation but may not cover all real-world scenarios.
- Unit Testing: Tests individual components using Jest and React Testing Library.
- Integration Testing: Ensures that the components interact correctly, using Apollo’s MockedProvider to simulate API responses.
- Error Scenarios: Tests cover various states including loading, error handling, and no results scenarios.
- Enhanced Error Handling: Differentiate error messages based on error types for better user experience.
- Performance Optimization: Use code splitting and lazy loading to improve application load times.
- UI Customization: Introduce more custom styling to create a unique look beyond Material-UI’s defaults.
- End-to-End Testing: Implement e2e tests to simulate real user interactions and ensure application reliability.