Krank2me/rick-morty-app

โ˜… 0Forks 0TypeScriptGitHub โ†—Compare

README

Rick and Morty Character Explorer ๐Ÿš€

A modern, responsive web application built with React 18, TypeScript, and GraphQL to explore characters from the Rick and Morty universe. Browse, search, filter, and manage your favorite characters with an intuitive and beautiful user interface.

Rick and Morty

๐ŸŒŸ Features

Core Features

  • Character Listing: Browse all Rick and Morty characters with pagination
  • Character Details: View detailed information including origin, location, and episodes
  • Sorting: Sort characters alphabetically (A-Z / Z-A)
  • Favorites System: Mark characters as favorites with persistent storage
  • Comments: Add and view comments for each character
  • Responsive Design: Fully responsive layout that works on mobile, tablet, and desktop

Bonus Features

  • TypeScript: Full TypeScript implementation for type safety
  • Soft Delete: Temporarily remove characters from view (with restore option)
  • Advanced Filters: Filter by Status (Alive/Dead/Unknown), Species, and Gender
  • Unit Tests: Comprehensive test coverage for critical components
  • Modern UI: Beautiful interface with Tailwind CSS and smooth animations

๐Ÿ› ๏ธ Tech Stack

  • Frontend Framework: React 18
  • Language: TypeScript
  • Architecture: Feature-Driven Design
  • Build Tool: Vite
  • Styling: Tailwind CSS
  • Routing: React Router DOM v6
  • API: GraphQL with Apollo Client
  • State Management: React Context API + LocalStorage
  • Icons: Lucide React
  • Testing: Vitest + React Testing Library

๐Ÿ“‹ Prerequisites

Before running this application, make sure you have the following installed:

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

๐Ÿš€ Installation

  1. Clone the repository

    git clone <your-repository-url>
    cd ricky-morty-app
  2. Install dependencies

    npm install
  3. Start the development server

    npm run dev
  4. Open your browser Navigate to http://localhost:5173 (or the port shown in your terminal)

๐Ÿ“ฆ Available Scripts

  • npm run dev - Start the development server
  • npm run build - Build for production
  • npm run preview - Preview production build locally
  • npm run test - Run unit tests
  • npm run lint - Run ESLint

๐ŸŽฏ Usage

Browsing Characters

  • The home page displays a grid of character cards
  • Each card shows the character's image, name, species, and status
  • Click on any character card to view detailed information

Filtering and Sorting

  • Use the filter panel to search by name, status, species, or gender
  • Use the sort dropdown to order characters alphabetically
  • Filters and sorting work together for precise results

Managing Favorites

  • Click the heart icon on any character card to add/remove from favorites
  • Access your favorites from the navigation menu
  • Favorites are persisted in browser storage

Adding Comments

  • Navigate to a character's detail page
  • Type your comment in the input field
  • Click "Send" to add the comment
  • Comments are stored locally and persist across sessions

Soft Delete

  • Click the trash icon to temporarily remove a character from view
  • Deleted characters can be restored by clicking the restore icon
  • Soft-deleted characters are hidden but not permanently removed

๐Ÿ—๏ธ Project Structure

This project follows a Feature-Driven Architecture for better scalability and maintainability:

ricky-morty-app/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ features/            # Feature modules (self-contained)
โ”‚   โ”‚   โ”œโ”€โ”€ characters/      # Character listing feature
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ components/  # CharacterCard, CharacterListHeader, etc.
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ hooks/       # useCharacters, useCharacterFilters, etc.
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts     # Feature exports
โ”‚   โ”‚   โ”œโ”€โ”€ character-detail/  # Character detail feature
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ components/  # CharacterDetailHeader, CharacterInfo, etc.
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ hooks/       # useCharacterDetail
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”‚   โ”œโ”€โ”€ favorites/       # Favorites management feature
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ components/  # FavoritesHeader, EmptyFavorites
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ hooks/       # useFavoritesPage
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ context/     # FavoritesContext
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”‚   โ””โ”€โ”€ comments/        # Comments feature
โ”‚   โ”‚       โ”œโ”€โ”€ components/  # CommentSection
โ”‚   โ”‚       โ”œโ”€โ”€ hooks/       # useComments, useCharacterComments
โ”‚   โ”‚       โ””โ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ shared/              # Shared resources across features
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # Layout, CharacterDetails
โ”‚   โ”‚   โ”œโ”€โ”€ graphql/         # Apollo client, queries
โ”‚   โ”‚   โ”œโ”€โ”€ types/           # TypeScript type definitions
โ”‚   โ”‚   โ”œโ”€โ”€ utils/           # localStorage utilities
โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ pages/               # Route pages
โ”‚   โ”‚   โ”œโ”€โ”€ Home.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ CharacterDetailPage.tsx
โ”‚   โ”‚   โ””โ”€โ”€ FavoritesPage.tsx
โ”‚   โ”œโ”€โ”€ test/                # Test configuration and tests
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # Component tests
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ CharacterCard.test.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ CommentSection.test.tsx
โ”‚   โ”‚   โ””โ”€โ”€ setup.ts
โ”‚   โ”œโ”€โ”€ App.tsx              # Main App component
โ”‚   โ”œโ”€โ”€ main.tsx             # Application entry point
โ”‚   โ””โ”€โ”€ index.css            # Global styles
โ”œโ”€โ”€ public/                  # Static assets
โ”œโ”€โ”€ index.html               # HTML template
โ”œโ”€โ”€ package.json             # Dependencies and scripts
โ”œโ”€โ”€ tsconfig.json            # TypeScript configuration
โ”œโ”€โ”€ vite.config.ts           # Vite configuration
โ”œโ”€โ”€ tailwind.config.js       # Tailwind CSS configuration
โ””โ”€โ”€ README.md                # This file

Architecture Benefits

  • Feature Isolation: Each feature is self-contained with its own components, hooks, and logic
  • Scalability: Easy to add new features without affecting existing ones
  • Maintainability: Changes to one feature don't impact others
  • Clear Boundaries: Shared code is explicitly placed in shared/
  • Better Imports: Barrel exports (index.ts) provide clean import paths

Feature Modules

Characters Feature (features/characters/)

  • Character listing and grid display
  • Search and filtering functionality
  • Sorting capabilities
  • Character cards with actions

Character Detail Feature (features/character-detail/)

  • Individual character detail pages
  • Episode information
  • Character metadata display

Favorites Feature (features/favorites/)

  • Favorites management
  • Favorites context and state
  • Favorites page and empty states

Comments Feature (features/comments/)

  • Comment system for characters
  • Comment storage and retrieval
  • Comment UI components

๐Ÿ”Œ API Documentation

This application uses the Rick and Morty GraphQL API.

Main Queries

Get Characters List

query GetCharacters($page: Int, $filter: FilterCharacter) {
  characters(page: $page, filter: $filter) {
    info {
      count
      pages
      next
      prev
    }
    results {
      id
      name
      status
      species
      type
      gender
      image
      origin {
        name
      }
      location {
        name
      }
    }
  }
}

Get Character Details

query GetCharacter($id: ID!) {
  character(id: $id) {
    id
    name
    status
    species
    type
    gender
    origin {
      name
      dimension
    }
    location {
      name
      dimension
    }
    image
    episode {
      id
      name
      episode
    }
    created
  }
}

Filter Options

  • name: String - Filter by character name
  • status: "Alive" | "Dead" | "unknown"
  • species: String - Filter by species (e.g., "Human", "Alien")
  • gender: "Male" | "Female" | "Genderless" | "unknown"

๐Ÿ’พ Local Storage Schema

The application uses browser LocalStorage to persist data:

{
  "rickmorty_favorites": ["1", "2", "3"],
  "rickmorty_comments": {
    "1": [
      {
        "id": "uuid",
        "text": "Great character!",
        "timestamp": "2024-02-04T10:00:00.000Z"
      }
    ]
  },
  "rickmorty_deleted": ["5", "10"]
}

๐Ÿงช Testing

The application includes unit tests for critical components:

  • CharacterCard: Tests rendering, favorite toggle, and delete functionality
  • CommentSection: Tests comment addition, display, and validation

All tests have been updated to work with the new feature-driven architecture.

Run tests with:

npm run test

For interactive test UI:

npm run test:ui

๐ŸŽจ Design Reference

The UI design follows the mockup provided in the Figma design.

Key design elements:

  • Modern card-based layout
  • Clean typography with Inter font
  • Consistent spacing and padding
  • Intuitive navigation
  • Smooth animations and transitions
  • Accessible color contrast

๐Ÿ“ฑ Responsive Breakpoints

  • Mobile: < 640px (1 column)
  • Tablet: 640px - 1024px (2 columns)
  • Desktop: > 1024px (3-4 columns)

๐Ÿ”ง Configuration

Environment Variables

No environment variables are required. The application uses the public Rick and Morty GraphQL API.

Customization

You can customize the theme colors in tailwind.config.js:

theme: {
  extend: {
    colors: {
      primary: {
        // Your custom colors
      },
    },
  },
}

๐Ÿ› Known Issues

  • None at the moment

๐Ÿšง Future Enhancements

  • Add character comparison feature
  • Implement infinite scroll
  • Add dark mode support
  • Export favorites list
  • Share character profiles
  • Add episode details page

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ‘จโ€๐Ÿ’ป Author

Created as a technical assessment project.

๐Ÿ™ Acknowledgments


Note: This application is for educational and demonstration purposes only. All Rick and Morty content is owned by Adult Swim and Justin Roiland.

Contributors

Krank2me

Issues