# queirozcarlos/shopsync-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/queirozcarlos/shopsync-frontend
- Repository: https://github.com/queirozcarlos/shopsync-frontend

## Overview

##### Project type and purpose
- Type: Full-stack web application (specifically the frontend service) in a larger inventory-management system.
- Purpose: A responsive SPA to manage products, sales, customers, suppliers, categories, reports and authentication, styled with Tailwind.

##### Main components
A. Developer / CI Environment (optional layer)
- Source files (src/)
- Configs: .env, tsconfig*, eslint.config.js, tailwind.config.js, vite.config.ts
- Build tools: Node 18+, npm/yarn, Vite
B. Docker-Compose services
1. frontend
- Dockerfile: builds the React app via Vite, then serves static assets through Nginx
- nginx.conf: config for static serving and proxy to backend API
2. backend (external service)
- Placeholder for your API service (e.g., Java/Spring, Node/Express) on port 8080
3. database
- MySQL container with migrations under src/database
C. Runtime / Production stack
1. Browser (end-user) – loads SPA via HTTP(S) from Nginx
2. Nginx (frontend container) – serves index.html, JS/CSS bundles, proxies API calls to backend
3. React SPA (client)
- Pages: Home, Dashboard, Sales, Reports, ...
- Components: Sidebar, Modals, List, ProtectedRoute, ChatbotButton, etc.
- Contexts: AuthContext (JWT management, ProtectedRoute), ThemeContext (light/dark persistence)
- Services (API layer): axios instance + productService, salesService, suppliersService
- Data flow: user actions → React components → services → backend
4. Backend API – REST endpoints for products, sales, customers, suppliers, categories, reports
5. MySQL – persistence layer, migrations located in src/database/migrations

##### Relationships & interactions
- Browser →(HTTP GET)→ Nginx (port 80/443)
- Nginx → serves JS/CSS → Browser
- Browser (SPA) →(Axios HTTP calls)→ Nginx proxy → Backend API (port 8080)
- Backend API →(SQL queries)→ MySQL
- React Context persists JWT & theme in localStorage
- Docker-Compose network allows name-based service discovery (e.g., http://backend:8080)

##### Architectural patterns & design principles
- Single-Page Application (SPA) architecture
- Component-based UI (React) with reusable components & modals
- Context API for global state (auth + theme) instead of Redux
- Service layer abstracts HTTP + domain logic
- Environment-driven config (VITE_API_BASE_URL)
- Containerization: Build once, run anywhere (Docker + Nginx)
- Orchestration: docker-compose ties frontend, backend, DB

##### Technologies & frameworks
- React 18 + TypeScript + Vite (dev server & build)
- Tailwind CSS + PostCSS + Headless UI + Lucide React (UI)
- React Router DOM (routing + ProtectedRoute)
- Axios (HTTP client)
- Docker & Docker-Compose (containerization)
- Nginx (static asset server & reverse proxy)
- MySQL (database)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Developer/CI Environment"
        DevSrc["src/"]:::dev
        TsConfig["tsconfig.json, tsconfig.app.json, tsconfig.node.json"]:::dev
        ESLint["eslint.config.js"]:::dev
        Tailwind["tailwind.config.js, postcss.config.js"]:::dev
        ViteConfig["vite.config.ts"]:::dev
        EnvFiles[".env, src/.env"]:::dev
    end

    subgraph "Docker-Compose Services"
        FrontendService["Frontend Service"]:::compose
        BackendService["Backend Service"]:::compose
        DatabaseService["Database Service"]:::compose
        DockerfileNode["Dockerfile"]:::compose
        NginxConf["nginx.conf"]:::compose
        ComposeYml["docker-compose.yml"]:::compose
        Dockerignore[".dockerignore"]:::compose
    end

    subgraph "Runtime Production Stack"
        Browser["Browser (HTTP 80/443)"]:::runtime
        Nginx["Nginx (80/443)"]:::runtime
        subgraph "React SPA (Client)"
            EntryMain["src/main.tsx"]:::runtime
            EntryApp["src/App.tsx"]:::runtime
            GlobalStyles["src/index.css"]:::runtime
            Pages["Pages (src/pages/)"]:::runtime
            Components["Components (src/components/)"]:::runtime
            Contexts["Contexts (src/contexts/)"]:::runtime
            Services["Services (src/services/)"]:::runtime
            EnvFilesSPA[".env, src/.env"]:::runtime
        end
        BackendAPI["Backend API (8080)"]:::runtime
        MySQL["MySQL (3306)"]:::db
        Migrations["Migrations (src/database/migrations/)"]:::db
    end

    %% Developer/CI -> Compose build
    DevSrc -->|uses| FrontendService
    TsConfig -->|configures| FrontendService
    ESLint -->|lint rules| FrontendService
    Tailwind -->|styles| FrontendService
    ViteConfig -->|build tool| FrontendService
    EnvFiles -->|env configs| FrontendService

    %% Docker-Compose files to services
    DockerfileNode -->|builds image| FrontendService
    NginxConf -->|serves/proxies| FrontendService
    ComposeYml -->|defines services| FrontendService
    ComposeYml -->|defines services| BackendService
    ComposeYml -->|defines services| DatabaseService
    Dockerignore -.->|ignore patterns| FrontendService

    %% Runtime interactions
    Browser -->|"HTTP GET"| Nginx
    Nginx -->|"Serves JS/CSS"| Browser
    Browser -->|"API Calls (Axios)"| Nginx
    Nginx -->|"Proxy to API"| BackendAPI
    BackendAPI -->|"SQL Queries"| MySQL

    %% React SPA internal flow
    EntryMain -->|renders| EntryApp
    EntryApp -->|routes to| Pages
    EntryApp -->|loads| Components
    EntryApp -->|provides| Contexts
    EntryApp -->|initializes| Services
    Pages -->|uses| Components
    Components -->|calls| Services
    Services -->|"HTTP via VITE_API_BASE_URL"| Nginx
    Contexts -->|injects state| Components
    EnvFilesSPA -.->|config| EntryMain

    %% Compose to runtime mapping
    FrontendService -->|runs Nginx| Nginx
    BackendService -->|runs API| BackendAPI
    DatabaseService -->|runs MySQL| MySQL
    DatabaseService -->|runs migrations| Migrations

    %% Click Events
    click DevSrc "https://github.com/queirozcarlos/shopsync-frontend/tree/main/src/"
    click TsConfig "https://github.com/queirozcarlos/shopsync-frontend/blob/main/tsconfig.json"
    click ESLint "https://github.com/queirozcarlos/shopsync-frontend/blob/main/eslint.config.js"
    click Tailwind "https://github.com/queirozcarlos/shopsync-frontend/blob/main/tailwind.config.js"
    click ViteConfig "https://github.com/queirozcarlos/shopsync-frontend/blob/main/vite.config.ts"
    click EnvFiles "https://github.com/queirozcarlos/shopsync-frontend/blob/main/.env"
    click DockerfileNode "https://github.com/queirozcarlos/shopsync-frontend/tree/main/Dockerfile"
    click NginxConf "https://github.com/queirozcarlos/shopsync-frontend/blob/main/nginx.conf"
    click ComposeYml "https://github.com/queirozcarlos/shopsync-frontend/blob/main/docker-compose.yml"
    click Dockerignore "https://github.com/queirozcarlos/shopsync-frontend/blob/main/.dockerignore"
    click EntryMain "https://github.com/queirozcarlos/shopsync-frontend/blob/main/src/main.tsx"
    click EntryApp "https://github.com/queirozcarlos/shopsync-frontend/blob/main/src/App.tsx"
    click GlobalStyles "https://github.com/queirozcarlos/shopsync-frontend/blob/main/src/index.css"
    click Pages "https://github.com/queirozcarlos/shopsync-frontend/tree/main/src/pages/"
    click Components "https://github.com/queirozcarlos/shopsync-frontend/tree/main/src/components/"
    click Contexts "https://github.com/queirozcarlos/shopsync-frontend/tree/main/src/contexts/"
    click Services "https://github.com/queirozcarlos/shopsync-frontend/tree/main/src/services/"
    click Migrations "https://github.com/queirozcarlos/shopsync-frontend/tree/main/src/database/migrations/"

    %% Styles
    classDef dev fill:#f9f,stroke:#333,stroke-width:1px;
    classDef compose fill:#bbf,stroke:#333,stroke-width:1px;
    classDef runtime fill:#bfb,stroke:#333,stroke-width:1px;
    classDef db fill:#fbf,stroke:#333,stroke-width:1px;
```
