How ivanloav/swiftshop works
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).