# sachalifs/rickandmorty architecture

> Architecture diagram of the GitHub repository sachalifs/rickandmorty, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sachalifs/rickandmorty
- Repository: https://github.com/sachalifs/rickandmorty

## Overview

1. **What this repo is**
   - A **single-page React application** built with **Create React App + TypeScript**.
   - Its purpose is to display a **list of Rick and Morty characters** by consuming the **public Rick and Morty GraphQL API**.
   - There is **no custom backend** in the repo; the browser app talks directly to the external GraphQL service.

2. **App bootstrap and runtime boundary**
   - The app is mounted from **`src/index.tsx`** into **`public/index.html`**.
   - `src/index.css` provides global styling, and `src/reportWebVitals.ts` / `src/setupTests.ts` are the standard CRA support files.
   - The whole system runs as a **client-side web app** in the browser.

3. **Top-level composition**
   - **`src/App.tsx`** is the top container.
   - **`src/AppContent.tsx`** appears to hold the actual page composition and likely orchestrates the main screen: hero/header area, character list, loading state, and any call-to-action/button wrapper.
   - This split suggests a clean separation between the app shell and the screen’s content logic.

4. **Data access layer**
   - **`src/api.ts`** is the central API boundary.
   - The README says data is obtained by **generated GraphQL types, queries, and React hooks**, so this file is likely the codegen entrypoint or a generated client facade.
   - Important architectural point: the UI does **not** use manual `fetch`, `axios`, or hand-written promise plumbing; data access is abstracted through generated GraphQL hooks.

5. **External service dependency**
   - The only material external dependency is the **Rick and Morty GraphQL API**.
   - The application’s data flow is therefore:
     - React screen mounts
     - generated GraphQL hook runs
     - API returns character data
     - UI renders the list/cards
   - This makes the repo a **frontend consumer of a public API**, not a full-stack system.

6. **Domain presentation: characters**
   - **`src/components/CharactersList/CharactersList.tsx`** is the list-level domain component.
   - **`src/components/CharacterCard/CharacterCard.tsx`** renders one character at a time.
   - The naming implies a standard parent/child data flow: the list receives a collection and maps each item into a card.
   - This is the core business surface of the app.

7. **Loading and state feedback**
   - **`src/components/Loader/Loader.tsx`** provides async feedback while data is being fetched.
   - This is important because the UI depends on remote GraphQL data and must represent loading state explicitly.
   - The loader is part of the presentation layer, not the data layer.

8. **Shared UI primitives**
   - **`Button`**, **`ButtonWrapper`**, and **`Typography`** are reusable design-system-like components.
   - These are likely used across the app to keep styling and spacing consistent.
   - Their presence indicates the UI is componentized around **small reusable primitives** rather than large page-specific styles.

9. **Layout and visual structure**
   - **`Hero`** provides the top-of-page branding/header area.
   - **`CharactersList/styles.ts`**, **`Button/styles.ts`**, **`Hero/styles.tsx`**, and **`Loader/styles.ts`** indicate the app uses **styled-components** or a similar CSS-in-JS approach.
   - Styling is therefore colocated with components, which matters for the architecture diagram because visual concerns are tightly bound to the UI components rather than a separate CSS layer.

10. **Mock and fixture data**
   - **`src/characters-mock.ts`** and **`src/components/CharactersList/characters.ts`** suggest local sample data or typed fixtures.
   - These files likely support development, story/demo data, or a fallback path.
   - They are not the primary source of truth; the GraphQL API is.

11. **Project structure and boundaries**
   - `src/components/index.ts` and per-component `index.ts` files show a barrel-export pattern for cleaner imports.
   - The repo is organized by **feature/component folders**, not by technical layers alone.
   - The main boundary is:
     - **presentation components** on one side
     - **GraphQL data access** on the other
     - with `AppContent` acting as the composition/orchestration layer between them.

12. **Build and tooling**
   - `package.json`, `package-lock.json`, and `tsconfig.json` indicate a standard Node-based frontend build.
   - The README documents `npm run update:graphql`, which means **schema/query code generation** is part of the workflow.
   - `public/manifest.json` and `public/robots.txt` are standard CRA static assets, not core architecture.

13. **How the main data path likely looks**
   - Browser loads the SPA.
   - `index.tsx` renders `App`.
   - `AppContent` triggers the generated GraphQL query hook from `api.ts`.
   - While pending, `Loader` is shown.
   - When data resolves, `CharactersList` receives the results and renders `CharacterCard` instances.
   - Shared primitives like `Typography`, `Button`, and `Hero` frame the page around that list.

14. **Diagram takeaways**
   - Draw this as a **frontend-only client app** with one significant external dependency: the **Rick and Morty GraphQL API**.
   - Inside the app, show a clear split between:
     - **app shell/composition**
     - **generated data access**
     - **domain UI components**
     - **shared presentation primitives**
   - The list-and-card rendering path is the central functional flow of the repository.

Main entry points: [`src/AppContent.tsx`](https://github.com/sachalifs/rickandmorty/blob/master/src/AppContent.tsx) (AppContent), [`src/components/CharactersList/CharactersList.tsx`](https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharactersList/CharactersList.tsx) (CharactersList), [`src/components/Typography/Typography.tsx`](https://github.com/sachalifs/rickandmorty/blob/master/src/components/Typography/Typography.tsx) (Typography), [`src/components/Button/Button.tsx`](https://github.com/sachalifs/rickandmorty/blob/master/src/components/Button/Button.tsx) (Button)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_public_index["index.html<br/>html shell<br/>[index.html]"]
  node_src_index["index.tsx<br/>bootstrap<br/>[index.tsx]"]
end

subgraph group_composition["Composition"]
  node_app["App<br/>[App.tsx]"]
  node_app_content["AppContent<br/>screen composer<br/>[AppContent.tsx]"]
end

subgraph group_data["Data"]
  node_api["api<br/>GraphQL client<br/>[api.ts]"]
  node_external_api[("GraphQL API<br/>external service")]
end

subgraph group_domain["Domain UI"]
  node_characters_list["CharactersList<br/>list view<br/>[CharactersList.tsx]"]
  node_character_card["CharacterCard<br/>item view<br/>[CharacterCard.tsx]"]
  node_hero["Hero<br/>header view<br/>[index.ts]"]
  node_loader(("Loader<br/>async state<br/>[Loader.tsx]"))
  node_characters_mock["characters mock<br/>fixture data<br/>[characters-mock.ts]"]
  node_characters_data["characters data<br/>local data<br/>[characters.ts]"]
end

subgraph group_ui["Shared UI"]
  node_button["Button<br/>control<br/>[Button.tsx]"]
  node_button_wrapper["ButtonWrapper<br/>layout helper<br/>[ButtonWrapper.ts]"]
  node_typography["Typography<br/>text primitive<br/>[Typography.tsx]"]
  node_components_index["components index<br/>barrel export<br/>[index.ts]"]
  node_styles_bundle["styles<br/>css-in-js"]
end

node_public_index -->|"loads"| node_src_index
node_src_index -->|"renders"| node_app
node_app -->|"composes"| node_app_content
node_app_content -->|"queries"| node_api
node_api -->|"calls"| node_external_api
node_app_content -->|"shows"| node_loader
node_app_content -->|"frames"| node_hero
node_app_content -->|"uses"| node_button
node_app_content -->|"uses"| node_button_wrapper
node_app_content -->|"passes data"| node_characters_list
node_characters_list -->|"maps to"| node_character_card
node_characters_list -.->|"may use"| node_characters_data
node_characters_mock -.->|"supports"| node_characters_data
node_characters_list -->|"uses"| node_typography
node_character_card -->|"uses"| node_typography
node_hero -->|"uses"| node_typography
node_button -->|"uses"| node_typography
node_button -->|"styles"| node_styles_bundle
node_hero -->|"styles"| node_styles_bundle
node_loader -->|"styles"| node_styles_bundle
node_characters_list -->|"styles"| node_styles_bundle
node_components_index -->|"exports"| node_button
node_components_index -->|"exports"| node_button_wrapper
node_components_index -->|"exports"| node_typography

click node_public_index "https://github.com/sachalifs/rickandmorty/blob/master/public/index.html"
click node_src_index "https://github.com/sachalifs/rickandmorty/blob/master/src/index.tsx"
click node_app "https://github.com/sachalifs/rickandmorty/blob/master/src/App.tsx"
click node_app_content "https://github.com/sachalifs/rickandmorty/blob/master/src/AppContent.tsx"
click node_api "https://github.com/sachalifs/rickandmorty/blob/master/src/api.ts"
click node_characters_list "https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharactersList/CharactersList.tsx"
click node_character_card "https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharacterCard/CharacterCard.tsx"
click node_hero "https://github.com/sachalifs/rickandmorty/blob/master/src/components/Hero/index.ts"
click node_loader "https://github.com/sachalifs/rickandmorty/blob/master/src/components/Loader/Loader.tsx"
click node_button "https://github.com/sachalifs/rickandmorty/blob/master/src/components/Button/Button.tsx"
click node_button_wrapper "https://github.com/sachalifs/rickandmorty/blob/master/src/components/ButtonWrapper/ButtonWrapper.ts"
click node_typography "https://github.com/sachalifs/rickandmorty/blob/master/src/components/Typography/Typography.tsx"
click node_characters_mock "https://github.com/sachalifs/rickandmorty/blob/master/src/characters-mock.ts"
click node_characters_data "https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharactersList/characters.ts"
click node_components_index "https://github.com/sachalifs/rickandmorty/blob/master/src/components/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_index,node_src_index toneBlue
class node_app,node_app_content toneAmber
class node_api,node_external_api toneMint
class node_characters_list,node_character_card,node_hero,node_loader,node_characters_mock,node_characters_data toneRose
class node_button,node_button_wrapper,node_typography,node_components_index,node_styles_bundle toneIndigo
```

## Components

### Runtime

Browser SPA boundary and entrypoint

- [index.html](https://github.com/sachalifs/rickandmorty/blob/master/public/index.html): html shell · SPA host document · `public/index.html`
- [index.tsx](https://github.com/sachalifs/rickandmorty/blob/master/src/index.tsx): bootstrap · React entrypoint · `src/index.tsx`

### Composition

Top-level app assembly and screen orchestration

- [App](https://github.com/sachalifs/rickandmorty/blob/master/src/App.tsx): app shell · Top-level application wrapper · `src/App.tsx`
- [AppContent](https://github.com/sachalifs/rickandmorty/blob/master/src/AppContent.tsx): screen composer · Main page composition and orchestration · `src/AppContent.tsx`

### Data

GraphQL access and external service dependency

- [api](https://github.com/sachalifs/rickandmorty/blob/master/src/api.ts): GraphQL client · Generated query and hook boundary · `src/api.ts`
- **GraphQL API**: external service · Public Rick and Morty GraphQL service

### Domain UI

Characters screen and related views

- [CharactersList](https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharactersList/CharactersList.tsx): list view · Renders the character collection · `src/components/CharactersList/CharactersList.tsx`
- [CharacterCard](https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharacterCard/CharacterCard.tsx): item view · Renders one character · `src/components/CharacterCard/CharacterCard.tsx`
- [Hero](https://github.com/sachalifs/rickandmorty/blob/master/src/components/Hero/index.ts): header view · Top-of-page branding area · `src/components/Hero/index.ts`
- [Loader](https://github.com/sachalifs/rickandmorty/blob/master/src/components/Loader/Loader.tsx): async state · Loading feedback while data resolves · `src/components/Loader/Loader.tsx`
- [characters mock](https://github.com/sachalifs/rickandmorty/blob/master/src/characters-mock.ts): fixture data · Local sample character data · `src/characters-mock.ts`
- [characters data](https://github.com/sachalifs/rickandmorty/blob/master/src/components/CharactersList/characters.ts): local data · Characters collection fixture or constants · `src/components/CharactersList/characters.ts`

### Shared UI

Reusable presentation primitives

- [Button](https://github.com/sachalifs/rickandmorty/blob/master/src/components/Button/Button.tsx): control · Reusable clickable primitive · `src/components/Button/Button.tsx`
- [ButtonWrapper](https://github.com/sachalifs/rickandmorty/blob/master/src/components/ButtonWrapper/ButtonWrapper.ts): layout helper · Spacing and placement for buttons · `src/components/ButtonWrapper/ButtonWrapper.ts`
- [Typography](https://github.com/sachalifs/rickandmorty/blob/master/src/components/Typography/Typography.tsx): text primitive · Reusable text styling component · `src/components/Typography/Typography.tsx`
- [components index](https://github.com/sachalifs/rickandmorty/blob/master/src/components/index.ts): barrel export · Shared component exports · `src/components/index.ts`
- **styles**: css-in-js · Component-scoped styling files

## Connections

- index.html → index.tsx: loads · Document hosts the React entrypoint
- index.tsx → App: renders · Bootstraps the root application
- App → AppContent: composes · App delegates screen composition
- AppContent → api: queries · Requests character data through generated GraphQL hooks
- api → GraphQL API: calls · GraphQL client reads from the public service
- AppContent → Loader: shows · Loading state while remote data is pending
- AppContent → Hero: frames · Uses header/branding area above the list
- AppContent → Button: uses · Screen actions may rely on reusable buttons
- AppContent → ButtonWrapper: uses · Button placement and spacing wrapper
- AppContent → CharactersList: passes data · Provides resolved character results to the list
- CharactersList → CharacterCard: maps to · Renders each character as a card
- CharactersList → characters data: may use · List can be driven by local fixture data
- characters mock → characters data: supports · Mock data complements local character fixtures
- CharactersList → Typography: uses · List presentation uses shared text styles
- CharacterCard → Typography: uses · Card text is rendered through shared typography
- Hero → Typography: uses · Header text uses shared typography
- Button → Typography: uses · Button label styling relies on typography
- Button → styles: styles · Component styling is colocated
- Hero → styles: styles · Component styling is colocated
- Loader → styles: styles · Component styling is colocated
- CharactersList → styles: styles · List styling is colocated
- components index → Button: exports · Barrel re-exports shared primitives
- components index → ButtonWrapper: exports · Barrel re-exports shared primitives
- components index → Typography: exports · Barrel re-exports shared primitives
