# andresbrav/pg-frontend-ts- architecture

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

- Interactive diagram: https://gitdiagram.com/andresbrav/pg-frontend-ts-
- Repository: https://github.com/andresbrav/pg-frontend-ts-

## Overview

1. This is a Vite + React + TypeScript single-page client application. The runtime entry points are `src/main.tsx` and `src/App.tsx`, with Vite handling dev server, HMR, and production bundling.

2. The app is organized around two major user journeys: account access and the game/training experience. The `src/pages/users` area contains `Login.tsx`, `SignUp.tsx`, and avatar selection, while `src/pages/Games` contains the learning activities and presentation/dashboard screens.

3. Authentication is a distinct subsystem. `src/Context/TokenContext.tsx` and `TokenProvider.tsx` manage access-token state, `src/Services/authService.ts` centralizes auth logic, and `useAuthRedirect.ts` / `useCerrarSesion.ts` provide login gating and logout behavior.

4. Backend integration is abstracted behind API modules rather than embedded in pages. `src/api/usuarioApi.ts` and `src/api/notificacionApi.ts` are the main client boundaries for user and notification data, suggesting the UI talks to an external backend service for persisted state and alerts.

5. The game area is split into two levels with separate exercise sets: `Level1` and `Nivel2`. Each level has its own exercise pages, result-checking modules (`VerificarResultado.ts`, `VerificarResultadoPseudo.ts`), and supporting type/data files (`typesLevel1.ts`, `widgetsDataLevel1.ts`, `ejercicios.ts`).

6. Each game level also has responsive UI variants for desktop and mobile. The `DesignLaptop` and `DesignPhone` folders under each level indicate the same exercise logic is rendered through device-specific presentation components, likely chosen through screen-size detection.

7. Presentation and onboarding for the game are separated from the exercises themselves. `src/pages/Games/Presentation` contains the dashboard plus modal-based explanations (`Dashboard.tsx`, `ExplicationModal.tsx`, `ModalInf1.tsx`, `ModalInf2.tsx`), which likely serve as the entry screen before users enter exercises.

8. Responsive behavior is handled as a cross-cutting concern. `useVerificarTamañoPantalla.ts` appears to decide which device-specific component tree to show, keeping the exercise logic independent from layout selection.

9. Styling is heavily domain-scoped rather than global. CSS is partitioned into background, dashboard, games, modals, sweet alerts, and user/profile styles under `src/assets/styles`, which suggests the visual system is organized by feature area and screen type.

10. Static assets support the UI and avatar/game visuals. The `src/assets/avatares` and `src/assets/filesSvg` directories imply iconography and avatar-based personalization are part of the user-facing flow.

11. The repo is front-end only in this tree: there is no local server, database layer, or routing backend code shown. Any persisted auth, user data, or notifications are expected to come from the external API layer through the service modules.

12. For an architecture diagram, the clearest boundaries are: app bootstrap, auth/token management, API integration, game presentation layer, level/exercise logic, and responsive view variants. The main data flow is user interaction -> page/component state -> validation or API call -> token/user/notification state update -> navigation or feedback modal.

Main entry points: [`src/App.tsx`](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/App.tsx) (App), [`src/pages/Games/Level1`](https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/pages/Games/Level1) (Level 1), [`src/pages/Games/Nivel2`](https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/pages/Games/Nivel2) (Level 2), [`src/pages/users/Login.tsx`](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/Login.tsx) (Login)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_bootstrap["Bootstrap"]
  node_node_main["main<br/>Vite entry<br/>[main.tsx]"]
  node_node_app["App<br/>Shell<br/>[App.tsx]"]
end

subgraph group_group_auth["Access"]
  node_node_token_context["Token state<br/>Context<br/>[TokenContext.tsx]"]
  node_node_token_provider["Token provider<br/>[TokenProvider.tsx]"]
  node_node_auth_service["Auth service<br/>[authService.ts]"]
  node_node_login["Login<br/>Page<br/>[Login.tsx]"]
  node_node_signup["Sign up<br/>Page<br/>[SignUp.tsx]"]
  node_node_avatars["Avatars<br/>User data<br/>[avatars.ts]"]
  node_node_usuario_api["User API<br/>API client<br/>[usuarioApi.ts]"]
  node_node_notif_api["Notify API<br/>API client<br/>[notificacionApi.ts]"]
  node_node_auth_redirect["Auth guard<br/>Hook<br/>[useAuthRedirect.ts]"]
  node_node_logout_hook["Logout hook<br/>[useCerrarSesion.ts]"]
end

subgraph group_group_game["Game flows"]
  node_node_presentation["Presentation<br/>Game entry<br/>[Dashboard.tsx]"]
  node_node_explication_modal["Intro modal"]
  node_node_level1["Level 1<br/>Exercise set"]
  node_node_level2["Level 2<br/>Exercise set"]
end

subgraph group_group_ui["Shared UI"]
  node_node_screen_hook["Screen hook"]
  node_node_exercises_data["Exercises data<br/>Shared data<br/>[ejercicios.ts]"]
  node_node_styles["Styles<br/>CSS system"]
end

node_node_main -->|"boots"| node_node_app
node_node_app -->|"wraps"| node_node_token_provider
node_node_token_provider -->|"supplies"| node_node_token_context
node_node_app -->|"guards"| node_node_auth_redirect
node_node_app -->|"routes to"| node_node_login
node_node_app -->|"routes to"| node_node_signup
node_node_login -->|"authenticates"| node_node_auth_service
node_node_signup -->|"creates user"| node_node_usuario_api
node_node_login -->|"loads user"| node_node_usuario_api
node_node_signup -->|"chooses"| node_node_avatars
node_node_auth_service -->|"updates"| node_node_token_context
node_node_logout_hook -->|"clears"| node_node_token_context
node_node_presentation -->|"opens"| node_node_explication_modal
node_node_presentation -->|"enters"| node_node_level1
node_node_presentation -->|"enters"| node_node_level2
node_node_level1 -->|"adapts"| node_node_screen_hook
node_node_level2 -->|"adapts"| node_node_screen_hook
node_node_level1 -->|"uses"| node_node_exercises_data
node_node_level2 -->|"uses"| node_node_exercises_data
node_node_level1 -->|"styled by"| node_node_styles
node_node_level2 -->|"styled by"| node_node_styles
node_node_login -->|"alerts"| node_node_notif_api
node_node_level1 -->|"reports"| node_node_notif_api
node_node_level2 -->|"reports"| node_node_notif_api

click node_node_main "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/main.tsx"
click node_node_app "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/App.tsx"
click node_node_token_context "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/Context/TokenContext.tsx"
click node_node_token_provider "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/Context/TokenProvider.tsx"
click node_node_auth_service "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/Services/authService.ts"
click node_node_login "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/Login.tsx"
click node_node_signup "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/SignUp.tsx"
click node_node_avatars "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/avatars.ts"
click node_node_usuario_api "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/api/usuarioApi.ts"
click node_node_notif_api "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/api/notificacionApi.ts"
click node_node_auth_redirect "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/hooks/useAuthRedirect.ts"
click node_node_logout_hook "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/hooks/useCerrarSesion.ts"
click node_node_presentation "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/Games/Presentation/Dashboard.tsx"
click node_node_explication_modal "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/Games/Presentation/ExplicationModal.tsx"
click node_node_level1 "https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/pages/Games/Level1"
click node_node_level2 "https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/pages/Games/Nivel2"
click node_node_screen_hook "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/hooks/useVerificarTamañoPantalla.ts"
click node_node_exercises_data "https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/data/ejercicios.ts"
click node_node_styles "https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/assets/styles"

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_node_main,node_node_app toneBlue
class node_node_token_context,node_node_token_provider,node_node_auth_service,node_node_login,node_node_signup,node_node_avatars,node_node_usuario_api,node_node_notif_api,node_node_auth_redirect,node_node_logout_hook toneAmber
class node_node_presentation,node_node_explication_modal,node_node_level1,node_node_level2 toneMint
class node_node_screen_hook,node_node_exercises_data,node_node_styles toneRose
```

## Components

### Bootstrap

Vite entry and app shell

- [main](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/main.tsx): Vite entry · Application bootstrap and React mount point · `src/main.tsx`
- [App](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/App.tsx): Shell · Top-level application composition and routing · `src/App.tsx`

### Access

Token state, auth flows, and user entry

- [Token state](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/Context/TokenContext.tsx): Context · Access-token state shared across the app · `src/Context/TokenContext.tsx`
- [Token provider](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/Context/TokenProvider.tsx): Provider · Context provider wiring token state into the tree · `src/Context/TokenProvider.tsx`
- [Auth service](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/Services/authService.ts): Service · Centralized authentication logic · `src/Services/authService.ts`
- [Login](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/Login.tsx): Page · User sign-in screen · `src/pages/users/Login.tsx`
- [Sign up](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/SignUp.tsx): Page · User registration screen · `src/pages/users/SignUp.tsx`
- [Avatars](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/users/avatars.ts): User data · Avatar selection and profile options · `src/pages/users/avatars.ts`
- [User API](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/api/usuarioApi.ts): API client · Backend boundary for user data and profile operations · `src/api/usuarioApi.ts`
- [Notify API](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/api/notificacionApi.ts): API client · Backend boundary for notifications and alerts · `src/api/notificacionApi.ts`
- [Auth guard](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/hooks/useAuthRedirect.ts): Hook · Login gating and protected navigation · `src/hooks/useAuthRedirect.ts`
- [Logout hook](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/hooks/useCerrarSesion.ts): Hook · Logout behavior and session clearing · `src/hooks/useCerrarSesion.ts`

### Game flows

Presentation and level exercises

- [Presentation](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/Games/Presentation/Dashboard.tsx): Game entry · Dashboard and modal-based onboarding for the game area · `src/pages/Games/Presentation/Dashboard.tsx`
- [Intro modal](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/pages/Games/Presentation/ExplicationModal.tsx): Modal · Primary explanation dialog for the game flow · `src/pages/Games/Presentation/ExplicationModal.tsx`
- [Level 1](https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/pages/Games/Level1): Exercise set · First exercise track with desktop and phone variants · `src/pages/Games/Level1`
- [Level 2](https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/pages/Games/Nivel2): Exercise set · Second exercise track with desktop and phone variants · `src/pages/Games/Nivel2`

### Shared UI

Responsive selection, data, and assets

- [Screen hook](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/hooks/useVerificarTamañoPantalla.ts): Hook · Responsive breakpoint selection for device-specific trees · `src/hooks/useVerificarTamañoPantalla.ts`
- [Exercises data](https://github.com/andresbrav/pg-frontend-ts-/blob/main/src/data/ejercicios.ts): Shared data · Common exercise content used by the game flows · `src/data/ejercicios.ts`
- [Styles](https://github.com/andresbrav/pg-frontend-ts-/tree/main/src/assets/styles): CSS system · Feature-scoped styling for users, dashboard, games, modals, and alerts · `src/assets/styles`

## Connections

- main → App: boots · Mounts the application shell
- App → Token provider: wraps · Provides token context to the routed UI
- Token provider → Token state: supplies · Implements shared token state
- App → Auth guard: guards · Protects authenticated journeys
- App → Login: routes to · Entry point for sign-in
- App → Sign up: routes to · Entry point for registration
- Login → Auth service: authenticates · Uses centralized auth logic
- Sign up → User API: creates user · Persists new user data through backend API
- Login → User API: loads user · Fetches account-related backend data
- Sign up → Avatars: chooses · Includes avatar selection in onboarding
- Auth service → Token state: updates · Stores and clears access token state
- Logout hook → Token state: clears · Ends the active session
- Presentation → Intro modal: opens · Shows onboarding and explanations before play
- Presentation → Level 1: enters · Navigates into the first exercise track
- Presentation → Level 2: enters · Navigates into the second exercise track
- Level 1 → Screen hook: adapts · Selects mobile or desktop presentation
- Level 2 → Screen hook: adapts · Selects mobile or desktop presentation
- Level 1 → Exercises data: uses · Consumes shared exercise content
- Level 2 → Exercises data: uses · Consumes shared exercise content
- Level 1 → Styles: styled by · Uses scoped game and modal CSS
- Level 2 → Styles: styled by · Uses scoped game and modal CSS
- Login → Notify API: alerts · Can surface notification-backed feedback
- Level 1 → Notify API: reports · May write progress or feedback notifications
- Level 2 → Notify API: reports · May write progress or feedback notifications
