How arojaspolanco/supplier-management-api works
1. This repository is a Node.js backend organized as a feature-modular HTTP API. The entrypoints are src/index.js and src/app.js, with top-level routing assembled in src/routes/routes.js.
2. The codebase is split by business domain rather than by technical layer. The main domain modules are:
- Supplier
- TaxInformation
- CommercialCriteria
- HseqCriteria
- SafetyCriteria
- Offers
- Quoatations
Each module has its own controller, service, model, route, and schema files, and some include middleware for request checks.
3. The request flow is the standard API pipeline: route → middleware/schema validation → controller → service → model/database. Controllers handle HTTP concerns, services contain business logic, and models represent persistence objects.
4. Database access is centralized under src/config/database. database.js likely initializes the ORM connection, while associations.js defines relationships between the feature models. This suggests a relational data model with cross-entity links between suppliers, criteria, offers, and quotations.
5. The criteria modules are a distinct subsystem. The qualification-related utility files (qualificationComercialResults.js, qualificationHseqCriteria.js, qualificationSafetyCriteria.js, qualificationTaxInformationResulst.js) indicate that the application computes evaluation or scoring results across several criteria domains, probably aggregating supplier qualification outcomes.
6. src/utils/ contains cross-cutting helpers used by multiple modules:
- message catalogs for success/error text
- email utilities in nodemailes.js
- domain result helpers for qualification logic
- error-message extraction helpers
This is the shared application layer, separate from feature-specific code.
7. External integrations are visible in src/config/conections/axios.config.js, src/config/plugins/generate-JWT.js, and src/utils/nodemailes.js. That points to outbound HTTP calls, JWT generation for auth/token workflows, and email delivery as part of the backend’s integration surface.
8. Error handling is centralized. The src/errors folder contains custom error classes, async wrapper middleware, and a dedicated error controller/model, which means exceptions are normalized at the framework boundary instead of being handled ad hoc in each feature.
9. Configuration is environment-driven. src/config/enviroments/enviroments.js and env.templates imply deployment-specific settings are loaded from environment variables, keeping secrets and environment endpoints outside the code.
10. The schema files in each module suggest input validation is first-class. These schemas likely define request payload structure and business constraints before data reaches controllers or services.
11. src/common/utils/extractErrorData.js and the shared message files indicate the app converts low-level validation/database failures into consistent API responses. That matters for the architecture diagram because it is a separate cross-cutting error/response normalization path.
12. wp_users.json appears to be an auxiliary data fixture or import artifact, not a core runtime component. It may support seeding, testing, or integration with an external user source.
13. Overall, the architecture is a layered backend with a shared infrastructure tier, feature-based domains, centralized persistence, and several cross-cutting services for validation, qualification logic, email, JWT, and error handling.
Main entry points: routes.js routes.js · database.js Database · utils Utils · app.js app.js
Components 18
Entry & routing
Process bootstrap and top-level route assembly.
Feature domains
Business modules organized by supplier qualification and commercial workflows.
- Supplier · Supplier lifecycle and validation flow.
src/modules/Supplier - Tax Info · Tax-information capture and checks.
src/modules/TaxInformation - Commercial · Commercial qualification rules and scoring.
src/modules/ComercialCriteria - HSEQ · Health, safety, environment, and quality qualification.
src/modules/HseqCriteria - Safety · Safety qualification rules and scoring.
src/modules/SafetyCriteria - Offers · Offer handling and persistence.
src/modules/Offers - Quotations · Quotation handling and persistence.
src/modules/Quoatations
Shared infrastructure
Database, config, error handling, and cross-cutting utilities.
- Database · Initializes the relational datastore connection.
src/config/database/database.js - Associations · Defines relationships between feature models.
src/config/database/associations.js - Env config · Loads environment-specific settings.
src/config/enviroments/enviroments.js - HTTP client · Configured axios client for external requests.
src/config/conections/axios.config.js - JWT plugin · Generates JWTs for auth or token workflows.
src/config/plugins/generate-JWT.js - Errors · Custom errors, async wrapper, and error controller/model.
src/errors - Utils · Messages, qualification helpers, email, and error extraction utilities.
src/utils - Email · Nodemailer-based outbound email delivery.
src/utils/nodemailes.js
Connections 27
- index.js → app.js: boots · Server startup delegates to app composition.
- app.js → routes.js: mounts · The app installs the top-level router.
- routes.js → Supplier: routes · Registers supplier endpoints.
- routes.js → Tax Info: routes · Registers tax-information endpoints.
- routes.js → Commercial: routes · Registers commercial-criteria endpoints.
- routes.js → HSEQ: routes · Registers HSEQ criteria endpoints.
- routes.js → Safety: routes · Registers safety criteria endpoints.
- routes.js → Offers: routes · Registers offers endpoints.
- routes.js → Quotations: routes · Registers quotation endpoints.
- Supplier → Database: persists via · Supplier data is stored through the shared database layer.
- Tax Info → Database: persists via · Tax-information records use the shared database layer.
- Commercial → Database: persists via · Commercial criteria data uses the shared database layer.
- HSEQ → Database: persists via · HSEQ criteria data uses the shared database layer.
- Safety → Database: persists via · Safety criteria data uses the shared database layer.
- Offers → Database: persists via · Offers are stored through the shared database layer.
- Quotations → Database: persists via · Quotations are stored through the shared database layer.
- Database → Associations: links · Associations define cross-model relationships.
- Supplier → Utils: uses · Supplier flows share messages and validation helpers.
- Commercial → Utils: uses · Qualification calculations reuse shared helper logic.
- HSEQ → Utils: uses · Qualification calculations reuse shared helper logic.
- Safety → Utils: uses · Qualification calculations reuse shared helper logic.
- Tax Info → Utils: uses · Qualification calculations reuse shared helper logic.
- app.js → Errors: centralizes · The app boundary normalizes failures through shared error handling.
- routes.js → Env config: configures · Runtime behavior depends on environment settings.
- app.js → HTTP client: calls out · Some flows use the shared outbound HTTP client.
- app.js → JWT plugin: auth/token · Token generation supports authentication-related workflows.
- Utils → Email: includes · Email sending is part of the shared application utilities.