# swarnim-sawane/har-file-analyser architecture

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

- Interactive diagram: https://gitdiagram.com/swarnim-sawane/har-file-analyser
- Repository: https://github.com/swarnim-sawane/har-file-analyser

## Overview

#### Purpose and Entry Points
HAR File Analyzer is an internal diagnostic system for browser HAR files and console logs. It surfaces request failures, performance issues, request flows, sanitization, comparisons, and optional AI summaries. Browser startup is `src/main.tsx` into `src/App.tsx`; the API starts at `backend/src/server.ts`; asynchronous processing starts at `backend/src/worker.ts`. `backend/src/combinedRuntime.ts` supports a combined API/worker runtime.

#### Frontend Analysis Workspace
The React/Vite frontend owns interactive file selection, progressive results, filtering, details, visualizations, and AI surfaces. `src/hooks/useHarData.ts` and `src/hooks/useConsoleLogData.ts` coordinate retrieval and UI state; `src/services/apiClient.ts` and `src/services/websocketClient.ts` establish backend REST and Socket.IO boundaries. Primary result surfaces are organized in `src/components/HarTabContent.tsx`, `src/components/ConsoleLogTabContent.tsx`, and `src/components/AiInsightsSurface.tsx`.

#### Upload and Event Flow
The browser uploads HAR/log files in validated chunks through `src/services/chunkedUploader.ts` and upload components such as `src/components/UnifiedUploader.tsx`. Backend upload endpoints in `backend/src/routes/uploadRoutes.ts` validate, assemble, and persist source artifacts through `backend/src/services/artifactStore.ts`, then enqueue processing. Upload status/progress crosses the API-worker boundary through Redis/BullMQ and Socket.IO, with backend socket support in `backend/src/utils/socketHelper.ts`.

#### Background Parsing and Persistence
The worker consumes queued upload jobs and turns source artifacts into queryable records. `backend/src/workers/harProcessor.ts` processes HAR content, `backend/src/workers/logProcessor.ts` handles console logs, and `backend/src/workers/harEntryStorage.ts` persists large HAR entry sets. PostgreSQL access and migrations are centralized in `backend/src/persistence/postgresStore.ts` and `backend/src/persistence/postgresMigrations.ts`; Redis queue connection/names are defined by `backend/src/config/bullmqConfig.ts` and `backend/src/config/queueNames.ts`.

#### Query, Automation, and OpenAPI Boundary
Express routes expose upload state, paged/searchable analysis data, sanitization, AI, operations, and stable automation endpoints. Core route groups are `backend/src/routes/harRoutes.ts`, `backend/src/routes/consoleLogRoutes.ts`, and `backend/src/routes/automationRoutes.ts`. `backend/src/openapiSpec.ts` publishes the OpenAPI contract for internal/OCI clients. The frontend does not need raw full-file parsing for normal hosted workflows; it consumes persisted API results and progressive previews.

#### Deterministic and AI Insight Pipeline
Client-side analyzers support local display and investigation logic, including `src/utils/harAnalyzer.ts`, `src/utils/consoleLogAnalyzer.ts`, and `src/utils/requestFlowAnalyzer.ts`. Backend automation builds bounded HAR evidence in `backend/src/services/harAutomationService.ts`; AI routes invoke configured OpenAI-compatible endpoints via `backend/src/routes/aiRoutes.ts` and track usage through `backend/src/services/aiUsageService.ts`. AI is optional: deterministic evidence/fallbacks remain authoritative when provider configuration or output is unavailable.

#### Runtime, Deployment, and Operational Boundaries
Node.js 22 hosts React/Vite development plus separate Express API and BullMQ worker processes. PostgreSQL stores metadata, parsed entries, and AI usage; Redis provides queues, progress, pub/sub, and worker coordination; artifact storage is local filesystem or OCI Object Storage. Local dependencies run via `backend/docker-compose.yml`. Hosted builds split application and worker images under `deploy/hosted/Dockerfile.combined` and `deploy/hosted/Dockerfile.worker`; the current VM process model is documented in `VM_RUNBOOK.md`. Readiness, operational status, error handling, and retention are represented by `backend/src/routes/opsRoutes.ts`, `backend/src/middleware/errorHandler.ts`, and `backend/src/services/retentionCleanupService.ts`.

Main entry points: [`backend/src/server.ts`](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/server.ts) (Express API), [`src/hooks/useHarData.ts`](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/hooks/useHarData.ts) (Analysis state hooks), [`backend/src/routes/uploadRoutes.ts`](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/uploadRoutes.ts) (Upload endpoints), [`backend/src/persistence/postgresStore.ts`](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/persistence/postgresStore.ts) (PostgreSQL records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser workspace"]
  node_app["React application<br/>React/Vite<br/>[App.tsx]"]
  node_data_hooks["Analysis state hooks<br/>React hooks<br/>[useHarData.ts]"]
  node_api_client["API client<br/>REST client<br/>[apiClient.ts]"]
  node_socket_client["Socket client<br/>Socket.IO client<br/>[websocketClient.ts]"]
  node_uploader["Chunked uploader<br/>browser upload<br/>[chunkedUploader.ts]"]
  node_result_surfaces["Result and AI surfaces<br/>React components<br/>[HarTabContent.tsx]"]
end

subgraph group_api["API and realtime"]
  node_express_api["Express API<br/>Node.js server<br/>[server.ts]"]
  node_upload_routes["Upload endpoints<br/>Express routes<br/>[uploadRoutes.ts]"]
  node_analysis_routes["Analysis and automation API<br/>Express routes<br/>[harRoutes.ts]"]
  node_socket_gateway["Socket progress gateway<br/>Socket.IO<br/>[socketHelper.ts]"]
  node_openapi["OpenAPI contract<br/>API specification<br/>[openapiSpec.ts]"]
end

subgraph group_processing["Background processing"]
  node_worker["BullMQ worker runtime<br/>Node.js worker<br/>[worker.ts]"]
  node_processors["HAR and log processors<br/>worker processors<br/>[harProcessor.ts]"]
end

subgraph group_insights["Analysis and AI"]
  node_automation["HAR evidence builder<br/>automation service"]
  node_ai_routes["Optional AI insights<br/>AI routes<br/>[aiRoutes.ts]"]
end

subgraph group_infra["Storage and operations"]
  node_artifact_store[("Artifact store<br/>source storage<br/>[artifactStore.ts]")]
  node_postgres[("PostgreSQL records<br/>database<br/>[postgresStore.ts]")]
  node_redis["Redis and BullMQ<br/>queue and pub/sub<br/>[bullmqConfig.ts]"]
  node_ops["Operations and retention<br/>operational services<br/>[opsRoutes.ts]"]
end

node_app -->|"drives state"| node_data_hooks
node_app -->|"selects files"| node_uploader
node_data_hooks -->|"queries results"| node_api_client
node_data_hooks -->|"subscribes progress"| node_socket_client
node_data_hooks -->|"renders"| node_result_surfaces
node_uploader -->|"uploads chunks"| node_upload_routes
node_api_client -->|"REST"| node_express_api
node_socket_client -->|"Socket.IO"| node_socket_gateway
node_express_api -->|"hosts"| node_upload_routes
node_express_api -->|"hosts"| node_analysis_routes
node_express_api -->|"hosts"| node_ai_routes
node_express_api -->|"publishes"| node_openapi
node_upload_routes -->|"persists sources"| node_artifact_store
node_upload_routes -->|"enqueues job"| node_redis
node_worker -->|"consumes jobs"| node_redis
node_worker -->|"runs"| node_processors
node_processors -->|"reads sources"| node_artifact_store
node_processors -->|"persists records"| node_postgres
node_redis -->|"progress events"| node_socket_gateway
node_analysis_routes -->|"queries records"| node_postgres
node_analysis_routes -->|"builds evidence"| node_automation
node_ai_routes -->|"uses evidence"| node_automation
node_ai_routes -->|"tracks usage"| node_postgres
node_ops -->|"checks and cleans"| node_postgres
node_ops -->|"retention cleanup"| node_artifact_store

click node_app "https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/App.tsx"
click node_data_hooks "https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/hooks/useHarData.ts"
click node_api_client "https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/services/apiClient.ts"
click node_socket_client "https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/services/websocketClient.ts"
click node_uploader "https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/services/chunkedUploader.ts"
click node_result_surfaces "https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/components/HarTabContent.tsx"
click node_express_api "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/server.ts"
click node_upload_routes "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/uploadRoutes.ts"
click node_analysis_routes "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/harRoutes.ts"
click node_socket_gateway "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/utils/socketHelper.ts"
click node_openapi "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/openapiSpec.ts"
click node_worker "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/worker.ts"
click node_processors "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/workers/harProcessor.ts"
click node_artifact_store "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/services/artifactStore.ts"
click node_postgres "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/persistence/postgresStore.ts"
click node_redis "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/config/bullmqConfig.ts"
click node_automation "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/services/harAutomationService.ts"
click node_ai_routes "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/aiRoutes.ts"
click node_ops "https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/opsRoutes.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_app,node_data_hooks,node_api_client,node_socket_client,node_uploader,node_result_surfaces toneBlue
class node_express_api,node_upload_routes,node_analysis_routes,node_socket_gateway,node_openapi toneAmber
class node_worker,node_processors toneMint
class node_automation,node_ai_routes toneRose
class node_artifact_store,node_postgres,node_redis,node_ops toneIndigo
```

## Components

### Browser workspace

- [React application](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/App.tsx): React/Vite · Interactive analysis workspace. · `src/App.tsx`
- [Analysis state hooks](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/hooks/useHarData.ts): React hooks · Coordinate HAR and console result state. · `src/hooks/useHarData.ts`
- [API client](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/services/apiClient.ts): REST client · `src/services/apiClient.ts`
- [Socket client](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/services/websocketClient.ts): Socket.IO client · `src/services/websocketClient.ts`
- [Chunked uploader](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/services/chunkedUploader.ts): browser upload · Validates and sends file chunks. · `src/services/chunkedUploader.ts`
- [Result and AI surfaces](https://github.com/swarnim-sawane/har-file-analyser/blob/main/src/components/HarTabContent.tsx): React components · HAR, console, and AI result views. · `src/components/HarTabContent.tsx`

### API and realtime

- [Express API](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/server.ts): Node.js server · REST, Socket.IO, and route host. · `backend/src/server.ts`
- [Upload endpoints](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/uploadRoutes.ts): Express routes · `backend/src/routes/uploadRoutes.ts`
- [Analysis and automation API](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/harRoutes.ts): Express routes · HAR, console, and stable automation endpoints. · `backend/src/routes/harRoutes.ts`
- [Socket progress gateway](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/utils/socketHelper.ts): Socket.IO · `backend/src/utils/socketHelper.ts`
- [OpenAPI contract](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/openapiSpec.ts): API specification · `backend/src/openapiSpec.ts`

### Background processing

- [BullMQ worker runtime](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/worker.ts): Node.js worker · Consumes asynchronous upload jobs. · `backend/src/worker.ts`
- [HAR and log processors](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/workers/harProcessor.ts): worker processors · Parse source artifacts into records. · `backend/src/workers/harProcessor.ts`

### Analysis and AI

- [HAR evidence builder](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/services/harAutomationService.ts): automation service · Builds bounded deterministic evidence. · `backend/src/services/harAutomationService.ts`
- [Optional AI insights](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/aiRoutes.ts): AI routes · Uses configured OpenAI-compatible providers with usage tracking. · `backend/src/routes/aiRoutes.ts`

### Storage and operations

- [Artifact store](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/services/artifactStore.ts): source storage · Local filesystem or OCI Object Storage. · `backend/src/services/artifactStore.ts`
- [PostgreSQL records](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/persistence/postgresStore.ts): database · Metadata, parsed entries, and AI usage. · `backend/src/persistence/postgresStore.ts`
- [Redis and BullMQ](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/config/bullmqConfig.ts): queue and pub/sub · Jobs, progress, and worker coordination. · `backend/src/config/bullmqConfig.ts`
- [Operations and retention](https://github.com/swarnim-sawane/har-file-analyser/blob/main/backend/src/routes/opsRoutes.ts): operational services · Readiness, status, errors, and cleanup. · `backend/src/routes/opsRoutes.ts`

## Connections

- React application → Analysis state hooks: drives state
- React application → Chunked uploader: selects files
- Analysis state hooks → API client: queries results
- Analysis state hooks → Socket client: subscribes progress
- Analysis state hooks → Result and AI surfaces: renders
- Chunked uploader → Upload endpoints: uploads chunks
- API client → Express API: REST
- Socket client → Socket progress gateway: Socket.IO
- Express API → Upload endpoints: hosts
- Express API → Analysis and automation API: hosts
- Express API → Optional AI insights: hosts
- Express API → OpenAPI contract: publishes
- Upload endpoints → Artifact store: persists sources
- Upload endpoints → Redis and BullMQ: enqueues job
- BullMQ worker runtime → Redis and BullMQ: consumes jobs
- BullMQ worker runtime → HAR and log processors: runs
- HAR and log processors → Artifact store: reads sources
- HAR and log processors → PostgreSQL records: persists records
- Redis and BullMQ → Socket progress gateway: progress events
- Analysis and automation API → PostgreSQL records: queries records
- Analysis and automation API → HAR evidence builder: builds evidence
- Optional AI insights → HAR evidence builder: uses evidence
- Optional AI insights → PostgreSQL records: tracks usage
- Operations and retention → PostgreSQL records: checks and cleans
- Operations and retention → Artifact store: retention cleanup
