How kotkoa/rickandmorty works
Project type and purpose
• This is a single-page, client-side web application (built with Vite + React + TypeScript) that lets users browse “Rick and Morty” characters, locations, and episodes.
• It acts purely as a frontend; it queries the public Rick and Morty GraphQL API via Apollo Client and manages UI state with Jotai.
File structure
• Top-level config: .env(.example), codegen.yml, tsconfig.json, vite.config.mts, ESLint/Prettier configs.
• src/ contains:
• apolloClient/ – Apollo Client setup pointing at the external GraphQL endpoint
• components/ – UI components organized by feature (char-card, char-list, details, pagination, etc.)
• routes/ – app-router.tsx defines React Router routes or equivalent
• store/ – Jotai atoms for global state (e.g., characters.store.ts)
• queries/ – .gql query definitions
• generated/ – GraphQL codegen output (graphql.tsx, types)
• src/main.tsx & src/root.tsx bootstrap the React application.
• Tests live under src/__tests__, exercising components with React Testing Library.
README
• Confirms tech stack: Vite, React, TypeScript, Apollo GraphQL, Jotai, React Testing Library.
• No backend or microservices—all GraphQL data comes from the public API.
a. Main components:
• Client (Browser) running the bundled React SPA
• Vite Dev/Build Toolchain (serves during dev & bundles for prod)
• React Application Layers:
– Presentation/UI Layer (components folder)
– Routing Layer (app-router.tsx in routes/)
– State Management Layer (Jotai atoms in store/)
– Data Layer (Apollo Client in apolloClient/)
• GraphQL Code Generation (codegen.yml → generated/graphql.tsx)
• External Service: Rick and Morty GraphQL API
• Developer Tooling: ESLint, Prettier, TypeScript config (for build and lint pipelines)
• Test Runner (React Testing Library in __tests__)
b. Relationships and interactions:
1. Browser requests index.html → Vite serves the SPA.
2. main.tsx/root.tsx initialize React, wrap in ApolloProvider and Jotai Provider.
3. UI Components subscribe to Jotai atoms or directly invoke GraphQL queries via Apollo hooks.
4. Queries defined in queries/*.gql and code-generated types in generated/ ensure type safety.
5. Apollo Client sends HTTP requests to the Rick and Morty GraphQL endpoint, receives JSON responses.
6. State updates flow back into the React component tree.
7. CSS Modules (component-scoped .module.scss) style individual components; global CSS for reset and fonts.
8. Tests simulate user interactions against mounted components, verifying behavior.
c. Architectural patterns / design principles:
• Component-based UI (atomic & feature-oriented organization)
• Unidirectional data flow (React → Jotai/Apollo → External API)
• Separation of concerns: UI vs. state vs. data fetching vs. styling
• Type-safe GraphQL integration via codegen
d. Relevant technologies:
• Vite (dev server, bundler)
• React + React Router (component & navigation)
• TypeScript (static typing)
• Apollo Client (GraphQL data fetching)
• graphql-codegen (type/s API stubs generator)
• Jotai (minimal global state)
• SCSS Modules & CSS (styles)
• ESLint/Prettier (code quality)
• React Testing Library + Jest (tests)