# ryan-menezes/loja-virtual architecture

> Architecture diagram of the GitHub repository ryan-menezes/loja-virtual, 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/ryan-menezes/loja-virtual
- Repository: https://github.com/ryan-menezes/loja-virtual

## Overview

##### Project type and purpose
- This is a monolithic, full-stack PHP e-commerce web application (“Loja Virtual”) built on a custom lightweight MVC framework.
- It provides a public shopping site, an administration panel, database persistence, file storage, and integrates with external shipping (Correios) and payment gateways (MercadoPago, PagSeguro, PicPay).

##### File structure
- Top‐level “public/” serves static assets (CSS, JS, images) and routes all requests through “public/index.php.”
- “routes/web.php” defines URL → controller mappings.
- “src/Classes” houses framework core (Router, Request, Controller, View, Database, Session, Mail, Validator, Storage, etc.).
- “app/Controllers” separates admin (Panel) and public (Site) controllers.
- “app/Models” represents database entities (Product, Category, User, Request, etc.).
- “app/Classes” contains domain services (Cart, shipping under Correios, payment gateway wrappers).
- “app/Middlewares” handles cross-cutting concerns (auth, maintenance, LGPD).
- “config/” holds environment and service configurations.
- “resource/views” contains Blade-style templates for public site, admin panel, emails, and components.
- “storage/” persists user‐uploaded files (banners, products, policies) and local database dumps.
- Node and Webpack config build front-end assets under “public/assets.”

##### Review README for additional insights
- Requires Composer + NPM.
- Uses a blade-like templating system; assets must be rebuilt via npm scripts.
- External integrations (PagSeguro, MercadoPago, PicPay) are disabled by default and configured via admin panel.

##### Main components and interactions
a. Web & Static Asset Layer (public/)
- Web server (Apache/Nginx) → serves static files (CSS/JS/images) and forwards dynamic requests to index.php
b. HTTP Routing & Framework Core (src/Classes + routes/web.php)
- Request enters Router → dispatched to Middleware chain → Controller
c. Controllers (app/Controllers)
- “Site” controllers for public pages and checkout.
- “Panel” controllers for admin dashboard and configuration.
d. Business Logic & Services
- Cart service, shipping calculators (Correios classes), payment service wrappers (Pago, MercadoPago, PicPay)
e. Models & Database (app/Models + config/database.php)
- ORM/Active-Record or simple Query Builder → MySQL/PostgreSQL
f. Templating & Views (resource/views)
- Controllers pass data to Blade templates for HTML rendering.
g. File Storage (storage/app/public)
- Uploaded images/documents managed by Storage/File class and publicly accessible via symbolic link or web server alias
h. External Services
- Correios API (via FreteWsCorreios)
- Payment gateways (pagseguro, mercadopago, picpay) via REST/SDK calls

##### Architectural patterns & design principles
- MVC (Model-View-Controller) layered architecture
- Single-entry point / Front Controller in public/index.php
- Dependency injection limited – services instantiated in controllers or factory classes under app/Classes
- Middlewares for cross-cutting concerns (Authentication, Maintenance mode, LGPD compliance)
- Service wrappers for external APIs isolate HTTP logic

##### Elements
- Configuration store (config files) indicating where credentials and environment settings live
- Build step: npm/webpack compiles assets into public/assets

- Confirm MVC layers are distinct and labeled
- Services (shipping, payment) as dedicated components
- Middleware chain before controllers
- Where templating fits (Controllers → View → HTML)
- Differentiate internal data stores vs. external APIs
- Critical interactions for clarity (e.g., “Session start,” “CSRF check,” “ORM save”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        WebServer["Web Server (Apache/Nginx)"]:::presentation
        StaticAssets["Static Assets<br/>(CSS/JS/Images)"]:::presentation
        FrontController["Front Controller<br/>(public/index.php)"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FrameworkCore["Framework Core<br/>(src/Classes)"]:::core
        Routes["HTTP Routing<br/>(routes/web.php)"]:::core
        MiddlewareChain["Middleware Chain<br/>(app/Middlewares)"]:::middleware
        subgraph "Controllers"
            direction TB
            SiteControllers["Site Controllers<br/>(app/Controllers/Site)"]:::controller
            PanelControllers["Panel Controllers<br/>(app/Controllers/Panel)"]:::controller
        end
        Bootstrap["Application Bootstrap<br/>(core/bootstrap.php)"]:::core
        CoreConfig["Core Config<br/>(core/config.php)"]:::core
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        CartService["Cart Service<br/>(app/Classes/Cart.php)"]:::service
        ShippingServices["Shipping Services<br/>(app/Classes/Correios/Frete)"]:::service
        PaymentGateways["Payment Gateways<br/>(app/Classes/Payment)"]:::service
        Models["Models & Entities<br/>(app/Models)"]:::model
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DBConfig["Database Config<br/>(config/database.php)"]:::config
        Database["Database (MySQL/PostgreSQL)"]:::database
        StorageAbstraction["Storage Abstraction<br/>(src/Classes/Storage)"]:::core
        FileStorage["File Storage<br/>(storage/app/public)"]:::storage
    end

    %% Templating Layer
    subgraph "Templating & Views"
        direction TB
        Views["Blade Templates<br/>(resource/views)"]:::view
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CorreiosAPI["Correios API"]:::external
        MercadoPagoAPI["MercadoPago"]:::external
        PagSeguroAPI["PagSeguro"]:::external
        PicPayAPI["PicPay"]:::external
    end

    %% Data Flows
    WebServer -->|serves static| StaticAssets
    WebServer -->|forwards HTTP| FrontController
    FrontController -->|loads| Bootstrap
    FrontController -->|loads| CoreConfig
    FrontController -->|dispatches| FrameworkCore
    FrameworkCore -->|uses| Routes
    FrameworkCore -->|handles| MiddlewareChain
    Routes -->|routes to| SiteControllers
    Routes -->|routes to| PanelControllers
    MiddlewareChain -->|pre-process| SiteControllers
    MiddlewareChain -->|pre-process| PanelControllers
    SiteControllers -->|uses| CartService
    SiteControllers -->|uses| ShippingServices
    SiteControllers -->|uses| PaymentGateways
    PanelControllers -->|uses| PaymentGateways
    SiteControllers -->|accesses| Models
    PanelControllers -->|accesses| Models
    CartService -->|reads/writes| Models
    ShippingServices -->|REST API call| CorreiosAPI
    PaymentGateways -->|REST SDK| MercadoPagoAPI
    PaymentGateways -->|REST SDK| PagSeguroAPI
    PaymentGateways -->|REST SDK| PicPayAPI
    Models -->|SQL query| Database
    DBConfig -->|configures| Database
    FileStorage -->|stores files| StorageAbstraction
    SiteControllers -->|renders| Views
    PanelControllers -->|renders| Views
    Views -->|HTML response| WebServer

    %% Click Events
    click WebServer "https://github.com/ryan-menezes/loja-virtual/tree/main/public/"
    click FrontController "https://github.com/ryan-menezes/loja-virtual/blob/main/public/index.php"
    click Routes "https://github.com/ryan-menezes/loja-virtual/blob/main/routes/web.php"
    click FrameworkCore "https://github.com/ryan-menezes/loja-virtual/tree/main/src/Classes"
    click SiteControllers "https://github.com/ryan-menezes/loja-virtual/tree/main/app/Controllers/Site"
    click PanelControllers "https://github.com/ryan-menezes/loja-virtual/tree/main/app/Controllers/Panel"
    click CartService "https://github.com/ryan-menezes/loja-virtual/blob/main/app/Classes/Cart.php"
    click ShippingServices "https://github.com/ryan-menezes/loja-virtual/tree/main/app/Classes/Correios/Frete"
    click PaymentGateways "https://github.com/ryan-menezes/loja-virtual/tree/main/app/Classes/Payment"
    click Models "https://github.com/ryan-menezes/loja-virtual/tree/main/app/Models"
    click DBConfig "https://github.com/ryan-menezes/loja-virtual/blob/main/config/database.php"
    click StorageAbstraction "https://github.com/ryan-menezes/loja-virtual/tree/main/src/Classes/Storage"
    click FileStorage "https://github.com/ryan-menezes/loja-virtual/tree/main/storage/app/public"
    click Views "https://github.com/ryan-menezes/loja-virtual/tree/main/resource/views"

    %% Styles
    classDef presentation fill:#f2f2f2,stroke:#999,stroke-width:1px;
    classDef core fill:#e6f7ff,stroke:#3299ff,stroke-width:1px;
    classDef middleware fill:#fff4e6,stroke:#ffa940,stroke-width:1px;
    classDef controller fill:#e6ffe6,stroke:#52c41a,stroke-width:1px;
    classDef service fill:#fff0f6,stroke:#f759ab,stroke-width:1px;
    classDef model fill:#f9f0ff,stroke:#9254de,stroke-width:1px;
    classDef database fill:#d9f7be,stroke:#389e0d,stroke-width:1px,stroke-dasharray: 5, 5;
    classDef storage fill:#fff7e6,stroke:#d46b08,stroke-width:1px;
    classDef config fill:#fffbe6,stroke:#faad14,stroke-width:1px;
    classDef view fill:#e6fffb,stroke:#13c2c2,stroke-width:1px;
    classDef external fill:#fff1f0,stroke:#cf1322,stroke-width:1px,stroke-dasharray: 5, 5;
```
