# ccp-g18/misw4502-proyecto-final2-frontend-web architecture

> Architecture diagram of the GitHub repository ccp-g18/misw4502-proyecto-final2-frontend-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ccp-g18/misw4502-proyecto-final2-frontend-web
- Repository: https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web

## Overview

##### Project type and purpose
- This is a single-page application (SPA) built with React and Vite.
- It is purely a front-end client that consumes external REST APIs (auth, products, sellers, etc.).
- Infrastructure is managed via Terraform (main.tf), and the app is containerized (Dockerfile) and deployed to Google Cloud (gcloudignore, nginx.conf).

##### File structure
- Top-level files:
- .github/workflows/*.yml → CI/CD pipelines (build, test, deploy)
- main.tf → Terraform configuration for provisioning cloud resources
- Dockerfile + app/nginx.conf → container definition and server config
- “app/” directory:
- package.json, pnpm-lock.yaml, vite.config.js → build & dependency management
- src/ → React source code
– api/ → modules for calling external services
– components/, layouts/, pages/, routes/ → UI structure following a component-based (and some Router-based) pattern
– context/ → React Context for auth and notifications
– tests/ → unit & integration tests
- Public/assets and index.html → static assets and the SPA entry point

##### README for additional insights
- Confirms use of React + Vite with HMR and ESLint
- References how to extend linting and adopt TypeScript (optional future step)

a. Main components
1. Developer workstation (IDE, Git)
2. GitHub repository & Actions (CI/CD)
3. Terraform orchestrator (main.tf)
4. Container registry (e.g. GCR)
5. Google Cloud deployment (Cloud Run / GCS + Nginx)
6. Browser (user) running React SPA
7. External REST API services (Auth, Products, Sellers, etc.)
b. Relationships & interactions
- Developer pushes code → GitHub Actions triggers CI (install, lint, test) → build Docker image → push to registry
- CD pipeline: Terraform applies infrastructure → deploys container to Cloud Run (or GCS + Nginx)
- Browser fetches static bundle from the container’s Nginx server
- SPA issues HTTP requests to external APIs (auth.js, products.js, etc.)
c. Architectural patterns & design principles
- Component-based UI (React)
- Separation of concerns: API layer (src/api), state management (contexts), presentation (components/pages)
- Infrastructure as Code (Terraform)
- CI/CD pipeline for automated testing and deployment
d. Key technologies/frameworks
- React + Vite (build tool, HMR)
- ESLint (code quality)
- pnpm (package manager)
- Docker + Nginx (containerized web server)
- Terraform (IaC)
- GitHub Actions (CI/CD)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer and Repo
    Dev["Developer"]:::blue
    Repo["GitHub Repo"]:::blue
    Dev -->|"git push / webhook"| Repo

    %% CI/CD Pipelines
    subgraph "CI/CD Pipeline"
        CI["GitHub Actions CI"]:::blue
        CD["GitHub Actions CD"]:::blue
    end
    Repo -->|"trigger CI"| CI
    CI -->|"build & test"| CD
    click CI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/.github/workflows/main-ci.yml"
    click CD "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/.github/workflows/main-cd.yml"

    %% Infrastructure
    subgraph "Infrastructure (IaC & Registry)"
        TF["Terraform (main.tf)"]:::green
        Registry["Container Registry"]:::green
    end
    CD -->|"terraform apply"| TF
    CD -->|"docker build/push"| Registry
    click TF "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/main.tf"

    %% Deployment
    subgraph "Cloud Deployment"
        CloudRun["Cloud Run (Nginx)"]:::green
    end
    TF -->|"provision infra"| CloudRun
    Registry -->|"deploy image"| CloudRun

    %% SPA Source Code
    subgraph "SPA Source Code"
        subgraph Configurations
            Vite["vite.config.js"]:::blue
            Pkg["package.json"]:::blue
            Lock["pnpm-lock.yaml"]:::blue
            ESLint["eslint.config.js"]:::blue
        end
        subgraph Docker
            Dockerfile["Dockerfile"]:::blue
            NginxConf["nginx.conf"]:::blue
            GcloudIgnore[".gcloudignore"]:::blue
        end
        subgraph Public
            IndexHTML["index.html"]:::blue
            Assets["public assets"]:::blue
        end
        subgraph Source["src"]
            subgraph API_Layer
                AuthAPI["auth.js"]:::blue
                ProductsAPI["products.js"]:::blue
                SellersAPI["sellers.js"]:::blue
                CategoriesAPI["categories.js"]:::blue
                CountriesAPI["countries.js"]:::blue
                GoogleMapsAPI["googleMaps.js"]:::blue
                ProducersAPI["producers.js"]:::blue
                WarehousesAPI["warehouses.js"]:::blue
            end
            subgraph Components
                Breadcrumb["Breadcrumb.jsx"]:::blue
                Footer["Footer.jsx"]:::blue
                Loader["Loader.jsx"]:::blue
                Sidebar["Sidebar.jsx"]:::blue
                Topbar["Topbar.jsx"]:::blue
            end
            subgraph Layouts
                AuthLayout["AuthLayout.jsx"]:::blue
                MainLayout["MainLayout.jsx"]:::blue
            end
            subgraph Pages
                Pages["*.jsx (pages)"]:::blue
            end
            subgraph Routes
                AppRoutes["AppRoutes.jsx"]:::blue
                PrivateRoute["PrivateRoute.jsx"]:::blue
            end
            subgraph Contexts
                AuthCtx["AuthContext.jsx"]:::blue
                NotifCtx["NotificationContext.jsx"]:::blue
            end
            subgraph Utils
                Formatters["formatters.js"]:::blue
            end
            subgraph Styles
                Styles["index.css"]:::blue
            end
            subgraph Tests
                Tests["*.test.jsx"]:::blue
            end
            MainJS["main.jsx"]:::blue
            AppJS["App.jsx"]:::blue
        end
    end

    %% Click events for SPA mappings
    click Vite "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/vite.config.js"
    click Pkg "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/package.json"
    click Lock "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/pnpm-lock.yaml"
    click ESLint "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/eslint.config.js"
    click Dockerfile "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/tree/main/app/Dockerfile"
    click NginxConf "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/nginx.conf"
    click GcloudIgnore "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/.gcloudignore"
    click IndexHTML "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/index.html"
    click MainJS "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/main.jsx"
    click AppJS "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/App.jsx"
    click AuthAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/auth.js"
    click ProductsAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/products.js"
    click SellersAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/sellers.js"
    click CategoriesAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/categories.js"
    click CountriesAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/countries.js"
    click GoogleMapsAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/googleMaps.js"
    click ProducersAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/producers.js"
    click WarehousesAPI "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/api/warehouses.js"
    click Breadcrumb "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/components/Breadcrumb.jsx"
    click Footer "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/components/Footer.jsx"
    click Loader "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/components/Loader.jsx"
    click Sidebar "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/components/Sidebar.jsx"
    click Topbar "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/components/Topbar.jsx"
    click AuthLayout "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/layouts/AuthLayout.jsx"
    click MainLayout "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/layouts/MainLayout.jsx"
    click Pages "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/tree/main/app/src/pages"
    click AppRoutes "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/routes/AppRoutes.jsx"
    click PrivateRoute "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/routes/PrivateRoute.jsx"
    click AuthCtx "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/context/AuthContext.jsx"
    click NotifCtx "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/context/NotificationContext.jsx"
    click Styles "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/styles/index.css"
    click Formatters "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/blob/main/app/src/utils/formatters.js"
    click Tests "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/tree/main/app/src/tests"
    click Assets "https://github.com/ccp-g18/misw4502-proyecto-final2-frontend-web/tree/main/app/public"

    %% Runtime and External
    Browser["Browser (React SPA)"]:::orange
    External["External REST APIs"]:::gray

    CloudRun -->|"serve static bundle (HTTP)"| Browser
    Browser -->|"HTTP GET/POST"| External
    Browser -->|"loads bundle"| IndexHTML
    MainJS -->|"mount App"| AppJS

    %% Styles
    classDef blue fill:#D0E8FF,stroke:#0288D1,stroke-width:1px
    classDef green fill:#DFF2BF,stroke:#4CAF50,stroke-width:1px
    classDef orange fill:#FFE0B2,stroke:#FB8C00,stroke-width:1px
    classDef gray fill:#E0E0E0,stroke:#9E9E9E,stroke-width:1px
```
