# redx0476/test_assignment architecture

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

- Interactive diagram: https://gitdiagram.com/redx0476/test_assignment
- Repository: https://github.com/redx0476/test_assignment

## Overview

Result Analyzer accepts MSM test-result submissions, stores them, and turns the accumulated results into daily statistics and scheduled monthly averages. Users can view daily and monthly reports. The README documents the endpoint, schedule, and calculation rules; sampled source confirms the monthly calculation and reporting-controller reads, but the API controller, EOD implementation, and recurring-task configuration are not in the supplied tree, so their internal wiring is shown only where documented.

Main entry points: [`app/services/eod/calculate_daily_statistics.rb`](https://github.com/redx0476/test_assignment/blob/main/app/services/eod/calculate_daily_statistics.rb) (Daily aggregation), [`app/jobs/monthly_averages_job.rb`](https://github.com/redx0476/test_assignment/blob/main/app/jobs/monthly_averages_job.rb) (Monthly job), [`app/services/monthly/calculate_averages.rb`](https://github.com/redx0476/test_assignment/blob/main/app/services/monthly/calculate_averages.rb) (Monthly averaging), [`app/models/daily_result_statistic.rb`](https://github.com/redx0476/test_assignment/blob/main/app/models/daily_result_statistic.rb) (Daily statistics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Result ingestion"]
  node_api["Ingestion API"]
  node_ingestion["Store result"]
end

subgraph group_compute["Scheduled calculations"]
  node_eod_job["EOD job"]
  node_daily_calc["Daily aggregation"]
  node_monthly_job["Monthly job"]
  node_trigger_date["Trigger-date guard<br/>[trigger_date.rb]"]
  node_monthly_calc["Monthly averaging"]
end

subgraph group_storage["Persistence"]
  node_test_results[("Test results")]
  node_daily_stats[("Daily statistics")]
  node_monthly_stats[("Monthly averages")]
end

subgraph group_reports["Reports"]
  node_dashboard["Dashboard"]
  node_daily_report["Daily report"]
  node_monthly_report["Monthly report"]
end

node_msm(("MSM service"))
node_scheduler["Recurring scheduler"]
node_user(("Report user"))

node_msm -->|"submits JSON"| node_api
node_api -->|"delegates validation"| node_ingestion
node_ingestion -->|"persists result"| node_test_results
node_scheduler -.->|"dispatches daily"| node_eod_job
node_eod_job -->|"runs aggregation"| node_daily_calc
node_daily_calc -->|"reads results"| node_test_results
node_daily_calc -->|"writes statistics"| node_daily_stats
node_scheduler -.->|"dispatches daily"| node_monthly_job
node_monthly_job -->|"checks date"| node_trigger_date
node_monthly_job -->|"runs when due"| node_monthly_calc
node_monthly_calc -->|"reads history"| node_daily_stats
node_monthly_calc -->|"upserts averages"| node_monthly_stats
node_user -->|"requests page"| node_dashboard
node_user -->|"requests report"| node_daily_report
node_user -->|"requests report"| node_monthly_report
node_daily_report -->|"reads statistics"| node_daily_stats
node_monthly_report -->|"reads averages"| node_monthly_stats

click node_api "https://github.com/redx0476/test_assignment/tree/main/app/controllers"
click node_ingestion "https://github.com/redx0476/test_assignment/blob/main/app/services/ingestion/create_test_result.rb"
click node_test_results "https://github.com/redx0476/test_assignment/tree/main/app/models"
click node_eod_job "https://github.com/redx0476/test_assignment/blob/main/app/jobs/eod_statistics_job.rb"
click node_daily_calc "https://github.com/redx0476/test_assignment/blob/main/app/services/eod/calculate_daily_statistics.rb"
click node_daily_stats "https://github.com/redx0476/test_assignment/blob/main/app/models/daily_result_statistic.rb"
click node_monthly_job "https://github.com/redx0476/test_assignment/blob/main/app/jobs/monthly_averages_job.rb"
click node_trigger_date "https://github.com/redx0476/test_assignment/blob/main/app/services/monthly/trigger_date.rb"
click node_monthly_calc "https://github.com/redx0476/test_assignment/blob/main/app/services/monthly/calculate_averages.rb"
click node_monthly_stats "https://github.com/redx0476/test_assignment/blob/main/app/models/monthly_result_average.rb"
click node_dashboard "https://github.com/redx0476/test_assignment/blob/main/app/controllers/dashboard_controller.rb"
click node_daily_report "https://github.com/redx0476/test_assignment/blob/main/app/controllers/daily_statistics_controller.rb"
click node_monthly_report "https://github.com/redx0476/test_assignment/blob/main/app/controllers/monthly_averages_controller.rb"

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_ingestion,node_user toneBlue
class node_eod_job,node_daily_calc,node_monthly_job,node_trigger_date,node_monthly_calc toneAmber
class node_test_results,node_daily_stats,node_monthly_stats toneMint
class node_dashboard,node_daily_report,node_monthly_report,node_scheduler toneRose
class node_msm toneIndigo
```

## Components

### Result ingestion

- [Ingestion API](https://github.com/redx0476/test_assignment/tree/main/app/controllers): `app/controllers`
- [Store result](https://github.com/redx0476/test_assignment/blob/main/app/services/ingestion/create_test_result.rb): `app/services/ingestion/create_test_result.rb`

### Scheduled calculations

- [EOD job](https://github.com/redx0476/test_assignment/blob/main/app/jobs/eod_statistics_job.rb): `app/jobs/eod_statistics_job.rb`
- [Daily aggregation](https://github.com/redx0476/test_assignment/blob/main/app/services/eod/calculate_daily_statistics.rb): `app/services/eod/calculate_daily_statistics.rb`
- [Monthly job](https://github.com/redx0476/test_assignment/blob/main/app/jobs/monthly_averages_job.rb): `app/jobs/monthly_averages_job.rb`
- [Trigger-date guard](https://github.com/redx0476/test_assignment/blob/main/app/services/monthly/trigger_date.rb): `app/services/monthly/trigger_date.rb`
- [Monthly averaging](https://github.com/redx0476/test_assignment/blob/main/app/services/monthly/calculate_averages.rb): `app/services/monthly/calculate_averages.rb`

### Persistence

- [Test results](https://github.com/redx0476/test_assignment/tree/main/app/models): `app/models`
- [Daily statistics](https://github.com/redx0476/test_assignment/blob/main/app/models/daily_result_statistic.rb): `app/models/daily_result_statistic.rb`
- [Monthly averages](https://github.com/redx0476/test_assignment/blob/main/app/models/monthly_result_average.rb): `app/models/monthly_result_average.rb`

### Reports

- [Dashboard](https://github.com/redx0476/test_assignment/blob/main/app/controllers/dashboard_controller.rb): `app/controllers/dashboard_controller.rb`
- [Daily report](https://github.com/redx0476/test_assignment/blob/main/app/controllers/daily_statistics_controller.rb): `app/controllers/daily_statistics_controller.rb`
- [Monthly report](https://github.com/redx0476/test_assignment/blob/main/app/controllers/monthly_averages_controller.rb): `app/controllers/monthly_averages_controller.rb`

### Other components

- **MSM service**
- **Recurring scheduler**
- **Report user**

## Connections

- MSM service → Ingestion API: submits JSON
- Ingestion API → Store result: delegates validation
- Store result → Test results: persists result
- Recurring scheduler → EOD job: dispatches daily
- EOD job → Daily aggregation: runs aggregation
- Daily aggregation → Test results: reads results
- Daily aggregation → Daily statistics: writes statistics
- Recurring scheduler → Monthly job: dispatches daily
- Monthly job → Trigger-date guard: checks date
- Monthly job → Monthly averaging: runs when due
- Monthly averaging → Daily statistics: reads history
- Monthly averaging → Monthly averages: upserts averages
- Report user → Dashboard: requests page
- Report user → Daily report: requests report
- Report user → Monthly report: requests report
- Daily report → Daily statistics: reads statistics
- Monthly report → Monthly averages: reads averages
