# samuel-cruz/desafio-front architecture

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

- Interactive diagram: https://gitdiagram.com/samuel-cruz/desafio-front
- Repository: https://github.com/samuel-cruz/desafio-front

## Overview

##### Project type and purpose
- This is a front-end only, single-page application (SPA) built with JavaScript, jQuery, Materialize CSS, and bundled by webpack.
- Its purpose is to authenticate a user, display a paginated grid of “people” from an external REST API (two versions: v1 or v2), and allow create/update/delete operations via a modal dialog.

##### File structure
- Top-level config and metadata:
- package.json / package-lock.json – npm metadata and scripts (npm start → webpack-dev-server on localhost:3340)
- webpack.config.js – defines entry point (src/main.js), loaders, output and dev-server.
- public/index.html – the HTML shell loaded into the browser.
- Source code (src):
- src/main.js – application bootstrap: imports styles, initializes routing or page mounting.
- src/pages/login – Login page view and styles.
- src/pages/home – Home page view, which includes the Grid and controls (version flag).
- src/components/table – Presentational Table component to show the list of people.
- src/components/modal – Create/update/delete modal dialog component.
- src/utils/alert.js – Utility for showing user alerts.
- No backend code – it consumes an existing remote API (https://desafio-meta-back.herokuapp.com).

##### README for additional insights
- It confirms login credentials, grid features, version-flag behavior (v1 optional address, v2 requires address).
- Technologies and how to run locally.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure Layer
    Browser["Browser (User)"]:::infrastructure
    PackageJSON["package.json"]:::infrastructure
    WebpackConfig["webpack.config.js"]:::infrastructure
    DevServer["Webpack Dev Server"]:::infrastructure
    IndexHTML["public/index.html"]:::infrastructure

    %% Build Pipeline
    PackageJSON -->|"npm start"| WebpackConfig
    WebpackConfig -->|"bundles"| Bundle

    %% Serving Assets
    Browser -->|"HTTP GET index.html & assets"| DevServer
    DevServer -->|"serves index.html"| IndexHTML
    DevServer -->|"serves bundle"| Bundle
    IndexHTML --> Bundle

    %% Application Bundle
    subgraph "App Bundle" 
        direction TB
        Bundle["Bundled JS/CSS"]:::bundle
        Main["src/main.js"]:::bundle
        APIService["API Service Layer\n(v1/v2 logic)"]:::service
        AlertUtil["alert.js"]:::service
    end

    Bundle --> Main
    Main -->|boots SPA| LoginPage
    Main -->|on successful login| HomePage
    APIService --> AlertUtil

    %% UI Components
    subgraph "UI Components"
        direction TB
        LoginPage["Login Page"]:::ui
        LoginStyle["Login Styles"]:::ui
        HomePage["Home Page"]:::ui
        HomeStyle["Home Styles"]:::ui
        Table["Table Component"]:::ui
        Modal["Modal Component"]:::ui
    end

    Main --> LoginPage
    LoginPage --> LoginStyle
    Main --> HomePage
    HomePage --> HomeStyle
    HomePage --> Table
    HomePage --> Modal

    %% User Actions and API Calls
    Table -->|AJAX GET people| APIService
    Modal -->|AJAX POST/PUT/DELETE| APIService

    %% Version Flag Decision
    APIService -->|if v1| V1Endpoint
    APIService -->|if v2| V2Endpoint

    subgraph "External REST API"
        direction TB
        V1Endpoint["v1 endpoint"]:::external
        V2Endpoint["v2 endpoint"]:::external
    end

    V1Endpoint -->|response| APIService
    V2Endpoint -->|response| APIService
    APIService -->|data| Table
    APIService -->|data| Modal

    %% Click Events
    click PackageJSON "https://github.com/samuel-cruz/desafio-front/blob/master/package.json"
    click WebpackConfig "https://github.com/samuel-cruz/desafio-front/blob/master/webpack.config.js"
    click IndexHTML "https://github.com/samuel-cruz/desafio-front/blob/master/public/index.html"
    click Main "https://github.com/samuel-cruz/desafio-front/blob/master/src/main.js"
    click LoginPage "https://github.com/samuel-cruz/desafio-front/blob/master/src/pages/login/index.js"
    click LoginStyle "https://github.com/samuel-cruz/desafio-front/blob/master/src/pages/login/style.css"
    click HomePage "https://github.com/samuel-cruz/desafio-front/blob/master/src/components/home/index.js"
    click HomeStyle "https://github.com/samuel-cruz/desafio-front/blob/master/src/components/home/style.css"
    click Table "https://github.com/samuel-cruz/desafio-front/blob/master/src/components/table/index.js"
    click Modal "https://github.com/samuel-cruz/desafio-front/blob/master/src/components/modal/index.js"
    click AlertUtil "https://github.com/samuel-cruz/desafio-front/blob/master/src/utils/alert.js"

    %% Styles
    classDef infrastructure fill:#e0ffe0,stroke:#2d602d,stroke-width:1px
    classDef bundle fill:#cee0ff,stroke:#1f4f91,stroke-width:1px
    classDef ui fill:#fff4b2,stroke:#a37f00,stroke-width:1px
    classDef service fill:#ffe0b3,stroke:#994d00,stroke-width:1px
    classDef external fill:#e0ffe0,stroke:#2d602d,stroke-width:1px
```
