# leoincode/validate-ticket architecture

> Architecture diagram of the GitHub repository leoincode/validate-ticket, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leoincode/validate-ticket
- Repository: https://github.com/leoincode/validate-ticket

## Overview

##### Project type and purpose
- This is a backend API service (not a full-stack app) whose sole purpose is to validate bank-slip and dealership-slip codes and return parsed information (barCode, amount, expirationDate).
- It follows a layered, “clean” or hexagonal architecture (ports & adapters) implemented in Node.js + TypeScript + Express, with TDD via Jest.

##### File structure
- Top-level entry points:
– server.ts / app.ts – bootstraps the Express server
– routes/fetlock.ts – defines the HTTP endpoint(s)
- src/01.api – Express controllers that handle HTTP and call application use cases
- src/02.application – core business logic divided into:
– common/exceptions & common/helpers – reusable validators & calculators
– useCases/bankSlip & useCases/dealershipSlip – specific domain workflows, factories & helpers
- src/03.infra – technical adapters (e.g., dateTransform using date-fns)
- tests – mirrors the three layers (01.api, 02.application, 03.infra) for unit & integration tests

##### README for additional insights
- Describes supported slip types, success & error responses, external dependency (date-fns)
- Confirms Node.js, TypeScript, Express, Jest TDD

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "HTTP Layer"
    ServerTs["server.ts"]:::httpapi
    AppTs["app.ts"]:::httpapi
    FetlockRoute["routes/fetlock.ts"]:::httpapi
  end

  subgraph "API Layer"
    FetlockController["FetlockController"]:::httpapi
  end

  subgraph "Application Layer"
    subgraph "BankSlip Use Case"
      BankSlip["BankSlipUseCase"]:::appdomain
      BankSlipFactory["BankSlipFactory"]:::appdomain
      VerDigit["verifyingDigit"]:::appdomain
      IVerDigit["iVerifyingDigit"]:::appdomain
    end
    subgraph "DealershipSlip Use Case"
      DealSlip["DealershipSlipUseCase"]:::appdomain
      DealSlipFactory["DealershipSlipFactory"]:::appdomain
      VerDigitDeal["verifyingDigitDealership"]:::appdomain
      IVerDigitDeal["iVerifyingDigitDealership"]:::appdomain
    end
    subgraph "Common Helpers & Interfaces"
      CodeValidator["codeValidator"]:::appdomain
      ICodeValidator["iCodeValidator"]:::appdomain
      CodeCalculator["codeCalculator"]:::appdomain
      ICodeCalculator["iCodeCalculator"]:::appdomain
      ReplaceCode["replaceCode"]:::appdomain
      IBankSlipInt["iBankSlip"]:::appdomain
      IResponse["iResponse"]:::appdomain
    end
    subgraph "Exceptions"
      DiffLength["differentLengthError"]:::appdomain
      InvalidCode["invalidCodeError"]:::appdomain
      NotANumber["isNotANumberError"]:::appdomain
      MissingParam["missingParamError"]:::appdomain
    end
  end

  subgraph "Infrastructure Layer"
    IDateTransform["iDateTransform"]:::infra
    DateTransform["dateTransform"]:::infra
  end

  DateFns["date-fns"]:::external

  ServerTs --> AppTs
  AppTs --> FetlockRoute
  FetlockRoute --> FetlockController
  FetlockController --> BankSlip
  FetlockController --> DealSlip

  BankSlip -->|uses| VerDigit
  BankSlip -->|uses| IVerDigit
  BankSlip -->|uses| BankSlipFactory
  BankSlip -->|uses| CodeValidator
  BankSlip -->|uses| CodeCalculator
  BankSlip -->|uses| ReplaceCode
  BankSlip -->|throws| DiffLength
  BankSlip -->|throws| InvalidCode
  BankSlip -->|throws| NotANumber
  BankSlip -->|throws| MissingParam
  BankSlip --> IDateTransform

  DealSlip -->|uses| VerDigitDeal
  DealSlip -->|uses| IVerDigitDeal
  DealSlip -->|uses| DealSlipFactory
  DealSlip -->|uses| CodeValidator
  DealSlip -->|uses| CodeCalculator
  DealSlip -->|uses| ReplaceCode
  DealSlip -->|throws| DiffLength
  DealSlip -->|throws| InvalidCode
  DealSlip -->|throws| NotANumber
  DealSlip -->|throws| MissingParam
  DealSlip --> IDateTransform

  IDateTransform --> DateTransform
  DateTransform --> DateFns

  click ServerTs "https://github.com/leoincode/validate-ticket/blob/main/server.ts"
  click AppTs "https://github.com/leoincode/validate-ticket/blob/main/app.ts"
  click FetlockRoute "https://github.com/leoincode/validate-ticket/blob/main/routes/fetlock.ts"
  click FetlockController "https://github.com/leoincode/validate-ticket/blob/main/src/01.api/fetlockController.ts"
  click BankSlip "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/bankSlip/bankSplip.ts"
  click BankSlipFactory "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/bankSlip/factory/bankSlipFactory.ts"
  click VerDigit "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/bankSlip/utils/helpers/verifyingDigit.ts"
  click IVerDigit "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/bankSlip/utils/helpers/iVerifyingDigit.ts"
  click DealSlip "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/dealershipSlip/dealershipSlip.ts"
  click DealSlipFactory "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/dealershipSlip/factory/dealershipSlipFactory.ts"
  click VerDigitDeal "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/dealershipSlip/utils/helpers/verifyingDigitDealership.ts"
  click IVerDigitDeal "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/dealershipSlip/utils/helpers/iVerifyingDigitDealership.ts"
  click CodeValidator "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/helpers/codeValidator.ts"
  click ICodeValidator "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/helpers/iCodeValidator.ts"
  click CodeCalculator "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/helpers/codeCalculator.ts"
  click ICodeCalculator "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/helpers/iCodeCalculator.ts"
  click ReplaceCode "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/helpers/replaceCode.ts"
  click IBankSlipInt "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/interfaces/iBankSlip.ts"
  click IResponse "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/useCases/interfaces/iResponse.ts"
  click DiffLength "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/exceptions/differentLengthError.ts"
  click InvalidCode "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/exceptions/invalidCodeError.ts"
  click NotANumber "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/exceptions/isNotANumberError.ts"
  click MissingParam "https://github.com/leoincode/validate-ticket/blob/main/src/02.application/common/exceptions/missingParamError.ts"
  click DateTransform "https://github.com/leoincode/validate-ticket/blob/main/src/03.infra/adapters/dateTransform/dateTransform.ts"
  click IDateTransform "https://github.com/leoincode/validate-ticket/blob/main/src/03.infra/adapters/dateTransform/iDateTransform.ts"

  classDef httpapi fill:#e3f2fd,stroke:#90caf9
  classDef appdomain fill:#e8f5e9,stroke:#66bb6a
  classDef infra fill:#fff3e0,stroke:#ffa726
  classDef external fill:#eceff1,stroke:#b0bec5
```
