# sam14334/grade-tracker-backend architecture

> Architecture diagram of the GitHub repository sam14334/grade-tracker-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sam14334/grade-tracker-backend
- Repository: https://github.com/sam14334/grade-tracker-backend

## Overview

This is a PHP grade-tracking API for students and professors. Students enroll in published courses, record assessment scores, and receive course-grade and dashboard analytics; professors create and manage course templates and enrollment codes. Authentication includes role checks and email OTP verification. The excerpts show controller-to-service calls and several service-to-repository/support calls; the README is empty, and route registration details are not shown, so the graph avoids guessing how routes connect to controllers.

Main entry points: [`src/services/auth_service.php`](https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/auth_service.php) (Authentication service), [`src/services/student_service.php`](https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/student_service.php) (Enrollment and grades), [`api/index.php`](https://github.com/sam14334/grade-tracker-backend/blob/main/api/index.php) (API entry), [`src/controllers/student_controller.php`](https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/student_controller.php) (Student endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_entry["API entry<br/>[index.php]"]
  node_route_defs["Route definitions<br/>[api.php]"]
  node_router["HTTP router<br/>[router.php]"]
  node_database["Database connector<br/>[database.php]"]
end

subgraph group_identity["Identity and email"]
  node_auth_controller["Auth endpoints"]
  node_auth_service["Authentication service<br/>[auth_service.php]"]
  node_session["Session and access<br/>[session.php]"]
  node_user_repo["User records"]
  node_otp_repo["OTP records<br/>[otp_repository.php]"]
  node_email_templates["OTP email content"]
  node_mailer["Email delivery<br/>[mailer.php]"]
  node_email_service["Email provider"]
end

subgraph group_courses["Course templates"]
  node_template_controller["Professor endpoints"]
  node_template_service["Template management"]
  node_template_repo["Template records"]
  node_template_form["Template form rules<br/>[template_form.php]"]
end

subgraph group_grading["Enrollment and grading"]
  node_student_controller["Student endpoints"]
  node_student_service["Enrollment and grades"]
  node_enrollment_repo["Enrollment records"]
  node_score_repo["Assessment scores"]
  node_components["Course components"]
  node_calculator["Grade calculator"]
  node_standing["Standing analytics"]
end

node_user(("Student or professor"))
node_postgres[("PostgreSQL")]

node_user -->|"requests API"| node_entry
node_entry -->|"loads routes"| node_route_defs
node_entry -->|"loads router"| node_router
node_entry -->|"loads connector"| node_database
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"uses session"| node_session
node_auth_service -->|"reads and creates users"| node_user_repo
node_auth_service -->|"manages OTP"| node_otp_repo
node_auth_service -->|"builds email"| node_email_templates
node_auth_service -->|"sends email"| node_mailer
node_mailer -.->|"delivers email"| node_email_service
node_template_controller -->|"calls"| node_template_service
node_template_service -->|"reads and writes"| node_template_repo
node_template_service -->|"validates form"| node_template_form
node_student_controller -->|"calls"| node_student_service
node_student_controller -->|"gets grade scale"| node_calculator
node_student_service -->|"reads and updates"| node_enrollment_repo
node_student_service -->|"loads and saves scores"| node_score_repo
node_student_service -->|"looks up templates"| node_template_repo
node_student_service -->|"loads components"| node_components
node_student_service -->|"calculates grades"| node_calculator
node_student_controller -.->|"computes analytics"| node_standing
node_database -->|"connects"| node_postgres

click node_entry "https://github.com/sam14334/grade-tracker-backend/blob/main/api/index.php"
click node_route_defs "https://github.com/sam14334/grade-tracker-backend/blob/main/routes/api.php"
click node_router "https://github.com/sam14334/grade-tracker-backend/blob/main/src/http/router.php"
click node_auth_controller "https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/auth_controller.php"
click node_auth_service "https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/auth_service.php"
click node_session "https://github.com/sam14334/grade-tracker-backend/blob/main/src/auth/session.php"
click node_user_repo "https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/user_repository.php"
click node_otp_repo "https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/otp_repository.php"
click node_email_templates "https://github.com/sam14334/grade-tracker-backend/blob/main/src/auth/email_templates.php"
click node_mailer "https://github.com/sam14334/grade-tracker-backend/blob/main/src/auth/mailer.php"
click node_template_controller "https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/template_controller.php"
click node_template_service "https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/template_service.php"
click node_template_repo "https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/template_repository.php"
click node_template_form "https://github.com/sam14334/grade-tracker-backend/blob/main/src/support/template_form.php"
click node_student_controller "https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/student_controller.php"
click node_student_service "https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/student_service.php"
click node_enrollment_repo "https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/enrollment_repository.php"
click node_score_repo "https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/score_repository.php"
click node_components "https://github.com/sam14334/grade-tracker-backend/blob/main/src/support/course_components.php"
click node_calculator "https://github.com/sam14334/grade-tracker-backend/blob/main/src/support/grade_calculator.php"
click node_standing "https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/standing_service.php"
click node_database "https://github.com/sam14334/grade-tracker-backend/blob/main/src/database.php"

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_entry,node_route_defs,node_router,node_database toneBlue
class node_auth_controller,node_auth_service,node_session,node_user_repo,node_otp_repo,node_email_templates,node_mailer,node_email_service,node_postgres toneAmber
class node_template_controller,node_template_service,node_template_repo,node_template_form toneMint
class node_student_controller,node_student_service,node_enrollment_repo,node_score_repo,node_components,node_calculator,node_standing toneRose
class node_user toneIndigo
```

## Components

### API and access

- [API entry](https://github.com/sam14334/grade-tracker-backend/blob/main/api/index.php): `api/index.php`
- [Route definitions](https://github.com/sam14334/grade-tracker-backend/blob/main/routes/api.php): `routes/api.php`
- [HTTP router](https://github.com/sam14334/grade-tracker-backend/blob/main/src/http/router.php): `src/http/router.php`
- [Database connector](https://github.com/sam14334/grade-tracker-backend/blob/main/src/database.php): `src/database.php`

### Identity and email

- [Auth endpoints](https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/auth_controller.php): `src/controllers/auth_controller.php`
- [Authentication service](https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/auth_service.php): `src/services/auth_service.php`
- [Session and access](https://github.com/sam14334/grade-tracker-backend/blob/main/src/auth/session.php): `src/auth/session.php`
- [User records](https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/user_repository.php): `src/repositories/user_repository.php`
- [OTP records](https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/otp_repository.php): `src/repositories/otp_repository.php`
- [OTP email content](https://github.com/sam14334/grade-tracker-backend/blob/main/src/auth/email_templates.php): `src/auth/email_templates.php`
- [Email delivery](https://github.com/sam14334/grade-tracker-backend/blob/main/src/auth/mailer.php): `src/auth/mailer.php`
- **Email provider**

### Course templates

- [Professor endpoints](https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/template_controller.php): `src/controllers/template_controller.php`
- [Template management](https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/template_service.php): `src/services/template_service.php`
- [Template records](https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/template_repository.php): `src/repositories/template_repository.php`
- [Template form rules](https://github.com/sam14334/grade-tracker-backend/blob/main/src/support/template_form.php): `src/support/template_form.php`

### Enrollment and grading

- [Student endpoints](https://github.com/sam14334/grade-tracker-backend/blob/main/src/controllers/student_controller.php): `src/controllers/student_controller.php`
- [Enrollment and grades](https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/student_service.php): `src/services/student_service.php`
- [Enrollment records](https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/enrollment_repository.php): `src/repositories/enrollment_repository.php`
- [Assessment scores](https://github.com/sam14334/grade-tracker-backend/blob/main/src/repositories/score_repository.php): `src/repositories/score_repository.php`
- [Course components](https://github.com/sam14334/grade-tracker-backend/blob/main/src/support/course_components.php): `src/support/course_components.php`
- [Grade calculator](https://github.com/sam14334/grade-tracker-backend/blob/main/src/support/grade_calculator.php): `src/support/grade_calculator.php`
- [Standing analytics](https://github.com/sam14334/grade-tracker-backend/blob/main/src/services/standing_service.php): `src/services/standing_service.php`

### Other components

- **Student or professor**
- **PostgreSQL**

## Connections

- Student or professor → API entry: requests API
- API entry → Route definitions: loads routes (evidence: `api/index.php`)
- API entry → HTTP router: loads router (evidence: `api/index.php`)
- API entry → Database connector: loads connector
- Auth endpoints → Authentication service: calls (evidence: `src/controllers/auth_controller.php`)
- Authentication service → Session and access: uses session (evidence: `src/services/auth_service.php`)
- Authentication service → User records: reads and creates users (evidence: `src/services/auth_service.php`)
- Authentication service → OTP records: manages OTP (evidence: `src/services/auth_service.php`)
- Authentication service → OTP email content: builds email (evidence: `src/services/auth_service.php`)
- Authentication service → Email delivery: sends email (evidence: `src/services/auth_service.php`)
- Email delivery → Email provider: delivers email
- Professor endpoints → Template management: calls (evidence: `src/controllers/template_controller.php`)
- Template management → Template records: reads and writes (evidence: `src/services/template_service.php`)
- Template management → Template form rules: validates form (evidence: `src/services/template_service.php`)
- Student endpoints → Enrollment and grades: calls (evidence: `src/controllers/student_controller.php`)
- Student endpoints → Grade calculator: gets grade scale (evidence: `src/controllers/student_controller.php`)
- Enrollment and grades → Enrollment records: reads and updates (evidence: `src/services/student_service.php`)
- Enrollment and grades → Assessment scores: loads and saves scores (evidence: `src/services/student_service.php`)
- Enrollment and grades → Template records: looks up templates (evidence: `src/services/student_service.php`)
- Enrollment and grades → Course components: loads components (evidence: `src/services/student_service.php`)
- Enrollment and grades → Grade calculator: calculates grades (evidence: `src/services/student_service.php`)
- Student endpoints → Standing analytics: computes analytics
- Database connector → PostgreSQL: connects (evidence: `src/database.php`)
