How ai-scm/slascalculator works
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: Dashboard.jsx Dashboard · slaService.js SLA Service · sla-exporter-cron.js SLA Exporter · App.jsx App Shell
Components 23
Frontend
React/Vite dashboard for SLA reporting and ticket exploration
- Browser UI · User-facing dashboard entrypoint
frontend/index.html - App Shell · Bootstraps the SPA and shared UI context
frontend/src/App.jsx - App Context · Shared dashboard state and selections
frontend/src/context/AppContext.jsx - Dashboard · Main SLA reporting screen
frontend/src/pages/Dashboard.jsx - API Client · Frontend-to-backend service wrapper
frontend/src/services/api.js - Filters · Filter panel and calendar selection
frontend/src/components/filters/FilterPanel.jsx - Metrics UI · Metric cards and SLA progress display
frontend/src/components/metrics/MetricCard.jsx - Charts · Trend and distribution charts
frontend/src/components/charts/SLATrendChart.jsx - Tickets Table · Ticket listing and drill-down table
frontend/src/components/tables/TicketsTable.jsx - Ticket Modal · Ticket detail and auxiliary modals
frontend/src/components/modals/TicketDetailModal.jsx
Backend
Express API, SLA computation, exports, and scheduled jobs
- Node Server · Runtime host for API and optional SPA serving
backend/server.js - API Routes · Public metrics and export endpoints
backend/routes/api.js - Admin Routes · Administrative endpoints
backend/routes/admin.js - SLA Service · Central SLA computation and ticket shaping
backend/services/slaService.js - Working Hours · Working-time and calendar rules
backend/services/workingHoursService.js - Dynamo Service · Loads project and team configuration from DynamoDB
backend/services/dynamoService.js - Cron Scheduler · Scheduled export orchestration
backend/cron/cron-scheduler.js - SLA Exporter · Builds flattened datasets for analytics
backend/cron/sla-exporter-cron.js
AWS Analytics
Downstream reporting pipeline for exported datasets
- S3 Parquet · Export landing zone for analytics datasets
aws/cloudformation.yml - Glue Catalog · Schema discovery and table registration
aws/cloudformation.yml - Athena/QuickSight · Query and dashboard layer for exported data
aws/cloudformation.yml
Connections 23
- 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