# mati-gaston/pokedex-app architecture

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

- Interactive diagram: https://gitdiagram.com/mati-gaston/pokedex-app
- Repository: https://github.com/mati-gaston/pokedex-app

## Overview

##### Project type and purpose
- This is a full-stack web application (“Pokedex + Gestor de usuarios”) with:
- A React/React Router DOM frontend (port 3000)
- A Node.js + Express backend (port 4000)
- A MySQL database
- External integration with the public PokéAPI
- Main features: JWT-based authentication, role-based access (admin/viewer), user CRUD, paginated/searchable Pokedex.

##### File structure
- Top level:
- backend/ – Node.js + Express server
– index.js (entry point)
– db.js (MySQL connection)
– controllers/authController.js
– routes/auth.js, routes/users.js
– middleware/authMiddleware.js
– database.sql
- frontend/ – React app
– src/components (NavBar, protected-route, etc.)
– src/context/AuthContext.js (holds auth state + JWT)
– src/pages (Login, Admin, Pokedex, etc.)
– public/index.html + images
- Architectural hints:
- Follows a layered pattern in backend: Routes → Controllers → DB access
- Frontend uses Context for auth, React Router for routing.

##### README for additional insights
- Technology stack: React, Bootstrap, Node.js, Express, JWT, bcryptjs, dotenv, MySQL
- Database setup script (database.sql) creates `usuarios` table + seed user
- Frontend fetches both your backend API (for auth & user management) and the external PokéAPI (for Pokémon data).

a. Main components
- Client-Browser (React SPA)
- Web Server (Express API)
- MySQL Database
- External Service (PokéAPI)
- localStorage (in the browser) for JWT
b. Relationships & data flows
1. User opens React UI → UI triggers HTTP requests
2. Authentication flow:
– Login page → POST /auth/login → Express → authController → MySQL
– Express generates JWT → returns to client → stored in localStorage
3. Protected routes (admin, user CRUD):
– React sends JWT in Authorization header → authMiddleware verifies → controllers handle DB operations
4. Pokedex page:
– React directly calls external PokéAPI → renders paginated/search data
5. Admin pages:
– React calls /users routes → Express → MySQL
c. Architectural patterns & principles
- Layered architecture (Presentation, API routing, controllers/services, persistence)
- Stateless sessions via JWT
- Separation of concerns (frontend vs. backend)
- Context API for global state in React
d. Technologies & frameworks
- React (+ React Router, Bootstrap)
- Node.js + Express
- MySQL (via mysql2 or similar driver in db.js)
- JWT (jsonwebtoken) & bcryptjs for auth
- dotenv for environment configuration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Entry["Entry Point (index.js)"]:::frontend
        App["App Routing (App.js)"]:::frontend
        AuthContext["AuthContext"]:::frontend
        NavBar["NavBar"]:::frontend
        VolverArriba["ScrollToTop"]:::frontend
        RutaProtegida["Protected Route"]:::frontend
        AdminRuta["Admin Route"]:::frontend
        LoginPage["Login Page"]:::frontend
        PokedexPage["Pokedex Page"]:::frontend
        GestionUsuarios["User Management Page"]:::frontend
        AdminPage["Admin Dashboard"]:::frontend
        InicioPage["Home Page"]:::frontend
        ErrorPage["Error Page"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        BackendEntry["Entry Point (index.js)"]:::backend
        DBConn["MySQL Connection (db.js)"]:::backend
        AuthMiddleware["Auth Middleware"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoutes["Auth Routes"]:::backend
            UserRoutes["User Routes"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthController["Auth Controller"]:::backend
        end
        DBScript["DB Init Script"]:::backend
    end

    %% Database and External
    DB["MySQL Database"]:::db
    External["PokéAPI"]:::external

    %% Frontend flows
    Entry --> App
    App --> AuthContext
    App --> NavBar
    App --> VolverArriba
    App --> RutaProtegida
    App --> AdminRuta
    App --> LoginPage
    App --> PokedexPage
    App --> GestionUsuarios
    App --> AdminPage
    App --> InicioPage
    App --> ErrorPage

    LoginPage -->|POST /auth/login| AuthRoutes
    AuthRoutes --> AuthController
    AuthController --> DBConn
    DBConn --> DB
    AuthController -->|JWT| AuthRoutes
    AuthRoutes -->|200 JWT| LoginPage
    LoginPage -->|store JWT| AuthContext

    GestionUsuarios -->|GET/POST /users| UserRoutes
    UserRoutes --> AuthMiddleware
    UserRoutes --> DBConn
    DBConn --> DB

    PokedexPage -->|GET /pokemon| External

    BackendEntry --> AuthRoutes
    BackendEntry --> UserRoutes
    BackendEntry --> DBConn
    BackendEntry --> AuthMiddleware
    BackendEntry --> AuthController
    BackendEntry --> DBScript

    %% Click Events - Frontend
    click Entry "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/index.js"
    click App "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/App.js"
    click AuthContext "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/context/AuthContext.js"
    click RutaProtegida "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/components/RutaProtegida.js"
    click NavBar "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/components/NavBar.js"
    click VolverArriba "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/components/VolverArriba.js"
    click AdminRuta "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/components/AdminRuta.js"
    click LoginPage "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/pages/Login.js"
    click PokedexPage "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/pages/Pokedex.js"
    click GestionUsuarios "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/pages/GestionUsuarios.js"
    click AdminPage "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/pages/Admin.js"
    click InicioPage "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/pages/Inicio.js"
    click ErrorPage "https://github.com/mati-gaston/pokedex-app/blob/main/frontend/src/pages/Error.js"

    %% Click Events - Backend
    click BackendEntry "https://github.com/mati-gaston/pokedex-app/blob/main/backend/index.js"
    click DBConn "https://github.com/mati-gaston/pokedex-app/blob/main/backend/db.js"
    click AuthController "https://github.com/mati-gaston/pokedex-app/blob/main/backend/controllers/authController.js"
    click AuthRoutes "https://github.com/mati-gaston/pokedex-app/blob/main/backend/routes/auth.js"
    click UserRoutes "https://github.com/mati-gaston/pokedex-app/blob/main/backend/routes/users.js"
    click AuthMiddleware "https://github.com/mati-gaston/pokedex-app/blob/main/backend/middleware/authMiddleware.js"
    click DBScript "https://github.com/mati-gaston/pokedex-app/blob/main/backend/database.sql"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#004E8A,color:#000
    classDef backend fill:#DFF2D8,stroke:#27632A,color:#000
    classDef db fill:#FFE8C0,stroke:#A46300,color:#000
    classDef external fill:#E0E0E0,stroke:#888888,color:#000
```
