# joanguinart/bemobilechallenge architecture

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

- Interactive diagram: https://gitdiagram.com/joanguinart/bemobilechallenge
- Repository: https://github.com/joanguinart/bemobilechallenge

## Overview

##### Project type and purpose
- This is a full-stack-ish web application built with Next.js (v15) and React (v19).
- It lets users search Marvel characters/comics, view details, and save favorites in browser local storage.
- It consumes the external Marvel REST API via Next.js API routes.

##### File structure
- src/app → Next.js App Router entrypoints (layout.tsx, page.tsx, dynamic [id] pages).
- src/app/api → serverless API routes: /api/marvel and /api/comics. Each invokes Marvel API and returns JSON.
- src/components → reusable React UI components (CharacterCard, SearchBar, Header, etc.).
- src/context/FavoritesContext.tsx → React Context to manage favorites state (reads/writes localStorage).
- src/lib/marvel.ts → low-level Marvel API helper functions (hash creation, fetch wrappers).
- src/styles & css → SCSS/CSS Module files for styling per component.
- playwright-tests → end-to-end tests validating UI flows.
- next.config.ts, tsconfig.json, eslint.config.mjs → build/configuration.

##### README for additional insights
- Confirms usage of Next.js, React, TypeScript, SCSS Modules, Vercel deployment.
- Describes features: search, detail pages, favorites (localStorage), filter.
- Notes dev vs prod asset handling, Playwright tests.

##### Detailed capture of essential architectural elements
- Components folder feeding into App Router pages.
- How FavoritesContext wraps components and interacts with localStorage.
- Detail the lib/marvel.ts helper forwarding creds to Marvel API.
- Build & deploy flow: “npm run build → Vercel → global edge network.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser/Client Layer
    subgraph "Browser (Client)" 
        direction TB
        Browser[("Browser\nReact UI")]:::browser
        subgraph "UI Components"
            direction TB
            CharacterCard["CharacterCard"]:::ui
            CharactersList["CharactersList"]:::ui
            CharactersWithSearch["CharactersWithSearch"]:::ui
            Comic["Comic"]:::ui
            ComicsSection["ComicsSection"]:::ui
            Header["Header"]:::ui
            Heart["Heart"]:::ui
            LoadingBar["LoadingBar"]:::ui
            SearchBar["SearchBar"]:::ui
            SingleCharacterPage["SingleCharacterPage"]:::ui
        end
        FavoritesContext["FavoritesContext"]:::storage
        LocalStorage[("localStorage")]:::storage
    end

    %% Server Layer
    subgraph "Server (Next.js)" 
        direction TB
        AppRouter[("Next.js App Router\n(src/app)")]:::server
        subgraph "Pages"
            direction TB
            Layout["layout.tsx"]:::server
            Page["page.tsx"]:::server
            CharacterPage["[id]/page.tsx"]:::server
        end
        subgraph "API Routes"
            direction TB
            API_Marvel["/api/marvel"]:::api
            API_Comics["/api/comics"]:::api
        end
        MarvelHelper["marvel.ts\n(src/lib/marvel)"]:::server
    end

    %% External Services
    ExternalMarvelAPI[(External Marvel API)]:::external
    VercelCDN(("Vercel CDN / Hosting")):::external
    PlaywrightTests[("Playwright Tests")]:::testing

    %% Data Flows
    Browser -->|renders via SSR/SSG| AppRouter
    Browser -->|client fetch| API_Marvel
    Browser -->|client fetch| API_Comics
    API_Marvel -->|HTTP GET| ExternalMarvelAPI
    API_Comics -->|HTTP GET| ExternalMarvelAPI
    AppRouter -->|uses marvel.ts| MarvelHelper
    MarvelHelper -->|forwards request| ExternalMarvelAPI
    FavoritesContext -->|reads/writes| LocalStorage
    PlaywrightTests -->|simulate UI flows| Browser
    AppRouter -->|deploy build| VercelCDN

    %% UI Components relationships
    Browser --> CharacterCard
    Browser --> CharactersList
    Browser --> CharactersWithSearch
    Browser --> Comic
    Browser --> ComicsSection
    Browser --> Header
    Browser --> Heart
    Browser --> LoadingBar
    Browser --> SearchBar
    Browser --> SingleCharacterPage
    Browser --> FavoritesContext

    %% Click Events
    click Layout "https://github.com/joanguinart/bemobilechallenge/blob/main/src/app/layout.tsx"
    click Page "https://github.com/joanguinart/bemobilechallenge/blob/main/src/app/page.tsx"
    click CharacterPage "https://github.com/joanguinart/bemobilechallenge/blob/main/src/app/character/[id]/page.tsx"
    click AppRouter "https://github.com/joanguinart/bemobilechallenge/tree/main/src/app"
    click API_Marvel "https://github.com/joanguinart/bemobilechallenge/blob/main/src/app/api/marvel/route.ts"
    click API_Comics "https://github.com/joanguinart/bemobilechallenge/blob/main/src/app/api/comics/route.ts"
    click CharacterCard "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/CharacterCard.tsx"
    click CharactersList "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/CharactersList.tsx"
    click CharactersWithSearch "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/CharactersWithSearch.tsx"
    click Comic "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/Comic.tsx"
    click ComicsSection "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/ComicsSection.tsx"
    click Header "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/Header.tsx"
    click Heart "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/Heart.tsx"
    click LoadingBar "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/LoadingBar.tsx"
    click SearchBar "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/SearchBar.tsx"
    click SingleCharacterPage "https://github.com/joanguinart/bemobilechallenge/blob/main/src/components/SingleCharacterPage.tsx"
    click FavoritesContext "https://github.com/joanguinart/bemobilechallenge/blob/main/src/context/FavoritesContext.tsx"
    click MarvelHelper "https://github.com/joanguinart/bemobilechallenge/blob/main/src/lib/marvel.ts"
    click LocalStorage "https://github.com/joanguinart/bemobilechallenge/blob/main/src/context/FavoritesContext.tsx"
    click PlaywrightTests "https://github.com/joanguinart/bemobilechallenge/tree/main/playwright-tests/"
    click VercelCDN "https://github.com/joanguinart/bemobilechallenge/blob/main/next.config.ts"

    %% Styles and Types (grouped click regions)
    classDef ui fill:#D6EAF8,stroke:#3498DB,color:#1B4F72
    classDef server fill:#D5F5E3,stroke:#27AE60,color:#145A32
    classDef api fill:#ABEBC6,stroke:#229954,color:#1D8348
    classDef external fill:#FAD7A0,stroke:#D68910,color:#784212
    classDef storage fill:#FCF3CF,stroke:#F1C40F,color:#7D6608
    classDef browser fill:#EBDEF0,stroke:#8E44AD,color:#4A235A
    classDef testing fill:#E5E7E9,stroke:#ABB2B9,color:#424949
```
