How meruemvn/ocop_be works
Project type and purpose
• This is a RESTful backend service (“OCOPBE”) built on Node.js/Express, backed by MongoDB, that provides CRUD endpoints for users, products, orders, carts, distributors, admins, and an AI-based recommendation engine. Precomputed recommendation artifacts are produced and consumed by Python scripts and a Node.js “recommender” service.
Main architectural components
a. Entry point / API layer
• app.js – initializes Express, loads config, connects to MongoDB, mounts routes
• config/db.js – MongoDB/Mongoose connection setup
b. Routing & Middleware
• routes/*.js – define HTTP endpoints per resource (user, product, order, cart, distributor, admin, recommendation)
• middlewares/authMiddleware.js – handles authentication/authorization
c. Controllers
• controllers/*Controller.js – parse requests, enforce business rules, call services or models
d. Services & Business Logic
• services/recommender.service.js – loads Python artifacts (JSON, NPY, CSV, PKL) to compute recommendations
e. Data Layer
• models/*.js – Mongoose schemas (User, Product, Order, Cart, RequestLog)
• MongoDB – stores persistent application data
f. Python Recommender Artifacts & Scripts
• python_recommender_artifacts/ – precomputed matrices, maps, stopwords used by recommender.service
• scripts/ – Jupyter notebook and Python/JS scripts to train, normalize, enrich, export, and test the recommender
Relationships & data flows
1. Client (web/mobile) sends HTTP request →
2. Express (app.js) receives request →
3. Route handler (routes/*.js) →
4. Auth middleware (optional) →
5. Controller (*.js) →
• For CRUD: calls Mongoose Model → MongoDB → returns data → controller → response
• For recommendations: calls recommender.service → loads precomputed artifacts from disk → computes recommendations → returns to controller → response
6. Response sent back to client
Key architectural patterns & design principles
• MVC-style separation: routes → controllers → services/models
• Service layer for isolating business logic (recommender.service)
• Externalized configuration (config/db.js)
• Precomputation & caching: Python artifacts stored on disk to speed up recommendation queries
• Modularization: each resource has its own route, controller, and model
Detail without overthinking
• Every controller and its route grouping to highlight resource boundaries
• Distinguish the recommender path from standard CRUD paths
• Essential components so that an engineer can understand request flow, fault boundaries, and deployment scope at a glance