How hongphuc-ng24/doan_reactjs works
Project type and purpose
• This is a full-stack e-commerce / content site with a React-based front end and a Node.js/Express back end.
• The front end has both public (user) pages and an admin interface; the back end exposes REST endpoints for products, news, users, carts, and handles file uploads and static asset serving.
File structure
• Top level splits into front-end/ and back-end/.
• front-end/src/: React components organized by feature (layouts, pages, components, services, utils, routes).
• back-end/src/: Express server (server.js); configuration (config/db.js); route modules, controllers, models, and middlewares.
• Static assets: front-end/public/ and back-end/public/ + back-end/src/uploads.
• Deployment/build scripts: package.json in each directory; npm run dev, npm start in README.
README
• Minimal: start commands. Assumes dev mode spins up front- and back-end.
Main components of the system
a. Front-end application (React SPA)
• User-facing pages: Home, Product listing/detail, News, Cart, Contact
• Authentication pages: Login, SignUp
• Admin pages: Product management, News management, User management
• Client-side services: productServices.js, userServices.js, newServices.js calling the API via httpRequest.js.
b. Back-end API (Node.js + Express)
• Router layer: src/routes/*.js
• Controller layer: src/controllers/*.js
• Data layer: Mongoose models (src/models/*.js) connecting to MongoDB via src/config/db.js
• Middlewares: authMiddleware.js, file upload handler (upload.js)
• Static file serving: Express hosts public/products/* and uploads
c. Database
• MongoDB (implied by .env and config/db.js)
d. Static asset storage
• A local filesystem directory for product images (back-end/src/uploads/products) and public assets.
e. Optional external services
• Could include third-party authentication (JWT in authMiddleware), email or chat services (UI has Chatbox component).
Relationships and interactions
• React UI issues HTTP(S) requests to Express API endpoints.
• Express controllers validate/authenticate via middleware, then invoke model operations on MongoDB.
• On product upload, Express writes files to uploads and persists metadata in MongoDB.
• MongoDB returns data to controllers, which send JSON back to React.
• React updates UI state accordingly.
Architectural patterns & design principles
• Client–server separation (React front end vs. RESTful back end)
• Layered back-end: routing → controller → service/data → DB
• Single-page application with client-side routing (react-router)
• MVC-like structure in back end (models, views=JSON, controllers)
• Use of middleware for cross-cutting concerns (authentication, file uploads)
Detail
• Every subsystem: client routing, API endpoints, business logic, data persistence, static asset pipeline.
• Build steps/triggers if needed (e.g. npm run build → CI/CD pipeline → static host).