Repository navigation
Implement clean architecture across backend services and frontend api layer - #1
Merged
Merged
Conversation
… resilient fixtures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors both the Ruby on Rails 8 Backend and React 19 + TypeScript Frontend to follow Clean Architecture principles. It establishes clear separation of concerns, decouples persistence and domain logic from HTTP delivery, introduces a typed frontend API service layer, and improves testability and maintainability.
Architectural Changes
1. Backend (Ruby on Rails 8)
Repository Layer (
app/repositories/):BaseRepositoryproviding generalized CRUD operations.UserRepository,ClassroomRepository,ExaminationRepository,ExamAttemptRepository, andAssignmentRepository.ActiveRecordqueries out of controllers.Use Cases / Interactors (
app/use_cases/):UseCaseResultmonad for consistent success/failure responses without swallowing runtime exceptions.Auth::AuthenticateUser(BCrypt password check & JWT generation),Auth::RegisterStudent(transactional user + student profile creation).Exams::StartExamAttempt(timer calculation, question/option shuffling, resume state),Exams::SaveExamAnswer(autosave answer validation), andExams::SubmitExamAttempt(automatic grading & passing score calculation).Assignments::SubmitAssignmentandAssignments::GradeAssignment.Thin Controllers (
app/controllers/api/v1/):BaseController: addedhandle_result(result)helper to map use case outcomes directly to camelCase JSON API responses.AuthController,ClassroomsController,ExaminationsController,ExamRunnerController, andAssignmentsControllerto delegate business logic to use cases and repositories.Environment & Compatibility:
csvgem dependency inGemfilefor Ruby 3.4/4.0 standard library compatibility.5435) inconfig/database.ymlmatching the Docker Compose configuration.2. Frontend (React 19 + TypeScript)
Typed API Service Layer (
src/services/):authService.ts: login, register, profile, impersonation.classroomService.ts,subjectService.ts,teacherService.ts,studentService.ts.examService.ts: exam management, questions bank, CBT runner endpoints, proctoring/violation telemetry.assignmentService.ts,materialService.ts,announcementService.ts,gradeService.ts.index.ts.State Management & Components:
authStore.ts(Zustand) to delegate network operations toauthService.Classrooms.tsxto consumeclassroomServiceandteacherService.ExamRunner.tsxandExamMonitor.tsxby defininguseCallbackhooks with correct dependency chains before effects.Verification & Testing
bundle exec rspec— all tests passing:bundle exec rails zeitwerk:check— all constant names and namespaces validated.npm run build(tsc -b && vite build) — 0 TypeScript errors.npm run lint— 0 syntax / compiler errors.Checklist