# mhd-muzammil/opencall_be architecture

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

- Interactive diagram: https://gitdiagram.com/mhd-muzammil/opencall_be
- Repository: https://github.com/mhd-muzammil/opencall_be

## Overview

Open Call is a standalone backend for a daily call-plan API, with shared analytics and types. The principal workflow is an API user submitting or selecting source records, previewing their matches, then using report and productivity endpoints; administration and operational features form additional branches. The sampled source supports the matching and engineer-target flows, but not every listed subsystem’s runtime wiring. Unverified subsystem links are therefore omitted, and the graph does not imply that adjacent features call one another.

Main entry points: [`backend/src/services/compareService/matchPreviewService.ts`](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/compareService/matchPreviewService.ts) (Match preview), [`backend/src/services/engineerTarget/engineerTargetService.ts`](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/engineerTarget/engineerTargetService.ts) (Target calculation), [`backend/src/controllers/engineerTargetController.ts`](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/controllers/engineerTargetController.ts) (Target endpoint), [`backend/src/services/engineers/engineerService.ts`](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/engineers/engineerService.ts) (Engineer admin)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_api["Backend API<br/>[app.ts]"]
  node_auth["Authentication<br/>[authMiddleware.ts]"]
  node_rbac["Region access"]
  node_admin["Engineer admin<br/>[engineerService.ts]"]
  node_engineer_controller["Engineer endpoints"]
  node_engineer_store[("Engineer records")]
end

subgraph group_matching["Upload and matching"]
  node_uploads["Record uploads<br/>[uploadService.ts]"]
  node_preview["Match preview"]
  node_matcher["Record matching<br/>[matchingEngine.ts]"]
  node_dedupe["Ticket deduplication"]
  node_source_records[("Source records")]
end

subgraph group_productivity["Productivity"]
  node_call_plan[("Call-plan reports")]
  node_target_routes["Engineer target routes"]
  node_target_controller["Target endpoint"]
  node_target_service["Target calculation"]
  node_analytics["Productivity analytics"]
  node_status_cache["Status bucket cache"]
end

subgraph group_operations["Operations"]
  node_postgres[("PostgreSQL<br/>[database.ts]")]
  node_closure["Closure reconciliation"]
  node_warranty["Warranty processing"]
  node_email["Email workflows"]
  node_geo["Geocoding services"]
  node_payroll["Payroll sync"]
end

node_user(("API user"))

node_user -->|"calls API"| node_api
node_engineer_controller -->|"calls service"| node_admin
node_admin -->|"reads and writes"| node_engineer_store
node_engineer_store -->|"queries"| node_postgres
node_target_routes -->|"routes to"| node_target_controller
node_target_controller -->|"calls"| node_target_service
node_target_controller -->|"checks regions"| node_rbac
node_target_service -->|"reads report rows"| node_call_plan
node_target_service -->|"computes productivity"| node_analytics
node_target_service -->|"loads buckets"| node_status_cache
node_preview -->|"loads records"| node_source_records
node_preview -->|"checks duplicates"| node_dedupe
node_preview -->|"matches records"| node_matcher
node_preview -->|"limits regions"| node_rbac
node_call_plan -->|"queries"| node_postgres

click node_api "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/app.ts"
click node_auth "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/middlewares/authMiddleware.ts"
click node_rbac "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/rbac/regionAccessService.ts"
click node_admin "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/engineers/engineerService.ts"
click node_engineer_controller "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/controllers/adminEngineerController.ts"
click node_engineer_store "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/repositories/engineerRepository.ts"
click node_uploads "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/uploadService.ts"
click node_preview "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/compareService/matchPreviewService.ts"
click node_matcher "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/compareService/matchingEngine.ts"
click node_dedupe "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/normalization/dedupeRowsByTicket.ts"
click node_source_records "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/repositories/sourceRecordRepository.ts"
click node_call_plan "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/repositories/dailyCallPlanReportRepository.ts"
click node_target_routes "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/routes/engineerTargetRoutes.ts"
click node_target_controller "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/controllers/engineerTargetController.ts"
click node_target_service "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/engineerTarget/engineerTargetService.ts"
click node_analytics "https://github.com/mhd-muzammil/opencall_be/blob/main/shared/src/analytics/engineerProductivity.ts"
click node_status_cache "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/rtplStatuses/statusBucketCache.ts"
click node_postgres "https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/config/database.ts"
click node_closure "https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/closureDates"
click node_warranty "https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/warranty"
click node_email "https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/inboundEmail"
click node_geo "https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/geo"
click node_payroll "https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/payroll"

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_api,node_auth,node_rbac,node_admin,node_engineer_controller,node_engineer_store,node_user toneBlue
class node_uploads,node_preview,node_matcher,node_dedupe,node_source_records toneAmber
class node_call_plan,node_target_routes,node_target_controller,node_target_service,node_analytics,node_status_cache toneMint
class node_postgres,node_closure,node_warranty,node_email,node_geo,node_payroll toneRose
```

## Components

### API and access

- [Backend API](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [Authentication](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/middlewares/authMiddleware.ts): `backend/src/middlewares/authMiddleware.ts`
- [Region access](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/rbac/regionAccessService.ts): `backend/src/services/rbac/regionAccessService.ts`
- [Engineer admin](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/engineers/engineerService.ts): `backend/src/services/engineers/engineerService.ts`
- [Engineer endpoints](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/controllers/adminEngineerController.ts): `backend/src/controllers/adminEngineerController.ts`
- [Engineer records](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/repositories/engineerRepository.ts): `backend/src/repositories/engineerRepository.ts`

### Upload and matching

- [Record uploads](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/uploadService.ts): `backend/src/services/uploadService.ts`
- [Match preview](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/compareService/matchPreviewService.ts): `backend/src/services/compareService/matchPreviewService.ts`
- [Record matching](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/compareService/matchingEngine.ts): `backend/src/services/compareService/matchingEngine.ts`
- [Ticket deduplication](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/normalization/dedupeRowsByTicket.ts): `backend/src/services/normalization/dedupeRowsByTicket.ts`
- [Source records](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/repositories/sourceRecordRepository.ts): `backend/src/repositories/sourceRecordRepository.ts`

### Productivity

- [Call-plan reports](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/repositories/dailyCallPlanReportRepository.ts): `backend/src/repositories/dailyCallPlanReportRepository.ts`
- [Engineer target routes](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/routes/engineerTargetRoutes.ts): `backend/src/routes/engineerTargetRoutes.ts`
- [Target endpoint](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/controllers/engineerTargetController.ts): `backend/src/controllers/engineerTargetController.ts`
- [Target calculation](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/engineerTarget/engineerTargetService.ts): `backend/src/services/engineerTarget/engineerTargetService.ts`
- [Productivity analytics](https://github.com/mhd-muzammil/opencall_be/blob/main/shared/src/analytics/engineerProductivity.ts): `shared/src/analytics/engineerProductivity.ts`
- [Status bucket cache](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/services/rtplStatuses/statusBucketCache.ts): `backend/src/services/rtplStatuses/statusBucketCache.ts`

### Operations

- [PostgreSQL](https://github.com/mhd-muzammil/opencall_be/blob/main/backend/src/config/database.ts): `backend/src/config/database.ts`
- [Closure reconciliation](https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/closureDates): `backend/src/services/closureDates`
- [Warranty processing](https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/warranty): `backend/src/services/warranty`
- [Email workflows](https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/inboundEmail): `backend/src/services/inboundEmail`
- [Geocoding services](https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/geo): `backend/src/services/geo`
- [Payroll sync](https://github.com/mhd-muzammil/opencall_be/tree/main/backend/src/services/payroll): `backend/src/services/payroll`

### Other components

- **API user**

## Connections

- API user → Backend API: calls API
- Engineer endpoints → Engineer admin: calls service (evidence: `backend/src/controllers/adminEngineerController.ts`)
- Engineer admin → Engineer records: reads and writes (evidence: `backend/src/services/engineers/engineerService.ts`)
- Engineer records → PostgreSQL: queries (evidence: `backend/src/repositories/engineerRepository.ts`)
- Engineer target routes → Target endpoint: routes to (evidence: `backend/src/routes/engineerTargetRoutes.ts`)
- Target endpoint → Target calculation: calls (evidence: `backend/src/controllers/engineerTargetController.ts`)
- Target endpoint → Region access: checks regions (evidence: `backend/src/controllers/engineerTargetController.ts`)
- Target calculation → Call-plan reports: reads report rows (evidence: `backend/src/services/engineerTarget/engineerTargetService.ts`)
- Target calculation → Productivity analytics: computes productivity (evidence: `backend/src/services/engineerTarget/engineerTargetService.ts`)
- Target calculation → Status bucket cache: loads buckets (evidence: `backend/src/services/engineerTarget/engineerTargetService.ts`)
- Match preview → Source records: loads records (evidence: `backend/src/services/compareService/matchPreviewService.ts`)
- Match preview → Ticket deduplication: checks duplicates (evidence: `backend/src/services/compareService/matchPreviewService.ts`)
- Match preview → Record matching: matches records (evidence: `backend/src/services/compareService/matchPreviewService.ts`)
- Match preview → Region access: limits regions (evidence: `backend/src/services/compareService/matchPreviewService.ts`)
- Call-plan reports → PostgreSQL: queries
