Skip to content

Commit

Permalink
Merge pull request #11 from Tutortoise/refactor/modular-arch
Browse files Browse the repository at this point in the history
refactor: changing code architecture from traditional architecture into modular architecture
  • Loading branch information
elskow authored Nov 21, 2024
2 parents 8c68a16 + a878fdd commit ac04fdc
Show file tree
Hide file tree
Showing 49 changed files with 83 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from "express";
import { PORT } from "./config";
import { morganMiddleware, logger } from "./middleware/logging.middleware";
import { morganMiddleware, logger } from "@middleware/logging.middleware";
import router from "./routes";
import {
helmetMiddleware,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth, firestore } from "@/config";
import type { Controller } from "@/types";
import { registerSchema } from "@schemas/auth.schema";
import { AuthService } from "@services/auth.service";
import { registerSchema } from "@/module/auth/auth.schema";
import { AuthService } from "@/module/auth/auth.service";
import { z } from "zod";

const authService = new AuthService({ auth, firestore });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestHandler } from "express";
import type { Tutor, Learner } from "@/types";
import { auth, firestore } from "@/config";
import { logger } from "./logging.middleware";
import { logger } from "@middleware/logging.middleware";
import { DecodedIdToken } from "firebase-admin/lib/auth/token-verifier";

export const firebaseAuthMiddleware: RequestHandler = async (
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v1/auth.route.ts → src/module/auth/auth.route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Router } from "express";
import * as authController from "@controllers/auth.controller";
import * as authController from "@/module/auth/auth.controller";
import { validator } from "@middleware/validation.middleware";
import { registerSchema } from "@schemas/auth.schema";
import { registerSchema } from "@/module/auth/auth.schema";

// /api/v1/auth
const authRouter = Router();
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
createRoomSchema,
getRoomMessagesSchema,
sendMessageSchema,
} from "@schemas/chat.schema";
import { ChatService } from "@services/chat.service";
import { PresenceService } from "@services/presence.service";
} from "@/module/chat/chat.schema";
import { ChatService } from "@/module/chat/chat.service";
import { PresenceService } from "@/module/chat/presence.service";
import { z } from "zod";

// TODO: Implement FCM token management
Expand Down
6 changes: 3 additions & 3 deletions src/routes/v1/chat.route.ts → src/module/chat/chat.route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Router } from "express";
import * as chatController from "@controllers/chat.controller";
import { firebaseAuthMiddleware } from "@middleware/auth.middleware";
import * as chatController from "@/module/chat/chat.controller";
import { firebaseAuthMiddleware } from "@/module/auth/auth.middleware";
import {
validateChatImageUpload,
validator,
Expand All @@ -9,7 +9,7 @@ import {
createRoomSchema,
getRoomMessagesSchema,
sendMessageSchema,
} from "@schemas/chat.schema";
} from "@/module/chat/chat.schema";
import { z } from "zod";

const chatRouter = Router();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Bucket } from "@google-cloud/storage";
import { logger } from "@middleware/logging.middleware";
import { Firestore } from "firebase-admin/firestore";
import { PresenceService } from "./presence.service";
import { PresenceService } from "@/module/chat/presence.service";

interface ChatServiceDependencies {
firestore: Firestore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Database } from "firebase-admin/database";
import { logger } from "@/middleware/logging.middleware";
import { logger } from "@middleware/logging.middleware";
import { UserPresence, ChatRoomPresence } from "@/types";

interface PresenceServiceDependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { auth, bucket, firestore } from "@/config";
import { downscaleImage } from "@/helpers/image.helper";
import { Controller } from "@/types";
import { logger } from "@middleware/logging.middleware";
import { changePasswordSchema } from "@schemas/auth.schema";
import { updateProfileSchema } from "@schemas/learner.schema";
import { LearnerService } from "@services/learner.service";
import { changePasswordSchema } from "@/module/auth/auth.schema";
import { updateProfileSchema } from "@/module/learner/learner.schema";
import { LearnerService } from "@/module/learner/learner.service";
import { RequestHandler } from "express";
import { z } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as learnerController from "@controllers/learner.controller";
import * as learnerController from "@/module/learner/learner.controller";
import {
firebaseAuthMiddleware,
verifyLearner,
} from "@middleware/auth.middleware";
} from "@/module/auth/auth.middleware";
import {
validateProfilePictureUpload,
validator,
} from "@middleware/validation.middleware";
import { changePasswordSchema } from "@schemas/auth.schema";
import { updateProfileSchema } from "@schemas/learner.schema";
import { changePasswordSchema } from "@/module/auth/auth.schema";
import { updateProfileSchema } from "@/module/learner/learner.schema";
import { Router } from "express";

// /api/v1/learners
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { auth, bucket, firestore } from "@/config";
import { downscaleImage } from "@/helpers/image.helper";
import { LearnerService } from "@services/learner.service";
import { LearnerService } from "@/module/learner/learner.service";
import { z } from "zod";

const learnerService = new LearnerService({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bucket } from "@google-cloud/storage";
import { logger } from "@middleware/logging.middleware";
import { updateProfileSchema } from "@schemas/learner.schema";
import { updateProfileSchema } from "@/module/learner/learner.schema";
import firebase from "firebase-admin";
import { Firestore } from "firebase-admin/firestore";
import { Auth } from "firebase-admin/lib/auth/auth";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { firestore } from "@/config";
import { Controller } from "@/types";
import { logger } from "@middleware/logging.middleware";
import { createOrderSchema } from "@schemas/order.schema";
import { OrderService } from "@services/order.service";
import { createOrderSchema } from "@/module/order/order.schema";
import { OrderService } from "@/module/order/order.service";
import { z } from "zod";

const orderService = new OrderService({ firestore });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as orderController from "@controllers/order.controller";
import * as orderController from "@/module/order/order.controller";
import {
firebaseAuthMiddleware,
verifyLearner,
} from "@middleware/auth.middleware";
} from "@/module/auth/auth.middleware";
import { validator } from "@middleware/validation.middleware";
import { createOrderSchema } from "@schemas/order.schema";
import { createOrderSchema } from "@/module/order/order.schema";
import { Router } from "express";

// /api/v1/orders
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth, bucket, firestore } from "@/config";
import { downscaleImage } from "@/helpers/image.helper";
import { LearnerService } from "@services/learner.service";
import { TutorServiceService } from "@services/tutorService.service";
import { LearnerService } from "@/module/learner/learner.service";
import { TutorServiceService } from "@/module/tutor-service/tutorService.service";
import { z } from "zod";

const learnerService = new LearnerService({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createOrderSchema } from "@schemas/order.schema";
import { createOrderSchema } from "@/module/order/order.schema";
import { Firestore } from "firebase-admin/firestore";
import { z } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { firestore } from "@/config";
import { SubjectService } from "@/services/subject.service";
import { SubjectService } from "@/module/subject/subject.service";
import { Controller } from "@/types";
import { logger } from "@middleware/logging.middleware";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router } from "express";
import * as subjectController from "@controllers/subject.controller";
import * as subjectController from "@/module/subject/subject.controller";

// /api/v1/subjects
const subjectRouter = Router();
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
getServiceSchema,
getServicesSchema,
updateTutorServiceSchema,
} from "@schemas/tutorService.schema";
import { TutorServiceService } from "@services/tutorService.service";
} from "@/module/tutor-service/tutorService.schema";
import { TutorServiceService } from "@/module/tutor-service/tutorService.service";
import { z } from "zod";

const tutorServiceService = new TutorServiceService({ firestore });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as tutorServiceController from "@controllers/tutorService.controller";
import * as tutorServiceController from "@/module/tutor-service/tutorService.controller";
import {
firebaseAuthMiddleware,
verifyTutor,
} from "@middleware/auth.middleware";
} from "@/module/auth/auth.middleware";
import { validator } from "@middleware/validation.middleware";
import {
createTutorServiceSchema,
updateTutorServiceSchema,
} from "@schemas/tutorService.schema";
} from "@/module/tutor-service/tutorService.schema";
import { Router } from "express";

// /api/v1/tutors/services
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { auth, bucket, firestore } from "@/config";
import { downscaleImage } from "@/helpers/image.helper";
import { getCityName } from "@/helpers/location.helper";
import { SubjectService } from "@services/subject.service";
import { TutorService } from "@services/tutor.service";
import { SubjectService } from "@/module/subject/subject.service";
import { TutorService } from "@/module/tutor/tutor.service";
import { z } from "zod";

const subjectService = new SubjectService({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from "@middleware/logging.middleware";
import {
createTutorServiceSchema,
updateTutorServiceSchema,
} from "@schemas/tutorService.schema";
} from "@/module/tutor-service/tutorService.schema";
import firebase from "firebase-admin";
import { Firestore } from "firebase-admin/firestore";
import { z } from "zod";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { downscaleImage } from "@/helpers/image.helper";
import { getCityName } from "@/helpers/location.helper";
import { Controller } from "@/types";
import { logger } from "@middleware/logging.middleware";
import { changePasswordSchema } from "@schemas/auth.schema";
import { updateProfileSchema } from "@schemas/tutor.schema";
import { TutorService } from "@services/tutor.service";
import { changePasswordSchema } from "@/module/auth/auth.schema";
import { updateProfileSchema } from "@/module/tutor/tutor.schema";
import { TutorService } from "@/module/tutor/tutor.service";
import { RequestHandler } from "express";
import { z } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as tutorController from "@controllers/tutor.controller";
import * as tutorController from "@/module/tutor/tutor.controller";
import {
firebaseAuthMiddleware,
verifyTutor,
} from "@middleware/auth.middleware";
} from "@/module/auth/auth.middleware";
import {
validateProfilePictureUpload,
validator,
} from "@middleware/validation.middleware";
import { changePasswordSchema } from "@schemas/auth.schema";
import { updateProfileSchema } from "@schemas/tutor.schema";
import { changePasswordSchema } from "@/module/auth/auth.schema";
import { updateProfileSchema } from "@/module/tutor/tutor.schema";
import { Router } from "express";

// /api/v1/tutors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth, bucket, firestore } from "@/config";
import { downscaleImage } from "@/helpers/image.helper";
import { getCityName } from "@/helpers/location.helper";
import { TutorService } from "@services/tutor.service";
import { TutorService } from "@/module/tutor/tutor.service";
import { z } from "zod";

const tutorService = new TutorService({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { downscaleImage } from "@/helpers/image.helper";
import { getCityName } from "@/helpers/location.helper";
import { Tutor } from "@/types";
import { faker } from "@faker-js/faker";
import { AuthService } from "@services/auth.service";
import { TutorService } from "@services/tutor.service";
import { AuthService } from "@/module/auth/auth.service";
import { TutorService } from "@/module/tutor/tutor.service";

const authService = new AuthService({ firestore, auth });
const tutorService = new TutorService({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bucket } from "@google-cloud/storage";
import { logger } from "@middleware/logging.middleware";
import { updateProfileSchema } from "@schemas/tutor.schema";
import { updateProfileSchema } from "@/module/tutor/tutor.schema";
import firebase from "firebase-admin";
import { Firestore } from "firebase-admin/firestore";
import { Auth } from "firebase-admin/lib/auth/auth";
Expand Down
14 changes: 7 additions & 7 deletions src/routes/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Router } from "express";
import authRouter from "./auth.route";
import subjectRouter from "./subject.route";
import learnerRouter from "./learner.route";
import tutorRouter from "./tutor.route";
import tutorServiceRouter from "./tutorService.route";
import orderRouter from "./order.route";
import chatRouter from "./chat.route";
import authRouter from "@/module/auth/auth.route";
import subjectRouter from "@/module/subject/subject.route";
import learnerRouter from "@/module/learner/learner.route";
import tutorRouter from "@/module/tutor/tutor.route";
import tutorServiceRouter from "@/module/tutor-service/tutorService.route";
import orderRouter from "@/module/order/order.route";
import chatRouter from "@/module/chat/chat.route";

const v1Router = Router();

Expand Down
8 changes: 4 additions & 4 deletions src/seed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { seedLearners } from "./seeders/learner.seeder";
import { seedSubjects } from "./seeders/subject.seeder";
import { seedTutors } from "./seeders/tutor.seeder";
import { seedServices } from "./seeders/tutorService.seeder";
import { seedLearners } from "@/module/learner/learner.seeder";
import { seedSubjects } from "@/module/subject/subject.seeder";
import { seedTutors } from "@/module/tutor/tutor.seeder";
import { seedServices } from "@/module/tutor-service/tutorService.seeder";

export const runSeeder = async () => {
await seedSubjects();
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tutorSchema } from "@schemas/tutor.schema";
import { learnerSchema } from "@schemas/learner.schema";
import { tutorSchema } from "@/module/tutor/tutor.schema";
import { learnerSchema } from "@/module/learner/learner.schema";
import { z } from "zod";
import { tutorServiceSchema } from "@schemas/tutorService.schema";
import { tutorServiceSchema } from "@/module/tutor-service/tutorService.schema";
import { ParsedQs } from "qs";
import { NextFunction, Request, Response } from "express";

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/learner.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { auth, firestore } from "@/config";
import { app } from "@/main";
import { seedSubjects } from "@/seeders/subject.seeder";
import { seedSubjects } from "@/module/subject/subject.seeder";
import { faker } from "@faker-js/faker";
import { SubjectService } from "@services/subject.service";
import { SubjectService } from "@/module/subject/subject.service";
import { initializeApp } from "firebase/app";
import {
connectAuthEmulator,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/order.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { auth, firestore } from "@/config";
import { app } from "@/main";
import { seedLearners } from "@/seeders/learner.seeder";
import { seedTutors } from "@/seeders/tutor.seeder";
import { seedServices } from "@/seeders/tutorService.seeder";
import { seedLearners } from "@/module/learner/learner.seeder";
import { seedTutors } from "@/module/tutor/tutor.seeder";
import { seedServices } from "@/module/tutor-service/tutorService.seeder";
import { faker } from "@faker-js/faker";
import { TutorServiceService } from "@services/tutorService.service";
import { TutorServiceService } from "@/module/tutor-service/tutorService.service";
import { initializeApp } from "firebase/app";
import {
connectAuthEmulator,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/subject.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from "@/main";
import { seedSubjects } from "@/seeders/subject.seeder";
import { seedSubjects } from "@/module/subject/subject.seeder";
import supertest from "supertest";
import { beforeAll, describe, expect, test } from "vitest";

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/tutor.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { auth } from "@/config";
import { app } from "@/main";
import { seedTutors } from "@/seeders/tutor.seeder";
import { seedTutors } from "@/module/tutor/tutor.seeder";
import { faker } from "@faker-js/faker";
import { initializeApp } from "firebase/app";
import {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/tutorService.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app } from "@/main";
import { seedTutors } from "@/seeders/tutor.seeder";
import { seedServices } from "@/seeders/tutorService.seeder";
import { seedTutors } from "@/module/tutor/tutor.seeder";
import { seedServices } from "@/module/tutor-service/tutorService.seeder";
import supertest from "supertest";
import { beforeAll, describe, test } from "vitest";

Expand Down
2 changes: 1 addition & 1 deletion tests/services/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from "@faker-js/faker";
import { AuthService } from "@services/auth.service";
import { AuthService } from "@/module/auth/auth.service";
import { describe, expect, it, vi } from "vitest";

describe("AuthService", () => {
Expand Down
Loading

0 comments on commit ac04fdc

Please sign in to comment.