# ritikraj3/country-project-in-react architecture

> Architecture diagram of the GitHub repository ritikraj3/country-project-in-react, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ritikraj3/country-project-in-react
- Repository: https://github.com/ritikraj3/country-project-in-react

## Overview

##### Project Type and Core Purpose
- This is a client-side single-page application (SPA) built with React and JSX.
- Its main responsibility is: fetch a list of countries (and individual country details) from an external REST API, apply filters/search, and render the results with light/dark theme support.

##### Main Architectural Components
a. Browser (User Agent)
b. React Application
- HTML Host: index.html
- Entry Point: index.jsx
- Root Component: App.jsx
- Global Context Provider: ThemeContext (contexts/ThemeContext.jsx)
- Presentational & Container Components (components/)
- Header.jsx (renders theme toggle)
- Home.jsx (renders Searchbar, SelectMenu, CountriesList)
- CountryDetail.jsx (renders details of a single country)
- CountriesList.jsx & CountryCard.jsx
- Shimmer variants for loading states
- Error.jsx (renders on fetch failure)
- Custom Hooks (hooks/)
- useFilter.jsx (manages search & region filter logic)
- useTheme.jsx (syncs user’s theme choice)
- useWindowSize.jsx (for responsive layouts)
c. External REST API
- “REST Countries” public API (e.g. https://restcountries.com/)
d. Static Assets

##### Data Flow & Relationships
- The user’s browser loads index.html → executes index.jsx → mounts App.
- App.jsx wraps child components in ThemeContext.Provider.
- Home route:
- Searchbar & SelectMenu update filter state (via useFilter).
- CountriesList triggers fetch (useEffect + fetch) → queries external API → returns JSON.
- While loading, CountriesListShimmer renders; then mapped to CountryCard for each country.
- Detail route:
- On clicking a CountryCard, App updates view to CountryDetail.
- CountryDetail fetches details by country code → renders CountryDetail or CountryDetailShimmer while loading.
- ThemeContext (useTheme) supplies current theme to all styled components (App.css, component-level CSS).
- useWindowSize drives responsive styling (e.g. mobile vs desktop layouts).
- Error.jsx displays if any fetch fails.

##### Architectural Patterns & Design Principles
- Component-Based Architecture: each UI piece isolated in its own folder/file.
- Unidirectional Data Flow: top-down props + context, bottom-up events (callbacks).
- Separation of Concerns:
- Presentation vs logic: visual components separate from hooks that encapsulate logic.
- Global state (theme) in Context API.
- Responsiveness & User Experience:
- Shimmer components for loading feedback.
- useWindowSize for layout adjustments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Title
    Title["Country-Project-in-React – System Architecture"]

    %% Browser and Entry
    Browser["Browser (User Agent)"]:::external
    HTML["index.html"]:::ui
    Entry["index.jsx"]:::ui
    App["App.jsx"]:::ui

    Browser -->|"loads"| HTML
    HTML -->|"executes"| Entry
    Entry -->|"mounts"| App

    %% Global State
    subgraph "Global State & Context"
        ThemeCtx["ThemeContext"]:::logic
        useTheme["useTheme()"]:::logic
    end
    App -->|"wraps in Provider"| ThemeCtx
    ThemeCtx -->|"syncs theme"| useTheme

    %% Custom Hooks
    subgraph "Custom Hooks"
        useFilter["useFilter()"]:::logic
        useWindow["useWindowSize()"]:::logic
    end

    %% UI Components
    subgraph "UI Components"
        Header["Header.jsx"]:::ui
        Home["Home.jsx"]:::ui
        CountryDetail["CountryDetail.jsx"]:::ui
        ErrorCmp["Error.jsx"]:::ui

        subgraph "Home Subcomponents"
            Searchbar["Searchbar.jsx"]:::ui
            SelectMenu["SelectMenu.jsx"]:::ui
            CountriesList["CountriesList.jsx"]:::ui
            CountriesListShimmer["CountriesListShimmer.jsx"]:::ui
            CountryCard["CountryCard.jsx"]:::ui
        end

        subgraph "Detail Subcomponents"
            CountryDetailShimmer["CountryDetailShimmer.jsx"]:::ui
        end
    end

    %% Relationships: App to components
    App -->|"renders"| Header
    App -->|"route: Home"| Home
    App -->|"route: Detail"| CountryDetail
    App -->|"onError"| ErrorCmp

    %% Home interactions
    Home -->|"includes"| Searchbar
    Home -->|"includes"| SelectMenu
    Home -->|"includes"| CountriesList

    Searchbar -->|".filter via"| useFilter
    SelectMenu -->|".filter via"| useFilter
    CountriesList -->|".onResize"| useWindow
    CountryDetail -->|".onResize"| useWindow

    %% Data layer
    CountriesList -->|"fetch( GET countries )"| ExternalAPI
    CountryDetail -->|"fetch( GET country by code )"| ExternalAPI
    ExternalAPI["REST Countries API"]:::external
    ExternalAPI -->|"response JSON"| CountriesList
    ExternalAPI -->|"response JSON"| CountryDetail

    %% Shimmer usage
    CountriesList -->|"while loading"| CountriesListShimmer
    CountryDetail -->|"while loading"| CountryDetailShimmer

    %% Assets
    Assets["assets/images"]:::asset
    Header -->|"uses icons"| Assets

    %% Click events
    click HTML "https://github.com/ritikraj3/country-project-in-react/blob/main/index.html"
    click Entry "https://github.com/ritikraj3/country-project-in-react/blob/main/index.jsx"
    click App "https://github.com/ritikraj3/country-project-in-react/blob/main/App.jsx"
    click ThemeCtx "https://github.com/ritikraj3/country-project-in-react/blob/main/contexts/ThemeContext.jsx"
    click Header "https://github.com/ritikraj3/country-project-in-react/blob/main/components/Header.jsx"
    click Home "https://github.com/ritikraj3/country-project-in-react/blob/main/components/Home.jsx"
    click Searchbar "https://github.com/ritikraj3/country-project-in-react/blob/main/components/Searchbar.jsx"
    click SelectMenu "https://github.com/ritikraj3/country-project-in-react/blob/main/components/SelectMenu.jsx"
    click CountriesList "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountriesList.jsx"
    click CountriesListShimmer "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountriesListShimmer.jsx"
    click CountriesListShimmer "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountriesListShimmer.css"
    click CountryCard "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountryCard.jsx"
    click CountryDetail "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountryDetail.jsx"
    click CountryDetail "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountryDetail.css"
    click CountryDetailShimmer "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountryDetailShimmer.jsx"
    click CountryDetailShimmer "https://github.com/ritikraj3/country-project-in-react/blob/main/components/CountryDetailShimmer.css"
    click ErrorCmp "https://github.com/ritikraj3/country-project-in-react/blob/main/components/Error.jsx"
    click useFilter "https://github.com/ritikraj3/country-project-in-react/blob/main/hooks/useFilter.jsx"
    click useTheme "https://github.com/ritikraj3/country-project-in-react/blob/main/hooks/useTheme.jsx"
    click useWindow "https://github.com/ritikraj3/country-project-in-react/blob/main/hooks/useWindowSize.jsx"
    click Assets "https://github.com/ritikraj3/country-project-in-react/tree/main/assets/images"

    %% Styles
    classDef ui fill:#cfe2ff,stroke:#0d6efd,color:#0d6efd
    classDef logic fill:#d1e7dd,stroke:#198754,color:#198754
    classDef external fill:#ffe5b4,stroke:#ff9900,color:#ff9900
    classDef asset fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
