# hildelio/js-developer-pokedex architecture

> Architecture diagram of the GitHub repository hildelio/js-developer-pokedex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hildelio/js-developer-pokedex
- Repository: https://github.com/hildelio/js-developer-pokedex

## Overview

##### Project type and purpose
- This is a single-page, front-end Pokedex application built in vanilla JavaScript, HTML and CSS.
- It loads in the browser (index.html + CSS), fetches Pokémon data from an external API (pokeapi.co), applies a client-side data model, and renders results dynamically.

##### File structure
- index.html: the HTML entry point and root of the document.
- assets/css/global.css & pokedex.css: styling rules for layout and Pokémon-specific UI.
- assets/js/main.js: orchestrates user interactions, ties together view updates and service/model calls.
- assets/js/poke-api.js: encapsulates all HTTP calls to the external Pokémon API (e.g., using fetch).
- assets/js/pokemon-model.js: defines the in-memory data structures (e.g., Pokemon class/object) and any mapping or transformation logic.

##### Key insights from the README
- Very concise title: “Trilha JS Developer – Pokedex”
- No built-in backend or database; relies entirely on a third-party REST API.

##### Components
a. Browser (Client)
- index.html (static entry point)
- CSS modules (global.css, pokedex.css)
- JavaScript modules (main.js, poke-api.js, pokemon-model.js)
b. Presentation Layer (main.js + DOM)
- Listens for user events (search, pagination, click on a Pokémon)
- Updates view templates or DOM elements
c. Service Layer (poke-api.js)
- Exposes functions like getPokemonList(), getPokemonDetails(id)
- Uses Fetch API to call https://pokeapi.co
d. Data Model Layer (pokemon-model.js)
- Defines Pokemon entity with fields (id, name, stats, sprites)
- Transforms raw JSON into your front-end model
e. External API
- pokeapi.co (public REST endpoints)
f. In-memory Store
- Temporary cache of loaded Pokémon to avoid re-fetching

##### Relationships and interactions
1. User interacts with UI in Browser.
2. main.js captures the event (e.g., “load list” or “show details”).
3. main.js calls the Service Layer function in poke-api.js.
4. poke-api.js issues HTTP request to pokeapi.co and returns JSON.
5. pokemon-model.js transforms JSON into a JS object (Pokemon).
6. main.js receives the model instance(s), updates the DOM (view).
7. CSS styles are applied immediately by the browser.

##### Architectural patterns & principles
- Separation of concerns:
- View (HTML + CSS)
- Orchestration/Controller (main.js)
- Service/API wrapper (poke-api.js)
- Domain model (pokemon-model.js)
- Client-side MVC/MV* flavor (thin view layer, simple controller + model).
- Stateless on server side; state is ephemeral in the browser.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser"
        direction TB
        subgraph "View Layer"
            direction TB
            IndexHTML["index.html"]:::ui
            GlobalCSS["global.css"]:::ui
            PokeCSS["pokedex.css"]:::ui
        end
        subgraph "Controller Layer"
            MainJS["main.js"]:::logic
        end
        subgraph "Service Layer"
            PokeAPI["poke-api.js"]:::logic
        end
        subgraph "Model Layer"
            PokemonModel["pokemon-model.js"]:::logic
        end
    end

    ExternalAPI[(pokeapi.co)]:::external

    IndexHTML -->|"user event"| MainJS
    MainJS -->|"fetchPokemonList()"| PokeAPI
    PokeAPI -->|"HTTP GET"| ExternalAPI
    ExternalAPI -->|"JSON response"| PokeAPI
    PokeAPI -->|"toModel(rawJSON)"| PokemonModel
    PokemonModel -->|"Pokemon instance"| MainJS
    MainJS -->|"updateDOM()"| IndexHTML

    click IndexHTML "https://github.com/hildelio/js-developer-pokedex/blob/main/index.html"
    click GlobalCSS "https://github.com/hildelio/js-developer-pokedex/blob/main/assets/css/global.css"
    click PokeCSS "https://github.com/hildelio/js-developer-pokedex/blob/main/assets/css/pokedex.css"
    click MainJS "https://github.com/hildelio/js-developer-pokedex/blob/main/assets/js/main.js"
    click PokeAPI "https://github.com/hildelio/js-developer-pokedex/blob/main/assets/js/poke-api.js"
    click PokemonModel "https://github.com/hildelio/js-developer-pokedex/blob/main/assets/js/pokemon-model.js"

    classDef ui fill:#ADE8F4,stroke:#333,stroke-width:1px
    classDef logic fill:#D8F3DC,stroke:#333,stroke-width:1px
    classDef external fill:#FFC8DD,stroke:#333,stroke-width:1px
```
