How nhienkrb/app-simple-crud-e-commerce works
Project Type and Purpose
• This is a full-stack CRUD e-commerce application.
• Frontend: React (Vite) single-page app with Material-UI components.
• Backend: Laravel REST API (controllers, services, repositories) exposing endpoints for categories, products, orders, loyalty points, promotions and news.
• Database: relational (MySQL/Postgres) managed via Laravel migrations and seeders.
File Structure Analysis
• Top level: two main directories, frontend/ and backend/, plus global .gitignore and root README.md.
• backend/
• app/Http/Controllers/Api – REST endpoints
• app/Services & app/Repositories – service layer and data-access layer
• app/Models – database entities (Product, Order, User, etc.)
• database/migrations & seeders – schema definition and initial data
• routes/api.php – API route definitions
• config/, bootstrap/, public/index.php – Laravel bootstrapping and configuration
• frontend/
• src/pages – page components for home, products, cart, checkout, auth, news
• src/components – reusable UI elements (Navbar, ProductCard, CartTable, etc.)
• src/context & hooksCustom – React Contexts (Auth, Cart) and custom hooks for data fetching
• public/ – static assets (images, fonts)
• vite.config.js, package.json – build and dependency configuration
Key Architectural Themes
• Separation of concerns: frontend UI / backend API / database.
• Backend patterns: MVC + Service layer + Repository layer + Policy (authorization).
• Frontend patterns: Component hierarchy + Context for global state + custom hooks for API calls.
• Stateless REST communication between UI and API over HTTP/JSON.
• Authentication using Laravel Sanctum (implied by sanctum config).
Components
a. Frontend SPA
• React components tree
• Context providers (AuthContext, CartContext)
• Custom hooks invoking HTTP requests
b. API Gateway
• API routes → Controllers
• Middleware (Authentication, CORS, CSRF)
c. Domain Logic
• Service classes (AuthService, ProductService, OrderService, etc.)
• Repository classes accessing Eloquent models
d. Database
• Tables: users, products, categories, orders, order_details, promotions, loyalty_points, news
• Migrations & seeders
e. External/Internal Services
• Email service (mail config)
• Queue/Cache/Logging (config files)
• Static asset hosting (frontend CDN or web server)
Architectural Patterns & Technologies
• Frontend: React, Vite, Material-UI, React Router, Context API
• Backend: PHP, Laravel (MVC, Service/Repository patterns), Sanctum for auth, MySQL, Redis for cache/queue
• DevOps: Vite build, npm scripts, Composer, Artisan, environment files (.env)
– API Gateway (routes + middleware)
– Controllers → Services → Repositories → Models
– User actions → SPA → API → DB → API → SPA → User