refactor to mongo and MVC#28
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the backend from Prisma/PostgreSQL route handlers toward a MongoDB-backed MVC structure with separate controllers, services, models, and shared model types.
Changes:
- Replaces Prisma/PostgreSQL dependencies and schema with MongoDB access through
mongodb. - Moves backend route logic into controller/service/model layers.
- Adds custom model interfaces and
AppError-based service error handling.
Reviewed changes
Copilot reviewed 43 out of 44 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm-lock.yaml |
Updates lockfile from Prisma/PostgreSQL dependencies to MongoDB dependencies. |
package.json |
Changes root dev script to run web and backend together. |
apps/backend/package.json |
Removes Prisma/PostgreSQL scripts/dependencies and adds MongoDB. |
apps/backend/src/index.ts |
Adds MongoDB ping during server startup. |
apps/backend/src/lib/db.ts |
Adds MongoDB client/database export. |
apps/backend/src/lib/prisma.ts |
Removes Prisma client setup. |
apps/backend/src/errors/AppError.ts |
Adds application error type for service/controller handling. |
apps/backend/src/controllers/auth.controller.ts |
Adds auth controller wrapper around auth service. |
apps/backend/src/controllers/business.controller.ts |
Adds business controller wrapper around business service. |
apps/backend/src/controllers/service.controller.ts |
Adds service controller wrapper around service service. |
apps/backend/src/controllers/appointment.controller.ts |
Adds appointment controller wrapper around appointment service. |
apps/backend/src/controllers/health.controller.ts |
Adds MongoDB-backed health check controller. |
apps/backend/src/services/auth.service.ts |
Adds registration/login business logic. |
apps/backend/src/services/business.service.ts |
Adds business CRUD service logic. |
apps/backend/src/services/service.service.ts |
Adds service CRUD/validation logic. |
apps/backend/src/services/appointment.service.ts |
Adds appointment creation/query/update logic. |
apps/backend/src/models/user.model.ts |
Adds MongoDB user data access functions. |
apps/backend/src/models/business.model.ts |
Adds MongoDB business data access functions. |
apps/backend/src/models/service.model.ts |
Adds MongoDB service data access functions. |
apps/backend/src/models/appointment.model.ts |
Adds MongoDB appointment data access and conflict checks. |
apps/backend/src/types/models/user.ts |
Adds user/public-user TypeScript models. |
apps/backend/src/types/models/business.ts |
Adds business TypeScript model. |
apps/backend/src/types/models/service.ts |
Adds service TypeScript model. |
apps/backend/src/types/models/appointment.ts |
Adds appointment/status TypeScript model. |
apps/backend/src/types/models/index.ts |
Re-exports backend model types. |
apps/backend/src/routes/auth.ts |
Replaces inline auth handlers with controller bindings. |
apps/backend/src/routes/business.ts |
Replaces inline business handlers with controller bindings. |
apps/backend/src/routes/service.ts |
Replaces inline service handlers with controller bindings. |
apps/backend/src/routes/appointment.ts |
Replaces inline appointment handlers with controller bindings. |
apps/backend/src/routes/health.ts |
Replaces inline health check with controller binding. |
apps/backend/src/utils/checkConflicts.ts |
Removes Prisma-based conflict helper. |
apps/backend/src/constants/messages.ts |
Removes auth message constants. |
apps/backend/prisma/schema.prisma |
Removes Prisma schema. |
apps/backend/prisma/migrations/migration_lock.toml |
Removes Prisma migration lock. |
apps/backend/prisma/migrations/20260403200037_init/migration.sql |
Removes initial Prisma migration. |
apps/backend/prisma/migrations/20260403210108_add_business_service_appointment/migration.sql |
Removes business/service/appointment migration. |
apps/backend/prisma/migrations/20260403212016_add_indexes/migration.sql |
Removes Prisma index migration. |
apps/backend/prisma/migrations/20260403212805_snapshot_service_data_on_appointment/migration.sql |
Removes appointment snapshot migration. |
apps/backend/prisma/migrations/20260404150637_add_provider_service_relation/migration.sql |
Removes provider-service relation migration. |
apps/backend/prisma/migrations/20260408212027_add_compound_unique_phone_role/migration.sql |
Removes compound unique migration. |
apps/backend/prisma/migrations/20260413151449_remove_role_from_user/migration.sql |
Removes role-removal migration. |
apps/backend/prisma/migrations/20260413160000_split_name_into_first_last/migration.sql |
Removes name-splitting migration. |
apps/backend/prisma/migrations/20260421123511_add_user_avatar/migration.sql |
Removes avatar migration. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
apps/backend/prisma/schema.prisma:1
- This removes the persisted PostgreSQL schema and migration history without adding any MongoDB migration or backfill path. Existing production data (users, businesses, services, appointments) will not be transferred to the new collections, so deploying this would make current accounts and bookings disappear from the API.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+44
to
+48
| const user = await createUser({ | ||
| ...data, | ||
| password: hashedPassword, | ||
| avatar: data.avatar || null, | ||
| }); |
Comment on lines
+45
to
+48
| const business = await findBusinessById(id); | ||
| if (!business) throw new AppError(404, 'Business not found'); | ||
| if (business.ownerId !== userId) throw new AppError(403, 'Forbidden'); | ||
| return updateBusiness(id, data); |
Comment on lines
+123
to
+128
| return updateService(serviceId, { | ||
| name: data.name, | ||
| duration: data.duration, | ||
| price: data.price, | ||
| ...(providerIds !== undefined && { providerIds }), | ||
| }); |
Comment on lines
+17
to
+20
| export async function findBusinessById(id: string): Promise<Business | null> { | ||
| const doc = await db | ||
| .collection('businesses') | ||
| .findOne({ _id: new ObjectId(id) }); |
Comment on lines
+10
to
+13
| export async function findServiceById(id: string): Promise<Service | null> { | ||
| const doc = await db | ||
| .collection('services') | ||
| .findOne({ _id: new ObjectId(id) }); |
Comment on lines
+28
to
+30
| const result = await db | ||
| .collection('businesses') | ||
| .insertOne({ ...data, createdAt: now, updatedAt: now }); |
| } | ||
|
|
||
| const client = new MongoClient(uri); | ||
| export const db = client.db('soly_dev'); |
Comment on lines
+69
to
+78
| const existing = await db | ||
| .collection('appointments') | ||
| .find({ | ||
| providerId, | ||
| status: { $ne: 'CANCELED' }, | ||
| time: { $gte: dayStart, $lte: dayEnd }, | ||
| ...(excludeAppointmentId | ||
| ? { _id: { $ne: new ObjectId(excludeAppointmentId) } } | ||
| : {}), | ||
| }) |
Comment on lines
+22
to
+25
| const docs = await db | ||
| .collection('appointments') | ||
| .find({ $or: [{ customerId: userId }, { providerId: userId }] }) | ||
| .toArray(); |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 44 out of 45 changed files in this pull request and generated 3 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
apps/backend/prisma/schema.prisma:1
- Removing the Prisma schema and migrations leaves no migration path for existing PostgreSQL data into the new MongoDB collections. Deploying this change against an environment with existing users, businesses, services, and appointments would make the backend read from empty Mongo collections with no documented or automated data migration.
| serviceName: service.name, | ||
| price: service.price, | ||
| duration: service.duration, | ||
| status: 'PENDING', |
Comment on lines
+24
to
+40
| app.listen(PORT, async () => { | ||
| try { | ||
| await db.command({ ping: 1 }); | ||
| await db | ||
| .collection('users') | ||
| .createIndex({ phoneNumber: 1 }, { unique: true }); | ||
| await db | ||
| .collection('businesses') | ||
| .createIndex({ ownerId: 1 }, { unique: true }); | ||
| await db | ||
| .collection('appointments') | ||
| .createIndex({ providerId: 1, time: 1, status: 1 }); | ||
| await db.collection('appointments').createIndex({ customerId: 1 }); | ||
| await db.collection('appointments').createIndex({ providerId: 1 }); | ||
| console.log('Connected to MongoDB'); | ||
| } catch (error) { | ||
| console.log('MongoDB connection failed:', error); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Description
Related Issue(s)
Fixes SOLY-
Checklist
Screenshots (if appropriate)