Skip to content

dev-kohako/chuck-norris-facts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chuck Norris Facts πŸ₯‹

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.

Chuck Norris Facts Application Preview

πŸš€ Live Demo

Experience Chuck Norris facts like never before: https://chuck-norris-facts-kwk.vercel.app/


✨ Features

  • 🎲 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

πŸ—οΈ Architecture

This project follows a modern full-stack architecture:

Frontend (Client)

  • React 18 with TypeScript for type safety
  • Apollo Client for GraphQL state management
  • Tailwind CSS for responsive styling
  • Lucide React for beautiful icons

Backend (Server)

  • 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

πŸ› οΈ Tech Stack

Frontend Dependencies

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

Backend Dependencies

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

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn package manager

Installation

# Clone the repository
git clone https://github.com/your-username/chuck-norris-facts.git
cd chuck-norris-facts

Backend Setup

# Navigate to server directory
cd server

# Install dependencies
npm install

# Create environment file
cp .env.example .env

# Start development server
npm start

The GraphQL server will be available at http://localhost:4000/graphql

Frontend Setup

# Navigate to client directory (in a new terminal)
cd client

# Install dependencies
npm install

# Start React development server
npm start

The React app will be available at http://localhost:3000


πŸ“œ Available Scripts

Frontend Scripts

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

Backend Scripts

Command Description
npm start Starts the GraphQL server with hot reload
npm test Runs server-side tests

πŸ“ Project Structure

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

Backend GraphQL API

β”œβ”€β”€ 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

πŸ”§ Environment Variables

Create a .env file in the server directory:

PORT=4000
CHUCK_NORRIS_API_URL=https://api.chucknorris.io
NODE_ENV=development

πŸ“Š API Endpoints

GraphQL Schema

type 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!]!
}

πŸ§ͺ Testing

Frontend Testing

cd client

# Run unit tests
npm test

# Run e2e tests
npm run cypress:open

Backend Testing

cd server

# Run server tests
npm test

🌐 Deployment

Frontend (Vercel)

The frontend is automatically deployed to Vercel on every push to main branch.

Backend (Railway/Heroku)

Configure your preferred hosting platform with the following settings:

  • Build Command: npm run build
  • Start Command: npm start
  • Node Version: 18+

πŸ”’ Security Features

  • Helmet.js: Security headers protection
  • CORS: Cross-origin resource sharing configuration
  • Input Validation: GraphQL schema validation
  • Environment Variables: Sensitive data protection

🎨 Design System

  • 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

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style Guidelines

  • Use TypeScript for all new code
  • Follow ESLint configuration
  • Write tests for new features
  • Update documentation as needed

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


πŸ‘¨β€πŸ’» Author

Joseph Kawe


πŸ₯‹ 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."

Releases

No releases published

Packages

 
 
 

Contributors