How lawlielowen/back_atc works
Purpose and Runtime
Back_ATC is a production REST backend for ATC’s sales, inventory, fulfillment, and advisor operations. It runs on Node.js/Express with TypeScript, persists operational data in MySQL, and provides real-time and scheduled automation. Application bootstrap is server.ts; database access is configured in Config/db.ts.
Layered HTTP Application
The API follows Router → middleware → Controller → Service → Model/data boundary. Routers expose domain endpoints, controllers own HTTP request/response handling, and services implement business/database operations. Representative paths: Router/Producto.ts, Controller/ProductoController.ts, Service/Productos.ts, Model/Productos.ts.
Identity and Access Boundary
Authentication and role-based authorization protect operational modules, especially advisor administration and restricted actions. This boundary is implemented through Router/login.ts, Controller/AuthController.ts, Service/Auth.ts, middleware/Auth.middleware .ts, and middleware/Authorize.middleware.ts.
Commercial and Customer Lifecycle
Customer records support fiscal-document intake and credit assignment; quotes create commercial proposals; orders capture payment or authorized-credit fulfillment; projects and tickets track work and sales follow-up through closure. Core paths include Service/Cliente_s.ts, Service/Cotizaciones.ts, Service/Pedidos.ts, Service/Proyectos.ts, Service/ticket.ts, and Model/Cotizacion.ts.
Inventory, Supplier, and Dispatch Flow
Product catalog and stock movements are the inventory system of record. Supplier orders/receiving, output vouchers, demos, and customer visits coordinate physical goods from procurement through delivery or demonstration. Important components: Service/Movimientos.ts, Service/Proveedor.ts, Service/Vales.ts, Service/demos.ts, Service/Visitas.ts; corresponding API boundaries include Router/Movimientos.ts, Router/Proveedor.ts, and Router/Vales.ts.
Documents and External Integrations
The backend accepts CSF and payment-receipt uploads, validates PDFs, and stores them under local upload directories. Quote generation uses an HTML template and PDF support. Currency-dependent quote, order, and metric flows consume Banco de México SIE’s FIX exchange-rate API through Controller/cambioDivisa.ts. Relevant paths: middleware/multerCSF.ts, middleware/multerRecibos.ts, middleware/validarPDFReal.ts, Template/Plantilla.html, Controller/pdfHelper.ts, uploads/CSF, uploads/recibos.
Notifications, Automation, and Reporting
WebSockets synchronize dispatch/output-voucher activity in real time. Cron-driven jobs create reminders, process notifications, and clean notification data, including supplier-order date monitoring. Dashboard metrics aggregate commercial and inventory information, likely relying on MySQL views, stored procedures, and transactions. Key paths: Service/Notificaciones.ts, Controller/NotificacionController.ts, Jobs/NotifJob.ts, Jobs/recordatorioJob.ts, Jobs/LimpiezaNotis.ts, Service/metricas.ts, and Router/Metricas.ts.
Main entry points: db.ts MySQL operational data · Cliente_s.ts Customer-to-order lifecycle · Producto.ts Product routes · Notificaciones.ts Notifications and realtime
Components 20
HTTP application
- Express bootstrap · Starts the REST API and application services.
server.ts - Product routes
Router/Producto.ts - Product controller
Controller/ProductoController.ts
Identity and access
- Login routes
Router/login.ts - Auth controller
Controller/AuthController.ts - Authentication service
Service/Auth.ts - Authentication middleware
middleware/Auth.middleware .ts - Role authorization · Guards restricted operational actions.
middleware/Authorize.middleware.ts
Commercial and operations
- Product and stock service · Catalog operations and inventory system-of-record access.
Service/Productos.ts - Product model
Model/Productos.ts - Customer-to-order lifecycle · Customers, quotes, credit orders, projects, and sales tickets.
Service/Cliente_s.ts - Procurement and dispatch · Supplier receiving, stock movements, vouchers, demos, and visits.
Service/Movimientos.ts - MySQL operational data · Operational data, views, procedures, and transactions.
Config/db.ts
Automation and reporting
- Notifications and realtime · WebSocket dispatch updates and notification processing.
Service/Notificaciones.ts - Scheduled jobs · Reminders, notification processing, cleanup, and supplier-date monitoring.
Jobs/NotifJob.ts - Dashboard metrics · Aggregates commercial and inventory data.
Service/metricas.ts
Documents and integrations
- Fiscal and receipt uploads · Stores validated CSF and payment-receipt PDFs.
uploads/CSF - Upload validation · Accepts CSF and receipt uploads and validates real PDFs.
middleware/validarPDFReal.ts - Quote PDF generation
Controller/pdfHelper.ts - Banxico FIX rates · Currency rates for quotes, orders, and metrics.
Controller/cambioDivisa.ts
Connections 21
- Express bootstrap → Product routes: mounts
- Product routes → Authentication middleware: protected by
- Authentication middleware → Role authorization: enforces roles
- Product routes → Product controller: dispatches
- Product controller → Product and stock service: calls
- Product and stock service → Product model: uses
- Product model → MySQL operational data: persists
- Express bootstrap → Login routes: mounts
- Login routes → Auth controller: dispatches
- Auth controller → Authentication service: calls
- Authentication service → MySQL operational data: verifies identity
- Customer-to-order lifecycle → MySQL operational data: reads and writes
- Customer-to-order lifecycle → Quote PDF generation: generates quotes
- Customer-to-order lifecycle → Banxico FIX rates: uses rates
- Procurement and dispatch → MySQL operational data: records movements
- Procurement and dispatch → Notifications and realtime: publishes dispatch activity
- Upload validation → Fiscal and receipt uploads: stores accepted files
- Scheduled jobs → Notifications and realtime: creates and processes
- Notifications and realtime → MySQL operational data: stores notifications
- Dashboard metrics → MySQL operational data: aggregates
- Dashboard metrics → Banxico FIX rates: uses rates