How hlum/understandme-server-side works
Purpose and entry points
KnowYourCode is a PHP HTTP API for classroom/homework workflows that generates code-comprehension questions, accepts student answers, scores results, and reports progress. Endpoint scripts under public/ are the API entry points, e.g. public/homework/add_homework.php, public/questions_choices/v2/get_questions_choices.php, and public/result/update_score.php.
Layered application structure
Endpoint scripts delegate business operations to application use cases, which depend on domain entities and repository interfaces rather than concrete storage/services. Core layers are src/Application/UseCases/, src/Domain/Entities/, and src/Domain/Repositories/. Concrete adapters reside in src/Infrastructure/.
Classroom, identity, and enrollment
Users have roles and participate in classes through enrollment records. Class management and enrollment are exposed independently, forming the authorization/context boundary for teacher/student work. Key paths: src/Application/UseCases/UserUseCase.php, src/Application/UseCases/ClassUseCase.php, src/Application/UseCases/StudentClassEnrollmentUseCase.php.
Homework and project lifecycle
Teachers create/update/delete classes, projects, and homework. Homework status is queried per user, and submitted work can be removed. This lifecycle is represented by Homework, Project, and status-oriented entities/use cases, with APIs under public/homework/ and public/project/add_project.php.
Question-generation job pipeline
Question creation is asynchronous: jobs are persisted, a cron container invokes pending-job processing, and retry is exposed via the API. Processing can download source material, extract snippets, and call a question generator before storing questions/choices. Key paths: Cron/process_pending_jobs.php, src/Application/UseCases/ProcessPendingJobsUseCase.php, src/Application/UseCases/JobUseCase.php.
Source acquisition and AI generation boundary
Source inputs may come from GitHub or Google Drive through a downloader factory; repository URLs and file types are validated before content reaches generation. Ollama is the external LLM endpoint behind QuestionGeneratorInterface; generated questions/choices are then available through versioned retrieval APIs. Key paths: src/Infrastructure/ExternalServices/DownloaderFactory.php, src/Infrastructure/ExternalServices/OllamaQuestionGenerator.php, src/Domain/Repositories/QuestionGeneratorInterface.php.
Assessment and reporting
Students submit answers; correct choices, results, average scores, and homework completion status are persisted and queried separately. Score updates are explicit API operations, enabling generation/assessment to remain decoupled. Key paths: src/Application/UseCases/AnswerUseCase.php, src/Application/UseCases/ResultUseCase.php, src/Application/UseCases/AverageScoreUseCase.php.
Runtime, persistence, and notifications
Docker Compose runs PHP/Apache, MySQL, and the cron worker; schema initialization is in mysqlEntry/create_tables.sql. MySQL repository adapters implement domain persistence contracts. Firebase service-account configuration and FCM-token use cases indicate push notifications through Firebase; Ollama is separately configured by endpoint. Key paths: docker-compose.yml, php/Dockerfile, Cron/Dockerfile.
Main entry points: ProcessPendingJobsUseCase.php Pending-job processor · ClassUseCase.php Identity, classes & enrollment · JobUseCase.php Job management · docker-compose.yml Docker Compose
Components 21
HTTP API
- Homework endpoints · Teacher homework lifecycle and status APIs.
public/homework/add_homework.php - Question retrieval API
public/questions_choices/v2/get_questions_choices.php - Score update API
public/result/update_score.php - Project API
public/project/add_project.php
Application
- Identity, classes & enrollment · Establishes teacher/student classroom context.
src/Application/UseCases/ClassUseCase.php - User use case
src/Application/UseCases/UserUseCase.php - Enrollment use case
src/Application/UseCases/StudentClassEnrollmentUseCase.php - Homework & projects · Manages assignments, projects, submissions, and status.
- Job management · Persists generation jobs and exposes retry.
src/Application/UseCases/JobUseCase.php - Pending-job processor · Acquires source, generates questions, and stores choices.
src/Application/UseCases/ProcessPendingJobsUseCase.php - Answers & results · Records answers, scores, completion, and averages.
src/Application/UseCases/AnswerUseCase.php - Average scores
src/Application/UseCases/AverageScoreUseCase.php
Domain
- Entities & repository contracts · Homework, project, status, result, and question abstractions.
- Question generator contract
src/Domain/Repositories/QuestionGeneratorInterface.php
Infrastructure
- MySQL repository adapters · Implements domain persistence contracts.
- Source downloader factory · Selects validated GitHub or Google Drive acquisition.
src/Infrastructure/ExternalServices/DownloaderFactory.php - Ollama generator
src/Infrastructure/ExternalServices/OllamaQuestionGenerator.php - Firebase notifications · Uses service credentials and FCM tokens.
Runtime
- Cron job runner · Invokes pending-job processing.
Cron/process_pending_jobs.php - Docker Compose · Runs PHP/Apache, MySQL, and cron worker.
docker-compose.yml - MySQL · Schema initialized for application persistence.
mysqlEntry/create_tables.sql
Connections 22
- Homework endpoints → Homework & projects
- Project API → Homework & projects
- Question retrieval API → Job management: retry / retrieve
- Score update API → Answers & results: update score
- Identity, classes & enrollment → User use case: user context
- Identity, classes & enrollment → Enrollment use case: class membership
- Homework & projects → Identity, classes & enrollment: teacher/student context
- Homework & projects → Job management: create generation jobs
- Cron job runner → Pending-job processor: process pending jobs
- Pending-job processor → Job management: loads jobs
- Pending-job processor → Source downloader factory: acquire source
- Pending-job processor → Question generator contract: generate questions
- Ollama generator → Question generator contract: implements
- Pending-job processor → Entities & repository contracts: stores questions and choices
- Answers & results → Entities & repository contracts: answers and results
- Average scores → Entities & repository contracts: queries aggregates
- Homework & projects → Entities & repository contracts: homework and project state
- Entities & repository contracts → MySQL repository adapters: persistence contracts
- MySQL repository adapters → MySQL: persists
- Docker Compose → Cron job runner: runs
- Docker Compose → MySQL: runs
- User use case → Firebase notifications: push notifications