Introduction
Mis Compras uses a dual-backend architecture that combines Node.js and PHP to provide a robust and flexible e-commerce API. This hybrid approach leverages the strengths of both technologies to deliver optimal performance and maintainability.The platform runs two separate backend servers: a Node.js server on port 4000 for modern REST API operations, and PHP scripts for legacy authentication and user management.
Architecture Overview
Node.js Backend (Express)
The primary API server runs on Express.js and handles core e-commerce operations:- Base URL:
http://localhost:4000 - Technology Stack: Express.js, MySQL/MySQL2
- Features: Product management, order processing, user registration
PHP Backend
Legacy authentication and user management system:- Location:
/php/directory - Technology Stack: PHP 7+, MySQL
- Features: Session-based authentication, user login/registration
API Endpoints Structure
Node.js Endpoints
The Express server exposes three main route groups:PHP Endpoints
Response Format
All API endpoints return JSON responses with a consistent structure:Success Response
Error Response
PHP endpoints may use Spanish field names (e.g.,
éxito instead of success). Check the authentication documentation for details.CORS Configuration
Both backends are configured with CORS enabled:- Node.js: Uses
corsmiddleware with default settings - PHP: Headers set to allow all origins (
Access-Control-Allow-Origin: *)
Node.js CORS
PHP CORS
Request Format
Node.js Endpoints
All Node.js endpoints expect JSON payloads:PHP Endpoints
PHP endpoints expect form-data (application/x-www-form-urlencoded):Error Handling
Node.js Error Handling
PHP Error Handling
Database Connection
Both backends connect to the same MySQL database:- Node.js: Uses
mysql2with promise-based connections - PHP: Uses
mysqliwith prepared statements
All database queries use prepared statements to prevent SQL injection attacks.
Server Status
Check if the Node.js server is running:Next Steps
Authentication
Learn about session management and authentication flows
Products API
Explore product catalog endpoints
Orders API
Process orders and manage checkout
Users API
Manage user accounts and profiles