# hajikhanovkh/backend-api architecture

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

- Interactive diagram: https://gitdiagram.com/hajikhanovkh/backend-api
- Repository: https://github.com/hajikhanovkh/backend-api

## Overview

CMR Analyzer accepts uploaded documents and returns structured CMR/invoice analysis. Its main workflow has two routes: OpenAI analyzes the uploaded file directly, while the Document AI route extracts page text, parses fields, and assembles CMR and invoice results. A separate registration-code lookup queries MySQL. The sampled server shows an in-memory analysis cache and these integrations; no README or other runtime source was provided.

Main entry points: [`server.js`](https://github.com/hajikhanovkh/backend-api/blob/main/server.js) (HTTP routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflows"]
  node_routes["HTTP routes<br/>[server.js]"]
  node_result_mapping["Result assembly<br/>[server.js]"]
  node_mysql_lookup["NV lookup<br/>[server.js]"]
end

subgraph group_analysis["Document analysis"]
  node_openai_analysis["OpenAI analysis<br/>[server.js]"]
  node_docai_analysis["Document AI OCR<br/>[server.js]"]
  node_field_extraction["Field extraction<br/>[server.js]"]
end

subgraph group_integrations["Services and state"]
  node_cache["Analysis cache<br/>[server.js]"]
  node_openai{{"OpenAI API"}}
  node_document_ai{{"Google Document AI"}}
  node_mysql[("MySQL")]
end

node_client(("Upload client"))

node_client -->|"uploads file"| node_routes
node_routes -->|"checks cache"| node_cache
node_routes -->|"analyzes upload"| node_openai_analysis
node_openai_analysis -->|"requests analysis"| node_openai
node_routes -->|"analyzes upload"| node_docai_analysis
node_docai_analysis -->|"processes document"| node_document_ai
node_routes -->|"parses page text"| node_field_extraction
node_routes -->|"assembles fields"| node_result_mapping
node_routes -->|"stores analysis"| node_cache
node_routes -->|"handles lookup"| node_mysql_lookup
node_mysql_lookup -->|"queries NV data"| node_mysql
node_routes -->|"returns JSON"| node_client

click node_routes "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"
click node_cache "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"
click node_openai_analysis "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"
click node_docai_analysis "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"
click node_field_extraction "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"
click node_result_mapping "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"
click node_mysql_lookup "https://github.com/hajikhanovkh/backend-api/blob/main/server.js"

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_routes,node_result_mapping,node_mysql_lookup,node_client toneBlue
class node_openai_analysis,node_docai_analysis,node_field_extraction toneAmber
class node_cache,node_openai,node_document_ai,node_mysql toneMint
```

## Components

### API workflows

- [HTTP routes](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`
- [Result assembly](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`
- [NV lookup](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`

### Document analysis

- [OpenAI analysis](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`
- [Document AI OCR](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`
- [Field extraction](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`

### Services and state

- [Analysis cache](https://github.com/hajikhanovkh/backend-api/blob/main/server.js): `server.js`
- **OpenAI API**
- **Google Document AI**
- **MySQL**

### Other components

- **Upload client**

## Connections

- Upload client → HTTP routes: uploads file (evidence: `server.js`)
- HTTP routes → Analysis cache: checks cache (evidence: `server.js`)
- HTTP routes → OpenAI analysis: analyzes upload (evidence: `server.js`)
- OpenAI analysis → OpenAI API: requests analysis (evidence: `server.js`)
- HTTP routes → Document AI OCR: analyzes upload (evidence: `server.js`)
- Document AI OCR → Google Document AI: processes document (evidence: `server.js`)
- HTTP routes → Field extraction: parses page text (evidence: `server.js`)
- HTTP routes → Result assembly: assembles fields (evidence: `server.js`)
- HTTP routes → Analysis cache: stores analysis (evidence: `server.js`)
- HTTP routes → NV lookup: handles lookup (evidence: `server.js`)
- NV lookup → MySQL: queries NV data (evidence: `server.js`)
- HTTP routes → Upload client: returns JSON (evidence: `server.js`)
