# ai-scm/slascalculator architecture

> Architecture diagram of the GitHub repository ai-scm/slascalculator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ai-scm/slascalculator
- Repository: https://github.com/ai-scm/slascalculator

## Overview

1. **What this system is**
   - A split frontend/backend application for SLA reporting on **Zammad** tickets.
   - Core job: read ticket data from **Zammad PostgreSQL**, compute SLA metrics, show them in a dashboard, and export flattened datasets for AWS analytics.

2. **Top-level boundaries**
   - **Frontend**: React app built with Vite.
   - **Backend**: Node.js + Express API.
   - **External data/config stores**: Zammad PostgreSQL, DynamoDB for project/team configuration, and AWS S3/Glue/QuickSight for the reporting pipeline.

3. **User-facing path**
   - The browser loads the React dashboard.
   - The frontend calls the backend through `frontend/src/services/api.js`.
   - Main dashboard concerns are metrics, ticket tables, charts, filtering, ticket detail modals, and SLA progress visualization.

4. **Frontend structure**
   - `AppContext` holds shared UI state.
   - `pages/Dashboard.jsx` is the main screen.
   - Reusable UI is grouped into common components, filter controls, metric cards, chart components, tables, and modals.
   - This looks like a single-page reporting UI rather than a multi-route product.

5. **Backend API layer**
   - Express routes are split into `routes/api.js` and `routes/admin.js`.
   - The main public entrypoint is `POST /api/metrics`.
   - A separate export endpoint, `POST /api/export/quicksight`, serves data in a flattened shape for downstream AWS ingestion.

6. **Business logic layer**
   - SLA computation is centralized in `services/slaService.js`.
   - Working-time rules are handled by `services/workingHoursService.js`.
   - Excel export is handled separately in `services/excelService.js`.
   - The backend separates transport concerns from metric/SLA calculation concerns.

7. **Primary data source**
   - The authoritative operational data comes from **Zammad PostgreSQL**.
   - `backend/config/database.js` and related config files define access.
   - The backend queries ticket and timeline data, then transforms it into the SLA-oriented shapes used by the API and exports.

8. **Dynamic configuration in DynamoDB**
   - Two DynamoDB tables drive runtime configuration:
     - `sla-reporter-projects` for project/client SLA calendars and thresholds.
     - `sla-reporter-teams` for team-to-agent mappings.
   - This lets SLA rules change without code changes.
   - If a project is missing, the SLA service falls back to hardcoded defaults.

9. **SLA rule model**
   - Calendars supported are `laboral`, `continuo`, and `24x7`.
   - Project-specific `sla_targets` determine first-response and resolution thresholds by ticket type and priority.
   - Team filtering is based on explicit agent IDs, which matters because agents can belong to more than one team.

10. **Scheduled export pipeline**
    - `backend/cron/cron-scheduler.js` and `sla-exporter-cron.js` run the reporting export on a schedule.
    - The export produces multiple datasets, not just a single table: tickets, ticket timeline, summary, by-agent, by-organization, by-type, and metadata.
    - Those outputs are meant for AWS analytics rather than the dashboard itself.

11. **AWS analytics path**
    - The cron export writes Parquet into **S3**.
    - A **Glue Crawler** discovers or refreshes the schema in the **Glue Data Catalog**.
    - **Athena** and then **QuickSight** consume those tables for BI-style reporting.
    - This is a separate downstream reporting path from the interactive frontend.

12. **Deployment/runtime shape**
    - Production is documented as running on a single **EC2** instance with Node.js directly, exposed on port 443.
    - The server can serve the frontend as well, depending on `SERVE_FRONTEND`.
    - AWS infrastructure for the analytics pipeline is provisioned separately via scripts under `aws/`.

13. **Local and operational tooling**
    - There are seed scripts for DynamoDB project/team data.
    - `docker-compose.yml` and `backend/Dockerfile` support containerized builds, but the documented production setup is direct Node on EC2.
    - `DATABASE_DICTIONARY.md` documents the source schema used by the backend queries.

14. **Architectural summary**
    - The repo is organized around a **reporting pipeline**: Zammad DB + DynamoDB config in, SLA calculations in the backend, interactive charts/tables in the frontend, and scheduled exports to S3/Glue/QuickSight for enterprise BI.

Main entry points: [`frontend/src/pages/Dashboard.jsx`](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/pages/Dashboard.jsx) (Dashboard), [`backend/services/slaService.js`](https://github.com/ai-scm/slascalculator/blob/main/backend/services/slaService.js) (SLA Service), [`backend/cron/sla-exporter-cron.js`](https://github.com/ai-scm/slascalculator/blob/main/backend/cron/sla-exporter-cron.js) (SLA Exporter), [`frontend/src/App.jsx`](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/App.jsx) (App Shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("Browser UI<br/>client<br/>[index.html]"))
  node_app["App Shell<br/>react app<br/>[App.jsx]"]
  node_context["App Context<br/>state<br/>[AppContext.jsx]"]
  node_dashboard["Dashboard<br/>screen<br/>[Dashboard.jsx]"]
  node_api_client["API Client<br/>http client<br/>[api.js]"]
  node_filters["Filters<br/>ui controls<br/>[FilterPanel.jsx]"]
  node_metrics_ui["Metrics UI<br/>ui widgets<br/>[MetricCard.jsx]"]
  node_charts["Charts<br/>visualization<br/>[SLATrendChart.jsx]"]
  node_tables["Tickets Table<br/>[TicketsTable.jsx]"]
  node_modal["Ticket Modal<br/>detail view"]
end

subgraph group_backend["Backend"]
  node_server["Node Server<br/>express server<br/>[server.js]"]
  node_api_routes["API Routes<br/>[api.js]"]
  node_admin_routes["Admin Routes<br/>[admin.js]"]
  node_sla_service["SLA Service<br/>business logic<br/>[slaService.js]"]
  node_hours_service["Working Hours<br/>rules engine"]
  node_dynamo_service["Dynamo Service<br/>config store<br/>[dynamoService.js]"]
  node_cron["Cron Scheduler<br/>job runner<br/>[cron-scheduler.js]"]
  node_exporter["SLA Exporter<br/>pipeline job"]
end

subgraph group_analytics["AWS Analytics"]
  node_s3[("S3 Parquet<br/>object storage<br/>[cloudformation.yml]")]
  node_glue["Glue Catalog<br/>data catalog<br/>[cloudformation.yml]"]
  node_athena_qs["Athena/QuickSight<br/>bi analytics<br/>[cloudformation.yml]"]
end

subgraph group_external["External Data"]
  node_zammad_db[("Zammad DB<br/>postgresql<br/>[database.js]")]
  node_dynamodb[("DynamoDB<br/>config tables<br/>[dynamodb.js]")]
end

node_browser -->|"loads"| node_app
node_app -->|"uses"| node_context
node_app -->|"renders"| node_dashboard
node_dashboard -->|"fetches"| node_api_client
node_dashboard -->|"contains"| node_filters
node_dashboard -->|"shows"| node_metrics_ui
node_dashboard -->|"shows"| node_charts
node_dashboard -->|"shows"| node_tables
node_tables -->|"opens"| node_modal
node_server -->|"mounts"| node_api_routes
node_server -->|"mounts"| node_admin_routes
node_api_routes -->|"invokes"| node_sla_service
node_sla_service -->|"applies"| node_hours_service
node_sla_service -->|"loads config"| node_dynamo_service
node_sla_service -->|"queries"| node_zammad_db
node_cron -->|"runs"| node_exporter
node_exporter -->|"reuses"| node_sla_service
node_exporter -->|"reads"| node_zammad_db
node_exporter -->|"writes"| node_s3
node_s3 -->|"cataloged by"| node_glue
node_glue -->|"consumed by"| node_athena_qs
node_dynamo_service -->|"reads"| node_dynamodb
node_api_client -->|"calls"| node_api_routes

click node_browser "https://github.com/ai-scm/slascalculator/blob/main/frontend/index.html"
click node_app "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/App.jsx"
click node_context "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/context/AppContext.jsx"
click node_dashboard "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/pages/Dashboard.jsx"
click node_api_client "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/services/api.js"
click node_filters "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/filters/FilterPanel.jsx"
click node_metrics_ui "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/metrics/MetricCard.jsx"
click node_charts "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/charts/SLATrendChart.jsx"
click node_tables "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/tables/TicketsTable.jsx"
click node_modal "https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/modals/TicketDetailModal.jsx"
click node_server "https://github.com/ai-scm/slascalculator/blob/main/backend/server.js"
click node_api_routes "https://github.com/ai-scm/slascalculator/blob/main/backend/routes/api.js"
click node_admin_routes "https://github.com/ai-scm/slascalculator/blob/main/backend/routes/admin.js"
click node_sla_service "https://github.com/ai-scm/slascalculator/blob/main/backend/services/slaService.js"
click node_hours_service "https://github.com/ai-scm/slascalculator/blob/main/backend/services/workingHoursService.js"
click node_dynamo_service "https://github.com/ai-scm/slascalculator/blob/main/backend/services/dynamoService.js"
click node_cron "https://github.com/ai-scm/slascalculator/blob/main/backend/cron/cron-scheduler.js"
click node_exporter "https://github.com/ai-scm/slascalculator/blob/main/backend/cron/sla-exporter-cron.js"
click node_zammad_db "https://github.com/ai-scm/slascalculator/blob/main/backend/config/database.js"
click node_dynamodb "https://github.com/ai-scm/slascalculator/blob/main/backend/config/dynamodb.js"
click node_s3 "https://github.com/ai-scm/slascalculator/blob/main/aws/cloudformation.yml"
click node_glue "https://github.com/ai-scm/slascalculator/blob/main/aws/cloudformation.yml"
click node_athena_qs "https://github.com/ai-scm/slascalculator/blob/main/aws/cloudformation.yml"

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_browser,node_app,node_context,node_dashboard,node_api_client,node_filters,node_metrics_ui,node_charts,node_tables,node_modal toneBlue
class node_server,node_api_routes,node_admin_routes,node_sla_service,node_hours_service,node_dynamo_service,node_cron,node_exporter toneAmber
class node_s3,node_glue,node_athena_qs toneMint
class node_zammad_db,node_dynamodb toneRose
```

## Components

### Frontend

React/Vite dashboard for SLA reporting and ticket exploration

- [Browser UI](https://github.com/ai-scm/slascalculator/blob/main/frontend/index.html): client · User-facing dashboard entrypoint · `frontend/index.html`
- [App Shell](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/App.jsx): react app · Bootstraps the SPA and shared UI context · `frontend/src/App.jsx`
- [App Context](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/context/AppContext.jsx): state · Shared dashboard state and selections · `frontend/src/context/AppContext.jsx`
- [Dashboard](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/pages/Dashboard.jsx): screen · Main SLA reporting screen · `frontend/src/pages/Dashboard.jsx`
- [API Client](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/services/api.js): http client · Frontend-to-backend service wrapper · `frontend/src/services/api.js`
- [Filters](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/filters/FilterPanel.jsx): ui controls · Filter panel and calendar selection · `frontend/src/components/filters/FilterPanel.jsx`
- [Metrics UI](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/metrics/MetricCard.jsx): ui widgets · Metric cards and SLA progress display · `frontend/src/components/metrics/MetricCard.jsx`
- [Charts](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/charts/SLATrendChart.jsx): visualization · Trend and distribution charts · `frontend/src/components/charts/SLATrendChart.jsx`
- [Tickets Table](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/tables/TicketsTable.jsx): table · Ticket listing and drill-down table · `frontend/src/components/tables/TicketsTable.jsx`
- [Ticket Modal](https://github.com/ai-scm/slascalculator/blob/main/frontend/src/components/modals/TicketDetailModal.jsx): detail view · Ticket detail and auxiliary modals · `frontend/src/components/modals/TicketDetailModal.jsx`

### Backend

Express API, SLA computation, exports, and scheduled jobs

- [Node Server](https://github.com/ai-scm/slascalculator/blob/main/backend/server.js): express server · Runtime host for API and optional SPA serving · `backend/server.js`
- [API Routes](https://github.com/ai-scm/slascalculator/blob/main/backend/routes/api.js): routes · Public metrics and export endpoints · `backend/routes/api.js`
- [Admin Routes](https://github.com/ai-scm/slascalculator/blob/main/backend/routes/admin.js): routes · Administrative endpoints · `backend/routes/admin.js`
- [SLA Service](https://github.com/ai-scm/slascalculator/blob/main/backend/services/slaService.js): business logic · Central SLA computation and ticket shaping · `backend/services/slaService.js`
- [Working Hours](https://github.com/ai-scm/slascalculator/blob/main/backend/services/workingHoursService.js): rules engine · Working-time and calendar rules · `backend/services/workingHoursService.js`
- [Dynamo Service](https://github.com/ai-scm/slascalculator/blob/main/backend/services/dynamoService.js): config store · Loads project and team configuration from DynamoDB · `backend/services/dynamoService.js`
- [Cron Scheduler](https://github.com/ai-scm/slascalculator/blob/main/backend/cron/cron-scheduler.js): job runner · Scheduled export orchestration · `backend/cron/cron-scheduler.js`
- [SLA Exporter](https://github.com/ai-scm/slascalculator/blob/main/backend/cron/sla-exporter-cron.js): pipeline job · Builds flattened datasets for analytics · `backend/cron/sla-exporter-cron.js`

### AWS Analytics

Downstream reporting pipeline for exported datasets

- [S3 Parquet](https://github.com/ai-scm/slascalculator/blob/main/aws/cloudformation.yml): object storage · Export landing zone for analytics datasets · `aws/cloudformation.yml`
- [Glue Catalog](https://github.com/ai-scm/slascalculator/blob/main/aws/cloudformation.yml): data catalog · Schema discovery and table registration · `aws/cloudformation.yml`
- [Athena/QuickSight](https://github.com/ai-scm/slascalculator/blob/main/aws/cloudformation.yml): bi analytics · Query and dashboard layer for exported data · `aws/cloudformation.yml`

### External Data

Operational and configuration data sources

- [Zammad DB](https://github.com/ai-scm/slascalculator/blob/main/backend/config/database.js): postgresql · Operational ticket and timeline source · `backend/config/database.js`
- [DynamoDB](https://github.com/ai-scm/slascalculator/blob/main/backend/config/dynamodb.js): config tables · Project and team SLA configuration · `backend/config/dynamodb.js`

## Connections

- Browser UI → App Shell: loads · Browser loads the SPA shell
- App Shell → App Context: uses · App shell provides shared state
- App Shell → Dashboard: renders · Main screen is the dashboard
- Dashboard → API Client: fetches · Dashboard requests metrics and exports
- Dashboard → Filters: contains · Dashboard includes filter controls
- Dashboard → Metrics UI: shows · Dashboard shows KPI and SLA widgets
- Dashboard → Charts: shows · Dashboard shows charts
- Dashboard → Tickets Table: shows · Dashboard shows ticket tables
- Tickets Table → Ticket Modal: opens · Ticket rows open detail modals
- Node Server → API Routes: mounts · Express mounts public API routes
- Node Server → Admin Routes: mounts · Express mounts admin routes
- API Routes → SLA Service: invokes · Metrics and export endpoints use SLA logic
- SLA Service → Working Hours: applies · SLA computation uses working-time rules
- SLA Service → Dynamo Service: loads config · Project and team settings come from DynamoDB
- SLA Service → Zammad DB: queries · Operational data is read from Zammad PostgreSQL
- Cron Scheduler → SLA Exporter: runs · Scheduler triggers the export job
- SLA Exporter → SLA Service: reuses · Export pipeline reuses SLA shaping logic
- SLA Exporter → Zammad DB: reads · Export job reads source ticket data
- SLA Exporter → S3 Parquet: writes · Parquet datasets are written to S3
- S3 Parquet → Glue Catalog: cataloged by · Glue crawler refreshes table metadata
- Glue Catalog → Athena/QuickSight: consumed by · Athena and QuickSight query the cataloged data
- Dynamo Service → DynamoDB: reads · Runtime configuration is stored in DynamoDB
- API Client → API Routes: calls · Frontend service layer calls API endpoints
