A modern full-stack React application that delivers random Chuck Norris facts and provides search functionality by text or category. Built with a GraphQL API backend and Apollo Client for seamless state management and data fetching.
Experience Chuck Norris facts like never before: https://chuck-norris-facts-kwk.vercel.app/
- π² Random Facts: Get entertaining Chuck Norris facts with a single click
- π Smart Search: Search facts by text content or browse by categories
- π Persistent Dark Mode: Toggle between light and dark themes with localStorage persistence
- π± Fully Responsive: Optimized for all device sizes and screen resolutions
- β‘ GraphQL Integration: Efficient data fetching with Apollo Client
- π¨ Modern UI: Clean, intuitive interface built with Tailwind CSS
- π§ TypeScript Support: Type-safe development with full TypeScript integration
This project follows a modern full-stack architecture:
- React 18 with TypeScript for type safety
- Apollo Client for GraphQL state management
- Tailwind CSS for responsive styling
- Lucide React for beautiful icons
- Node.js with Express framework
- GraphQL API with express-graphql
- TypeScript for server-side type safety
- Axios for external API integration
- Helmet and CORS for security
| Package | Version | Purpose |
|---|---|---|
| React | ^18.3.1 | UI Library |
| Apollo Client | ^3.10.5 | GraphQL Client |
| TypeScript | ^4.9.5 | Type Safety |
| Tailwind CSS | ^3.4.4 | Styling Framework |
| Lucide React | ^0.539.0 | Icon Library |
| Package | Version | Purpose |
|---|---|---|
| Express | ^4.19.2 | Web Framework |
| GraphQL | ^16.11.0 | Query Language |
| Apollo Server | ^4.0.0 | GraphQL Server |
| Axios | ^1.7.2 | HTTP Client |
| TypeScript | ^5.4.5 | Type Safety |
- Node.js (v16 or higher)
- npm or yarn package manager
# Clone the repository
git clone https://github.com/your-username/chuck-norris-facts.git
cd chuck-norris-facts# Navigate to server directory
cd server
# Install dependencies
npm install
# Create environment file
cp .env.example .env
# Start development server
npm startThe GraphQL server will be available at http://localhost:4000/graphql
# Navigate to client directory (in a new terminal)
cd client
# Install dependencies
npm install
# Start React development server
npm startThe React app will be available at http://localhost:3000
| Command | Description |
|---|---|
npm start |
Runs the React app in development mode |
npm run build |
Builds the app for production |
npm test |
Launches the test runner |
npm run cypress:open |
Opens Cypress for e2e testing |
npm run cypress:run |
Runs Cypress tests in headless mode |
| Command | Description |
|---|---|
npm start |
Starts the GraphQL server with hot reload |
npm test |
Runs server-side tests |
chuck-norris-facts/
βββ client/ # Frontend React application
β βββ public/
β β βββ index.html
β β βββ screenshot.png
β βββ src/
β β βββ components/
β β β βββ DarkModeButton/
β β β βββ DarkModeButton.tsx
β β β βββ useDarkModeButton.tsx
β β β βββ Footer/
β β β βββ Footer.tsx
β β β βββ useFooter.ts
β β β βββ Header/
β β β βββ Header.tsx
β β β βββ useHeader.ts
β β β βββ Modal/
β β β βββ Modal.tsx
β β β βββ useModal.ts
β β β βββ SearchByCategorySection/
β β β βββ SearchByCategorySection.tsx
β β β βββ useSearchByCategorySection.ts
β β βββ assets/
β β β βββ images/
β β βββ pages/
β β β βββ Categories/
β β β βββ Categories.tsx
β β β βββ useCategories.ts
β β β βββ FactByFreeText/
β β β βββ FactByFreeText.tsx
β β β βββ useFactByFreeText.ts
β β β βββ RandomFact/
β β β βββ RandomFact.tsx
β β β βββ useRandomFact.ts
β β βββ queries/
β β β βββ getChuckNorrisByCategories.ts
β β β βββ getChuckNorrisByText.ts
β β β βββ getChuckNorrisCategories.ts
β β β βββ getChuckNorrisFact.ts
β β βββ types/
β β β βββ types.ts
β β βββ utils/
β β β βββ apolloClient.ts
β β β βββ useModal.ts
β β βββ App.test.tsx
β β βββ App.tsx
β β βββ index.css
β β βββ index.tsx
β β βββ react-app-env.d.ts
β β βββ reportWebVitals.ts
β β βββ setupTests.ts
β βββ package.json
β βββ Dockerfile
β βββ tailwind.config.js
βββ server/
β βββ src/
β β βββ graphql/
β β β βββ resolvers/
β β β βββ index.ts
β β β βββ schema/
β β β βββ index.ts
β β βββ middlewares/
β β β βββ errorHandler.ts
β β βββ utils/
β β β βββ apiClient.ts
β β β βββ logger.ts
β β β βββ types.ts
β β βββ index.ts
β βββ package.json
β βββ Dockerfile
β βββ jest.config.ts
β βββ .env.example
βββ docker-compose.yml
βββ README.md
Create a .env file in the server directory:
PORT=4000
CHUCK_NORRIS_API_URL=https://api.chucknorris.io
NODE_ENV=developmenttype Fact {
id: ID!
value: String!
url: String!
categories: [String!]!
created_at: String!
updated_at: String!
}
type Query {
randomFact: Fact!
searchFacts(query: String!): [Fact!]!
factsByCategory(category: String!): [Fact!]!
categories: [String!]!
}cd client
# Run unit tests
npm test
# Run e2e tests
npm run cypress:opencd server
# Run server tests
npm testThe frontend is automatically deployed to Vercel on every push to main branch.
Configure your preferred hosting platform with the following settings:
- Build Command:
npm run build - Start Command:
npm start - Node Version: 18+
- Helmet.js: Security headers protection
- CORS: Cross-origin resource sharing configuration
- Input Validation: GraphQL schema validation
- Environment Variables: Sensitive data protection
- Primary Colors: Tailwind's blue and gray palette
- Dark Mode: Persistent theme switching
- Typography: Inter font family
- Spacing: Consistent 8px grid system
- Animations: Smooth transitions and hover effects
We welcome contributions! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Use TypeScript for all new code
- Follow ESLint configuration
- Write tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Chuck Norris API for providing the facts data
- Apollo GraphQL for excellent GraphQL tools
- Tailwind CSS for the utility-first CSS framework
Joseph Kawe
- GitHub: https://github.com/dev-kohako
- LinkedIn: https://www.linkedin.com/in/josephkawe/
- Email: josephkawe000@gmail.com
π₯ Made with β€οΈ and a roundhouse kick by Joseph Kawe
β Star this repository if Chuck Norris would approve!
"Chuck Norris doesn't need a README, but his code does."
