# lawlielowen/back_atc architecture

> Architecture diagram of the GitHub repository lawlielowen/back_atc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lawlielowen/back_atc
- Repository: https://github.com/lawlielowen/back_atc

## Overview

#### 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: [`Config/db.ts`](https://github.com/lawlielowen/back_atc/blob/main/Config/db.ts) (MySQL operational data), [`Service/Cliente_s.ts`](https://github.com/lawlielowen/back_atc/blob/main/Service/Cliente_s.ts) (Customer-to-order lifecycle), [`Router/Producto.ts`](https://github.com/lawlielowen/back_atc/blob/main/Router/Producto.ts) (Product routes), [`Service/Notificaciones.ts`](https://github.com/lawlielowen/back_atc/blob/main/Service/Notificaciones.ts) (Notifications and realtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP application"]
  node_server["Express bootstrap<br/>Node.js runtime<br/>[server.ts]"]
  node_product_router["Product routes<br/>router<br/>[Producto.ts]"]
  node_product_controller["Product controller"]
end

subgraph group_identity["Identity and access"]
  node_auth_router["Login routes<br/>router<br/>[login.ts]"]
  node_auth_controller["Auth controller<br/>[AuthController.ts]"]
  node_auth_service["Authentication service<br/>[Auth.ts]"]
  node_auth_middleware["Authentication middleware"]
  node_authorization["Role authorization<br/>middleware"]
end

subgraph group_operations["Commercial and operations"]
  node_product_service["Product and stock service<br/>[Productos.ts]"]
  node_product_model["Product model<br/>[Productos.ts]"]
  node_commercial["Customer-to-order lifecycle<br/>domain services<br/>[Cliente_s.ts]"]
  node_inventory["Procurement and dispatch<br/>domain services<br/>[Movimientos.ts]"]
  node_mysql[("MySQL operational data<br/>database<br/>[db.ts]")]
end

subgraph group_automation["Automation and reporting"]
  node_notifications["Notifications and realtime<br/>[Notificaciones.ts]"]
  node_scheduled_jobs["Scheduled jobs<br/>cron jobs<br/>[NotifJob.ts]"]
  node_metrics["Dashboard metrics<br/>reporting service<br/>[metricas.ts]"]
end

subgraph group_integrations["Documents and integrations"]
  node_uploads["Fiscal and receipt uploads<br/>local storage"]
  node_pdf_validation["Upload validation<br/>middleware<br/>[validarPDFReal.ts]"]
  node_quote_pdf["Quote PDF generation<br/>document generation<br/>[pdfHelper.ts]"]
  node_exchange_api{{"Banxico FIX rates<br/>external API<br/>[cambioDivisa.ts]"}}
end

node_server -->|"mounts"| node_product_router
node_product_router -->|"protected by"| node_auth_middleware
node_auth_middleware -->|"enforces roles"| node_authorization
node_product_router -->|"dispatches"| node_product_controller
node_product_controller -->|"calls"| node_product_service
node_product_service -->|"uses"| node_product_model
node_product_model -->|"persists"| node_mysql
node_server -->|"mounts"| node_auth_router
node_auth_router -->|"dispatches"| node_auth_controller
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"verifies identity"| node_mysql
node_commercial -->|"reads and writes"| node_mysql
node_commercial -->|"generates quotes"| node_quote_pdf
node_commercial -->|"uses rates"| node_exchange_api
node_inventory -->|"records movements"| node_mysql
node_inventory -->|"publishes dispatch activity"| node_notifications
node_pdf_validation -->|"stores accepted files"| node_uploads
node_scheduled_jobs -->|"creates and processes"| node_notifications
node_notifications -->|"stores notifications"| node_mysql
node_metrics -->|"aggregates"| node_mysql
node_metrics -->|"uses rates"| node_exchange_api

click node_server "https://github.com/lawlielowen/back_atc/blob/main/server.ts"
click node_product_router "https://github.com/lawlielowen/back_atc/blob/main/Router/Producto.ts"
click node_product_controller "https://github.com/lawlielowen/back_atc/blob/main/Controller/ProductoController.ts"
click node_product_service "https://github.com/lawlielowen/back_atc/blob/main/Service/Productos.ts"
click node_product_model "https://github.com/lawlielowen/back_atc/blob/main/Model/Productos.ts"
click node_auth_router "https://github.com/lawlielowen/back_atc/blob/main/Router/login.ts"
click node_auth_controller "https://github.com/lawlielowen/back_atc/blob/main/Controller/AuthController.ts"
click node_auth_service "https://github.com/lawlielowen/back_atc/blob/main/Service/Auth.ts"
click node_auth_middleware "https://github.com/lawlielowen/back_atc/blob/main/middleware/Auth.middleware%20.ts"
click node_authorization "https://github.com/lawlielowen/back_atc/blob/main/middleware/Authorize.middleware.ts"
click node_commercial "https://github.com/lawlielowen/back_atc/blob/main/Service/Cliente_s.ts"
click node_inventory "https://github.com/lawlielowen/back_atc/blob/main/Service/Movimientos.ts"
click node_mysql "https://github.com/lawlielowen/back_atc/blob/main/Config/db.ts"
click node_uploads "https://github.com/lawlielowen/back_atc/tree/main/uploads/CSF"
click node_pdf_validation "https://github.com/lawlielowen/back_atc/blob/main/middleware/validarPDFReal.ts"
click node_quote_pdf "https://github.com/lawlielowen/back_atc/blob/main/Controller/pdfHelper.ts"
click node_exchange_api "https://github.com/lawlielowen/back_atc/blob/main/Controller/cambioDivisa.ts"
click node_notifications "https://github.com/lawlielowen/back_atc/blob/main/Service/Notificaciones.ts"
click node_scheduled_jobs "https://github.com/lawlielowen/back_atc/blob/main/Jobs/NotifJob.ts"
click node_metrics "https://github.com/lawlielowen/back_atc/blob/main/Service/metricas.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_product_router,node_product_controller toneBlue
class node_auth_router,node_auth_controller,node_auth_service,node_auth_middleware,node_authorization toneAmber
class node_product_service,node_product_model,node_commercial,node_inventory,node_mysql toneMint
class node_notifications,node_scheduled_jobs,node_metrics toneRose
class node_uploads,node_pdf_validation,node_quote_pdf,node_exchange_api toneIndigo
```

## Components

### HTTP application

- [Express bootstrap](https://github.com/lawlielowen/back_atc/blob/main/server.ts): Node.js runtime · Starts the REST API and application services. · `server.ts`
- [Product routes](https://github.com/lawlielowen/back_atc/blob/main/Router/Producto.ts): router · `Router/Producto.ts`
- [Product controller](https://github.com/lawlielowen/back_atc/blob/main/Controller/ProductoController.ts): controller · `Controller/ProductoController.ts`

### Identity and access

- [Login routes](https://github.com/lawlielowen/back_atc/blob/main/Router/login.ts): router · `Router/login.ts`
- [Auth controller](https://github.com/lawlielowen/back_atc/blob/main/Controller/AuthController.ts): controller · `Controller/AuthController.ts`
- [Authentication service](https://github.com/lawlielowen/back_atc/blob/main/Service/Auth.ts): service · `Service/Auth.ts`
- [Authentication middleware](https://github.com/lawlielowen/back_atc/blob/main/middleware/Auth.middleware%20.ts): middleware · `middleware/Auth.middleware .ts`
- [Role authorization](https://github.com/lawlielowen/back_atc/blob/main/middleware/Authorize.middleware.ts): middleware · Guards restricted operational actions. · `middleware/Authorize.middleware.ts`

### Commercial and operations

- [Product and stock service](https://github.com/lawlielowen/back_atc/blob/main/Service/Productos.ts): service · Catalog operations and inventory system-of-record access. · `Service/Productos.ts`
- [Product model](https://github.com/lawlielowen/back_atc/blob/main/Model/Productos.ts): model · `Model/Productos.ts`
- [Customer-to-order lifecycle](https://github.com/lawlielowen/back_atc/blob/main/Service/Cliente_s.ts): domain services · Customers, quotes, credit orders, projects, and sales tickets. · `Service/Cliente_s.ts`
- [Procurement and dispatch](https://github.com/lawlielowen/back_atc/blob/main/Service/Movimientos.ts): domain services · Supplier receiving, stock movements, vouchers, demos, and visits. · `Service/Movimientos.ts`
- [MySQL operational data](https://github.com/lawlielowen/back_atc/blob/main/Config/db.ts): database · Operational data, views, procedures, and transactions. · `Config/db.ts`

### Automation and reporting

- [Notifications and realtime](https://github.com/lawlielowen/back_atc/blob/main/Service/Notificaciones.ts): service · WebSocket dispatch updates and notification processing. · `Service/Notificaciones.ts`
- [Scheduled jobs](https://github.com/lawlielowen/back_atc/blob/main/Jobs/NotifJob.ts): cron jobs · Reminders, notification processing, cleanup, and supplier-date monitoring. · `Jobs/NotifJob.ts`
- [Dashboard metrics](https://github.com/lawlielowen/back_atc/blob/main/Service/metricas.ts): reporting service · Aggregates commercial and inventory data. · `Service/metricas.ts`

### Documents and integrations

- [Fiscal and receipt uploads](https://github.com/lawlielowen/back_atc/tree/main/uploads/CSF): local storage · Stores validated CSF and payment-receipt PDFs. · `uploads/CSF`
- [Upload validation](https://github.com/lawlielowen/back_atc/blob/main/middleware/validarPDFReal.ts): middleware · Accepts CSF and receipt uploads and validates real PDFs. · `middleware/validarPDFReal.ts`
- [Quote PDF generation](https://github.com/lawlielowen/back_atc/blob/main/Controller/pdfHelper.ts): document generation · `Controller/pdfHelper.ts`
- [Banxico FIX rates](https://github.com/lawlielowen/back_atc/blob/main/Controller/cambioDivisa.ts): external API · Currency rates for quotes, orders, and metrics. · `Controller/cambioDivisa.ts`

## Connections

- 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
