Backend
Using Express for server
Architecture
We are using the controller-service-repository pattern
Controller: Where APIs are defined and exposed
Service: Business logic implementations, 3rd party integrations. Logic of fetching/filling up cache
Repository: Storage (database) retrieval
Divide functionalities by course, reviews, reports, and users
Course: Getting & searching courses
Reviews: Getting & searching for reviews
Reports: Reports made by users on a review reporting inappropriate content
Users: Creates new users, update them, get their info, and verify their session
Users
Uses csesoc’s authentication system
The user class stores their reviews, bookmarks, admin status, and report logs
We are using NextAuth to handle sign in and sign out functionalities
validationMiddleware: Checks if the request has the correct structure based on the defined schema
verifyToken: Making sure the user in session is correct by calling csesoc’s auth and matching the zid’s
validateReq: Alternative to request (wrapper for fetch API calls) that takes in the user’s ID and token session along the request. Used where we care about user sessions
Redis
In-memory data storage, cache
Class in modules/redis.ts
Stores data in key-value pairs
E.g. CourseID: Course Data
Will get called first to fetch data. If there is a miss, the service will call the repository and then put the data in the cache
Prisma
Object-Relational Mapper (ORM)
Class in modules/prisma.ts
When the server starts, it will create a Prisma manager that connects to our database
The repositories will do the SQL queries through Prisma, which will interact with our database
We define all the table schemas in Typescript so that Prisma understands the data