# ivanloav/swiftshop architecture

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

- Interactive diagram: https://gitdiagram.com/ivanloav/swiftshop
- Repository: https://github.com/ivanloav/swiftshop

## Overview

##### Project Type and Purpose
- Full-stack e-commerce dashboard application (“SwiftShop”)
- Frontend: React/Vite SPA for user authentication, dashboards, and CRUD on products, orders, inventory, customers, stores.
- Backend: NestJS monolith exposing a RESTful API (/api/*) with modules for auth, customers, products, orders, inventory, stores, dashboard.
- Data layer: MySQL (via TypeORM) storing users, stores, products, orders, inventory, customers.

##### File‐Structure Analysis
- Top-level:
– backend/: NestJS source (src/) + compiled output (dist/) + TypeORM entities + tsconfig
– frontend/: React/Vite source (src/) + public, config, hooks, services and component modules.
- Patterns:
– Backend: modular MVC (controllers, services, DTOs, entities) organized per domain (auth, products, orders, …).
– Frontend: component-based UI with routing (PrivateRoute), layout modules (login, main/layout, main/modules, main/ui) and custom hooks for state/side effects.
- Deployment scripts: GitHub Actions, AWS EC2 + Nginx + PM2 instructions in README.

##### Key README Insights
- JWT auth with bcrypt, token stored in localStorage, 1h expiry.
- API base path: http://…/api/
- Deployment on AWS EC2, Nginx serves static front (dist), reverse proxies /api to backend running on PM2.
- Endpoints for products, inventory, customers, orders, stores, plus a dashboard module.

##### Diagramming the Architecture
a. Main Components
– User’s Browser / SPA (React app)
– Static asset host (Nginx on EC2)
– Backend API server (NestJS on Node.js/PM2)
– Relational Database (MySQL via TypeORM)
– External services: JWT auth library, bcrypt, third-party APIs (if any in config.js)
b. Relationships and Data Flows
1. Browser requests index.html → Nginx serves React bundle.
2. React SPA (via axiosConfig/api.js) calls HTTP requests → Nginx proxy passes /api/* to Node.js backend.
3. NestJS controllers receive requests, apply guards (jwt-auth.guard), call services (business logic), TypeORM repositories interact with MySQL.
4. Responses flow back: backend → Nginx → SPA.
5. SPA stores JWT in localStorage, attaches Authorization header on subsequent API calls.
c. Architectural Patterns and Principles
– Layered architecture: Presentation (React components) → Application/API (NestJS controllers) → Business (NestJS services) → Data (TypeORM repositories/entities).
– Modular design: one module per bounded context (auth, products, orders, inventory, customers, stores, dashboard).
– Secure endpoints with JWT strategy and guards.
– CI/CD via GitHub Actions; Infrastructure: EC2 + PM2 + Nginx.
d. Relevant Technologies/Frameworks
– Frontend: React, Vite, Axios, custom Hooks, React Router (PrivateRoute).
– Backend: NestJS, TypeScript, @nestjs/config, @nestjs/typeorm, TypeORM, bcrypt, passport-jwt, mysql2.
– Infra: AWS EC2 Ubuntu, Nginx, PM2, GitHub Actions.

2. → rectangle “Nginx (EC2 Ubuntu) – serves React, proxies /api”.
– SPA → Nginx → API controllers → services → DB → back.
– Auth module → bcrypt, JWT (side-note).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External
    UserBrowser["User Browser"]:::external
    GitHubActions["GitHub Actions CI/CD"]:::ci

    %% Gateway
    Nginx["Nginx (EC2 Ubuntu)"]:::gateway

    %% Frontend Zone
    subgraph "Frontend (React/Vite SPA)" 
        direction TB
        ReactSPA["React SPA"]:::frontend
        LoginUI["Login Module"]:::frontend
        MainLayout["Main Layout"]:::frontend
        DashboardUI["Dashboard Module"]:::frontend
        CustomersUI["Clientes Module"]:::frontend
        ProductsUI["Products Module"]:::frontend
        OrdersUI["Orders Module"]:::frontend
        InventoryUI["Inventario Module"]:::frontend
        PrivateRouteComp["PrivateRoute"]:::frontend
        CardUI["UI Components (Card)"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        AxiosConfig["Axios Config"]:::frontend
        APIService["API Service"]:::frontend
        FrontendConfig["Config File"]:::frontend
        ViteConfig["Vite Config"]:::frontend
    end

    %% Backend Zone
    subgraph "Backend (NestJS API Server)" 
        direction TB
        MainTS["main.ts"]:::backend
        AppModule["App Module"]:::backend
        subgraph "Modules"
            direction TB
            AuthModule["Auth Module"]:::backend
            CustomersModule["Customers Module"]:::backend
            ProductsModule["Products Module"]:::backend
            OrdersModule["Orders Module"]:::backend
            InventoryModule["Inventory Module"]:::backend
            StoresModule["Stores Module"]:::backend
            DashboardModule["Dashboard Module"]:::backend
        end
        Entities["TypeORM Entities"]:::database
        TSConfigs["tsconfig.json / tsconfig.build.json"]:::backend
        Dist["Compiled Output (dist)"]:::backend
    end

    %% Database
    MySQL["MySQL Database"]:::database

    %% External Libraries
    Bcrypt["bcrypt / JWT"]:::external

    %% Connections
    UserBrowser -->|"HTTP GET /"| Nginx
    UserBrowser -->|"API Calls (axios)"| ReactSPA
    ReactSPA -->|"Serve \/api requests"| Nginx
    Nginx -->|"Proxy \/api to :3000"| MainTS
    MainTS -->|uses| AppModule
    AppModule -->|imports| AuthModule
    AppModule -->|imports| CustomersModule
    AppModule -->|imports| ProductsModule
    AppModule -->|imports| OrdersModule
    AppModule -->|imports| InventoryModule
    AppModule -->|imports| StoresModule
    AppModule -->|imports| DashboardModule
    AuthModule -->|"guards"| Bcrypt
    MainTS -->|runs code| Dist
    AuthModule -->|queries| Entities
    CustomersModule -->|queries| Entities
    ProductsModule -->|queries| Entities
    OrdersModule -->|queries| Entities
    InventoryModule -->|queries| Entities
    StoresModule -->|queries| Entities
    DashboardModule -->|queries| Entities
    Entities -->|storage| MySQL
    GitHubActions -->|deploy| Nginx
    GitHubActions -->|deploy| Dist
    GitHubActions -->|deploy| MySQL

    %% Frontend Flow
    ReactSPA --> LoginUI
    ReactSPA --> MainLayout
    MainLayout --> DashboardUI
    MainLayout --> CustomersUI
    MainLayout --> ProductsUI
    MainLayout --> OrdersUI
    MainLayout --> InventoryUI
    ReactSPA --> PrivateRouteComp
    ReactSPA --> CardUI
    ReactSPA --> Hooks
    ReactSPA --> AxiosConfig
    ReactSPA --> APIService
    ReactSPA --> FrontendConfig
    ReactSPA --> ViteConfig

    %% Click Events - Frontend
    click ReactSPA "https://github.com/ivanloav/swiftshop/tree/main/frontend/src"
    click LoginUI "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/login"
    click MainLayout "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/main/layout"
    click DashboardUI "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/main/modules/dashboard"
    click CustomersUI "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/main/modules/clientes"
    click ProductsUI "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/main/modules/products"
    click OrdersUI "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/main/modules/orders"
    click InventoryUI "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/components/main/modules/inventario"
    click PrivateRouteComp "https://github.com/ivanloav/swiftshop/blob/main/frontend/src/components/PrivateRoute.jsx"
    click CardUI "https://github.com/ivanloav/swiftshop/blob/main/frontend/src/components/main/ui/Card.jsx"
    click Hooks "https://github.com/ivanloav/swiftshop/tree/main/frontend/src/hooks"
    click AxiosConfig "https://github.com/ivanloav/swiftshop/blob/main/frontend/src/services/axiosConfig.js"
    click APIService "https://github.com/ivanloav/swiftshop/blob/main/frontend/src/services/api.js"
    click FrontendConfig "https://github.com/ivanloav/swiftshop/blob/main/frontend/src/config.js"
    click ViteConfig "https://github.com/ivanloav/swiftshop/blob/main/frontend/vite.config.js"

    %% Click Events - Backend
    click MainTS "https://github.com/ivanloav/swiftshop/blob/main/backend/src/main.ts"
    click AppModule "https://github.com/ivanloav/swiftshop/blob/main/backend/src/app.module.ts"
    click AuthModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/auth"
    click CustomersModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/customers"
    click ProductsModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/products"
    click OrdersModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/orders"
    click InventoryModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/inventory"
    click StoresModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/stores"
    click DashboardModule "https://github.com/ivanloav/swiftshop/tree/main/backend/src/dashboard"
    click Entities "https://github.com/ivanloav/swiftshop/tree/main/backend/src/entities"
    click TSConfigs "https://github.com/ivanloav/swiftshop/blob/main/backend/tsconfig.json"
    click TSConfigs "https://github.com/ivanloav/swiftshop/blob/main/backend/tsconfig.build.json"
    click Dist "https://github.com/ivanloav/swiftshop/tree/main/backend/dist"
    click GitHubActions "https://github.com/ivanloav/swiftshop/blob/main/.github/workflows/deploy.yml"

    %% Styles
    classDef external fill:#dddddd,stroke:#888,stroke-width:1px;
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:1px;
    classDef backend fill:#ABEBC6,stroke:#1D8348,stroke-width:1px;
    classDef database fill:#F5CBA7,stroke:#B9770E,stroke-width:1px;
    classDef gateway fill:#ABEBC6,stroke:#1D8348,stroke-width:2px,stroke-dasharray: 5 5;
    classDef ci fill:#E5E8E8,stroke:#7B7D7D,stroke-width:1px;
```
