# daparamo/homecenter-prueba-tecnica--etq-lpn architecture

> Architecture diagram of the GitHub repository daparamo/homecenter-prueba-tecnica--etq-lpn, 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/daparamo/homecenter-prueba-tecnica--etq-lpn
- Repository: https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn

## Overview

#### Purpose and Entry Points
ETQ is a warehouse label-printing submodule. It resolves an LPN to its source document, applies document and inventory rules, produces simulated ZPL output, and records every outcome for traceability. Primary API bootstrap and routing are `backend/src/index.ts` and `backend/src/routes/print.routes.ts`. The operator-facing SPA starts at `frontend/src/main.tsx` and composes the UI in `frontend/src/App.tsx`.

#### Deployment Topology and Gateway
The system runs as separate frontend and backend containers orchestrated by `docker-compose.yml`. The frontend is served through Nginx and acts as the API gateway: `api-gateway/nginx.conf` proxies browser `/api/v1/...` calls to the backend while exposing the UI on port 8888. Backend Swagger is configured in `backend/src/docs/swagger.ts`; containers are defined by `frontend/Dockerfile` and `backend/Dockerfile`.

#### Backend HTTP Boundary
`backend/src/controllers/print.controller.ts` is the REST boundary for label-print requests and audit-history retrieval. Routes in `backend/src/routes/print.routes.ts` map HTTP input to controller operations. The controller should remain responsible for request/response translation and status codes, while domain orchestration stays in services.

#### Print Processing and Rules Engine
`backend/src/services/print.service.ts` is the core application service. Its processing flow is: accept LPN/zone/request metadata; find the associated label/order; reject unknown LPNs; reject disallowed document states (`ANULADA`, `DEVUELTA`); verify requested products are supplied and sufficiently stocked for the target zone; classify a successful repeat as `REIMPRESION`; generate and return ZPL; audit either success or rejection. Source data boundaries are local JSON mock stores: `backend/src/data/tableOrders.json` and `backend/src/data/inventory.json`.

#### Audit and Reprint Semantics
`backend/src/services/audit.service.ts` owns audit read/write operations and prior-success detection. It persists each attempt—successful and rejected—to `backend/src/data/audit.json`, allowing the print service to convert subsequent successful requests for the same LPN into reprints and preserve an optional reason. History retrieval is exposed through the same controller/API surface rather than direct frontend file access.

#### Frontend Interaction Flow
The React SPA collects print input, calls the gateway-backed API, and renders loading, success/error, ZPL, and reprint state. `frontend/src/components/PrintForm.tsx` is the request interaction boundary; `frontend/src/components/ResultCard.tsx` presents processing output. `frontend/src/components/HistoryTable.tsx` fetches/displays the audit stream, making backend audit persistence the source of truth.

#### Material Boundaries and Dependencies
Runtime stack: Node.js/Express backend, React/Vite frontend, Nginx proxy, Docker Compose orchestration, and filesystem JSON persistence. There is no indicated production database, message broker, or physical printer integration: ZPL is returned as API data and the printer is simulated. The externally consumable API contract is also represented by `HomeCenter-ETQ-API.postman_collection.json`.

Main entry points: [`frontend/src/App.tsx`](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/App.tsx) (App Composition), [`backend/src/services/print.service.ts`](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/services/print.service.ts) (Print Service), [`api-gateway/nginx.conf`](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/api-gateway/nginx.conf) (Nginx API Gateway), [`backend/src/index.ts`](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/index.ts) (Express Bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_deployment["Deployment"]
  node_compose{{"Docker Compose<br/>orchestrator<br/>[docker-compose.yml]"}}
  node_nginx["Nginx API Gateway<br/>reverse proxy<br/>[nginx.conf]"]
  node_frontend_container["Frontend Container<br/>container image"]
  node_backend_container["Backend Container<br/>container image"]
end

subgraph group_frontend["Frontend SPA"]
  node_spa_entry["React Entry<br/>SPA bootstrap<br/>[main.tsx]"]
  node_app["App Composition<br/>React app<br/>[App.tsx]"]
  node_print_form["Print Form<br/>request UI<br/>[PrintForm.tsx]"]
  node_result_card["Result Card<br/>result UI<br/>[ResultCard.tsx]"]
  node_history_table["History Table<br/>audit UI<br/>[HistoryTable.tsx]"]
end

subgraph group_backend["Backend API"]
  node_api_bootstrap["Express Bootstrap<br/>API bootstrap<br/>[index.ts]"]
  node_print_routes["Print Routes<br/>route mapping<br/>[print.routes.ts]"]
  node_print_controller["Print Controller<br/>REST controller"]
  node_print_service["Print Service<br/>domain orchestration<br/>[print.service.ts]"]
  node_audit_service["Audit Service<br/>audit domain service<br/>[audit.service.ts]"]
  node_orders_store[("Orders Store<br/>JSON mock store<br/>[tableOrders.json]")]
  node_inventory_store[("Inventory Store<br/>JSON mock store<br/>[inventory.json]")]
  node_audit_store[("Audit Store<br/>JSON persistence<br/>[audit.json]")]
  node_swagger["Swagger Docs<br/>API documentation<br/>[swagger.ts]"]
end

node_postman_contract["Postman Collection<br/>API contract"]

node_compose -->|"runs"| node_frontend_container
node_compose -->|"runs"| node_backend_container
node_frontend_container -->|"serves via"| node_nginx
node_nginx -->|"proxies /api/v1"| node_api_bootstrap
node_spa_entry -->|"mounts"| node_app
node_app -->|"composes"| node_print_form
node_app -->|"composes"| node_result_card
node_app -->|"composes"| node_history_table
node_print_form -->|"print request"| node_nginx
node_history_table -->|"history request"| node_nginx
node_api_bootstrap -->|"registers"| node_print_routes
node_api_bootstrap -->|"configures"| node_swagger
node_print_routes -->|"maps requests"| node_print_controller
node_print_controller -->|"process print"| node_print_service
node_print_controller -->|"retrieve history"| node_audit_service
node_print_service -->|"resolve LPN and state"| node_orders_store
node_print_service -->|"verify zone stock"| node_inventory_store
node_print_service -->|"record outcome and reprint check"| node_audit_service
node_audit_service -->|"read/write attempts"| node_audit_store
node_postman_contract -.->|"documents API"| node_print_routes

click node_compose "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/docker-compose.yml"
click node_nginx "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/api-gateway/nginx.conf"
click node_frontend_container "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/Dockerfile"
click node_backend_container "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/Dockerfile"
click node_spa_entry "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/main.tsx"
click node_app "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/App.tsx"
click node_print_form "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/components/PrintForm.tsx"
click node_result_card "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/components/ResultCard.tsx"
click node_history_table "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/components/HistoryTable.tsx"
click node_api_bootstrap "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/index.ts"
click node_print_routes "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/routes/print.routes.ts"
click node_print_controller "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/controllers/print.controller.ts"
click node_print_service "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/services/print.service.ts"
click node_audit_service "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/services/audit.service.ts"
click node_orders_store "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/data/tableOrders.json"
click node_inventory_store "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/data/inventory.json"
click node_audit_store "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/data/audit.json"
click node_swagger "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/docs/swagger.ts"
click node_postman_contract "https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/HomeCenter-ETQ-API.postman_collection.json"

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_compose,node_nginx,node_frontend_container,node_backend_container toneBlue
class node_spa_entry,node_app,node_print_form,node_result_card,node_history_table toneAmber
class node_api_bootstrap,node_print_routes,node_print_controller,node_print_service,node_audit_service,node_orders_store,node_inventory_store,node_audit_store,node_swagger toneMint
class node_postman_contract toneNeutral
```

## Components

### Deployment

- [Docker Compose](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/docker-compose.yml): orchestrator · Runs the frontend and backend containers. · `docker-compose.yml`
- [Nginx API Gateway](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/api-gateway/nginx.conf): reverse proxy · Serves the SPA and proxies /api/v1 requests. · `api-gateway/nginx.conf`
- [Frontend Container](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/Dockerfile): container image · `frontend/Dockerfile`
- [Backend Container](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/Dockerfile): container image · `backend/Dockerfile`

### Frontend SPA

- [React Entry](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/main.tsx): SPA bootstrap · `frontend/src/main.tsx`
- [App Composition](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/App.tsx): React app · `frontend/src/App.tsx`
- [Print Form](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/components/PrintForm.tsx): request UI · Collects LPN, zone, and request metadata. · `frontend/src/components/PrintForm.tsx`
- [Result Card](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/components/ResultCard.tsx): result UI · Displays outcome, ZPL, errors, and reprint state. · `frontend/src/components/ResultCard.tsx`
- [History Table](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/frontend/src/components/HistoryTable.tsx): audit UI · Fetches and displays audit history. · `frontend/src/components/HistoryTable.tsx`

### Backend API

- [Express Bootstrap](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/index.ts): API bootstrap · `backend/src/index.ts`
- [Print Routes](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/routes/print.routes.ts): route mapping · `backend/src/routes/print.routes.ts`
- [Print Controller](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/controllers/print.controller.ts): REST controller · Translates print and history HTTP requests. · `backend/src/controllers/print.controller.ts`
- [Print Service](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/services/print.service.ts): domain orchestration · Validates documents and inventory, generates simulated ZPL, and audits outcomes. · `backend/src/services/print.service.ts`
- [Audit Service](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/services/audit.service.ts): audit domain service · Persists attempts and detects prior successful prints. · `backend/src/services/audit.service.ts`
- [Orders Store](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/data/tableOrders.json): JSON mock store · `backend/src/data/tableOrders.json`
- [Inventory Store](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/data/inventory.json): JSON mock store · `backend/src/data/inventory.json`
- [Audit Store](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/data/audit.json): JSON persistence · Stores successful and rejected print attempts. · `backend/src/data/audit.json`
- [Swagger Docs](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/backend/src/docs/swagger.ts): API documentation · `backend/src/docs/swagger.ts`

### Other components

- [Postman Collection](https://github.com/daparamo/homecenter-prueba-tecnica--etq-lpn/blob/master/HomeCenter-ETQ-API.postman_collection.json): API contract · `HomeCenter-ETQ-API.postman_collection.json`

## Connections

- Docker Compose → Frontend Container: runs
- Docker Compose → Backend Container: runs
- Frontend Container → Nginx API Gateway: serves via
- Nginx API Gateway → Express Bootstrap: proxies /api/v1
- React Entry → App Composition: mounts
- App Composition → Print Form: composes
- App Composition → Result Card: composes
- App Composition → History Table: composes
- Print Form → Nginx API Gateway: print request
- History Table → Nginx API Gateway: history request
- Express Bootstrap → Print Routes: registers
- Express Bootstrap → Swagger Docs: configures
- Print Routes → Print Controller: maps requests
- Print Controller → Print Service: process print
- Print Controller → Audit Service: retrieve history
- Print Service → Orders Store: resolve LPN and state
- Print Service → Inventory Store: verify zone stock
- Print Service → Audit Service: record outcome and reprint check
- Audit Service → Audit Store: read/write attempts
- Postman Collection → Print Routes: documents API
