{"id":42201425,"url":"https://github.com/batdimoiprint/e-commerce-sales-prediction-backend","last_synced_at":"2026-01-27T00:26:07.891Z","repository":{"id":285111309,"uuid":"951819571","full_name":"batdimoiprint/e-commerce-sales-prediction-backend","owner":"batdimoiprint","description":"Backend for E Commerce with Sales Prediction using GRU Time Series Forecasting","archived":false,"fork":false,"pushed_at":"2026-01-13T03:12:50.000Z","size":419,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-13T06:41:59.846Z","etag":null,"topics":["brainjs","cloudinary","docker","express","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/batdimoiprint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-20T09:45:06.000Z","updated_at":"2026-01-13T03:12:48.000Z","dependencies_parsed_at":"2025-04-29T20:27:20.802Z","dependency_job_id":"c21f6c25-6bb3-41c0-a61d-5c338e34e1ad","html_url":"https://github.com/batdimoiprint/e-commerce-sales-prediction-backend","commit_stats":null,"previous_names":["kenny2125/red-pc-sales-prediction-backend","kenny2125/e-commerce-sales-prediction-backend","batdimoiprint/e-commerce-sales-prediction-backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/batdimoiprint/e-commerce-sales-prediction-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/batdimoiprint%2Fe-commerce-sales-prediction-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/batdimoiprint%2Fe-commerce-sales-prediction-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/batdimoiprint%2Fe-commerce-sales-prediction-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/batdimoiprint%2Fe-commerce-sales-prediction-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/batdimoiprint","download_url":"https://codeload.github.com/batdimoiprint/e-commerce-sales-prediction-backend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/batdimoiprint%2Fe-commerce-sales-prediction-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28792979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T21:49:50.245Z","status":"ssl_error","status_checked_at":"2026-01-26T21:48:29.455Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brainjs","cloudinary","docker","express","nodejs"],"created_at":"2026-01-27T00:26:07.278Z","updated_at":"2026-01-27T00:26:07.871Z","avatar_url":"https://github.com/batdimoiprint.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# E-Commerce Sales Prediction Backend\n\nThis project is the backend for an e-commerce platform that includes features for managing products, orders, customer data, and sales predictions. It leverages machine learning to forecast future sales and provides APIs for various functionalities.\n\n## Features\n\n- **Product Management**: CRUD operations for products and their variants.\n- **Order Management**: Create, update, and manage orders, including support for discounts and cancellations.\n- **Customer Management**: Track customer acquisition and churn metrics.\n- **Cart Management**: Add, update, and remove items from the shopping cart.\n- **Sales Prediction**: Use GRU-based neural networks to forecast future sales.\n- **Data Aggregation**: Aggregate daily and monthly sales data for analytics and model training.\n\n## Project Structure\n\n- **`db/`**: Database connection and utility functions.\n  - `db.js`: Database connection setup.\n  - `salesData.js`: Functions for fetching and normalizing sales data.\n\n- **`models/`**: Business logic for interacting with the database.\n  - `product.js`: Handles product and variant operations.\n  - `order.js`: Manages orders and related operations.\n  - `cart.js`: Handles shopping cart operations.\n  - `customerAcquisition.js`: Tracks customer acquisition and churn metrics.\n  - `predictionModel.js`: Implements machine learning models for sales prediction.\n\n- **`routes/`**: API endpoints for various functionalities.\n  - `salesRoutes.js`: Endpoints for managing sales records and historical data.\n  - `predictionRoutes.js`: Endpoints for training and using sales prediction models.\n  - Other route files for products, orders, users, etc.\n\n- **`scripts/`**: Scripts for scheduled tasks.\n  - `generateDailySalesRecords.js`: Generates daily sales records from completed orders.\n  - `aggregateMonthlyData.js`: Aggregates monthly sales data and triggers model training.\n\n- **`saved_models/`**: Directory for storing trained machine learning models.\n\n- **`server.js`**: Main entry point for the backend server.\n\n## Setup\n\n### Prerequisites\n\n- Node.js (v14 or higher)\n- PostgreSQL database\n- Cloudinary account (for image management)\n\n### Installation\n\n1. Clone the repository:\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd e-commerce-sales-prediction-backend\n   ```\n\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n3. Set up environment variables:\n   Create a `.env` file in the root directory with the following variables:\n   ```\n   PORT=3000\n   DATABASE_URL=\u003cyour-database-url\u003e\n   CLOUDINARY_URL=\u003cyour-cloudinary-url\u003e\n   ```\n\n4. Run database migrations (if applicable).\n\n### Running the Server\n\nStart the development server:\n```bash\nnpm start\n```\n\nThe server will run on `http://localhost:3000` by default.\n\n## API Endpoints\n\n### Products\n- `GET /api/product`: Fetch all products.\n- `POST /api/product`: Create a new product.\n- `PUT /api/product/:id`: Update a product.\n- `DELETE /api/product/:id`: Delete a product.\n\n### Orders\n- `POST /api/orders`: Create a new order.\n- `GET /api/orders/:id`: Fetch order details.\n- `PUT /api/orders/:id/status`: Update order status.\n\n### Sales\n- `GET /api/sales/records`: Fetch all sales records.\n- `POST /api/sales/generate-records`: Manually trigger sales record generation.\n\n### Predictions\n- `POST /api/predictions/train`: Train a new sales prediction model.\n- `GET /api/predictions/sales`: Predict future sales.\n\n## Machine Learning\n\nThe project uses `brain.js` for training GRU-based neural networks to forecast sales. Models are saved in the `saved_models/` directory and can be reused for predictions.\n\n### Training a Model\nUse the `/api/predictions/train` endpoint to train a new model. Parameters such as `iterations` and `error_threshold` can be customized.\n\n### Forecasting Sales\nUse the `/api/predictions/sales` endpoint to forecast sales for a specified number of months ahead.\n\n## Scheduled Tasks\n\n- **Daily Sales Records**: The `generateDailySalesRecords.js` script generates sales records from completed orders.\n- **Monthly Data Aggregation**: The `aggregateMonthlyData.js` script aggregates sales data at the end of each month and triggers model training.\n\n## Frontend Repository\n\nThe frontend for this project is available at:  \n[https://github.com/batdimoiprint/e-commerce-sales-prediction-frontend](https://github.com/batdimoiprint/e-commerce-sales-prediction-frontend)\n\n## Contributing\n\n1. Fork the repository.\n2. Create a new branch for your feature or bugfix.\n3. Submit a pull request with a detailed description of your changes.\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbatdimoiprint%2Fe-commerce-sales-prediction-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbatdimoiprint%2Fe-commerce-sales-prediction-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbatdimoiprint%2Fe-commerce-sales-prediction-backend/lists"}