# denyscuevas/learntogether-server architecture

> Architecture diagram of the GitHub repository denyscuevas/learntogether-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/denyscuevas/learntogether-server
- Repository: https://github.com/denyscuevas/learntogether-server

## Overview

LearnTogether is a University of Windsor tutoring-exchange backend. The main workflow is authenticated students completing profiles, receiving course/availability-based matches, sending and accepting connection requests, then communicating through encrypted messages and live notifications. The API also supports email verification and password recovery, profile-image hosting, caching, and online presence. The graph follows documented route/controller and service references; some implementation details are unsampled, so only evidenced links are drawn.

Main entry points: [`src/index.js`](https://github.com/denyscuevas/learntogether-server/blob/dev/src/index.js) (HTTP and socket server), [`src/config/prismaClient.ts`](https://github.com/denyscuevas/learntogether-server/blob/dev/src/config/prismaClient.ts) (PostgreSQL via Prisma), [`src/middleware/verifyUserMiddleware.ts`](https://github.com/denyscuevas/learntogether-server/blob/dev/src/middleware/verifyUserMiddleware.ts) (JWT authorization), [`src/controllers/RequestController.ts`](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/RequestController.ts) (Connection requests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_server["HTTP and socket server<br/>[index.js]"]
  node_auth_routes["Auth routes<br/>[auth.ts]"]
  node_auth_controller["Authentication<br/>[AuthController.ts]"]
  node_auth_guard["JWT authorization"]
end

subgraph group_learning["Profiles and matching"]
  node_profile_routes["Profile routes<br/>[profile.ts]"]
  node_profile_controller["Profile management"]
  node_matching_routes["Match routes<br/>[matches.ts]"]
  node_matching["Recommendations and search"]
end

subgraph group_connections["Requests and messaging"]
  node_requests_routes["Request routes<br/>[requests.ts]"]
  node_requests["Connection requests"]
  node_thread_routes["Thread routes<br/>[thread.ts]"]
  node_message_routes["Message routes<br/>[message.ts]"]
  node_messaging["Thread and message API"]
  node_message_service["Encrypted message service<br/>[message.ts]"]
end

subgraph group_realtime["Realtime and notifications"]
  node_notification_routes["Notification routes<br/>[notifications.ts]"]
  node_notification_controller["Notification API"]
  node_socket["Socket.IO server<br/>[socket.ts]"]
  node_socket_server["Socket events<br/>[socketServer.ts]"]
  node_socket_notifications["Live notifications<br/>[notifications.ts]"]
  node_socket_presence["Socket presence store"]
end

subgraph group_infra["Data and integrations"]
  node_prisma[("PostgreSQL via Prisma<br/>[prismaClient.ts]")]
  node_redis[("Redis cache<br/>[redis.ts]")]
  node_cloudinary["Cloudinary image hosting"]
  node_mailer["Email delivery<br/>[mailer.ts]"]
  node_email_queue["Email queue<br/>[emailQueue.ts]"]
end

node_student(("Student"))

node_student -->|"uses API"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_profile_routes
node_server -->|"mounts"| node_matching_routes
node_server -->|"mounts"| node_requests_routes
node_server -->|"mounts"| node_thread_routes
node_server -->|"mounts"| node_message_routes
node_server -->|"mounts"| node_notification_routes
node_server -->|"creates"| node_socket
node_auth_routes -->|"routes to"| node_auth_controller
node_auth_routes -->|"guards routes"| node_auth_guard
node_profile_routes -->|"routes to"| node_profile_controller
node_profile_routes -->|"guards routes"| node_auth_guard
node_matching_routes -->|"routes to"| node_matching
node_matching_routes -->|"guards routes"| node_auth_guard
node_requests_routes -->|"routes to"| node_requests
node_requests_routes -->|"guards routes"| node_auth_guard
node_thread_routes -->|"routes to"| node_messaging
node_thread_routes -->|"guards routes"| node_auth_guard
node_message_routes -->|"routes to"| node_messaging
node_message_routes -->|"guards routes"| node_auth_guard
node_notification_routes -->|"routes to"| node_notification_controller
node_notification_routes -->|"guards routes"| node_auth_guard
node_auth_controller -->|"reads and writes"| node_prisma
node_auth_controller -->|"queues email"| node_email_queue
node_email_queue -->|"dispatches email"| node_mailer
node_profile_controller -->|"reads and writes"| node_prisma
node_profile_controller -->|"caches profiles"| node_redis
node_profile_controller -->|"uploads images"| node_cloudinary
node_matching -->|"queries candidates"| node_prisma
node_matching -->|"caches matches"| node_redis
node_matching -.->|"gets online status"| node_socket_presence
node_requests -->|"updates requests"| node_prisma
node_requests -->|"creates message"| node_message_service
node_requests -->|"invalidates cache"| node_redis
node_requests -->|"sends notification"| node_socket_notifications
node_messaging -->|"queries threads"| node_prisma
node_messaging -->|"decrypts messages"| node_message_service
node_message_service -->|"stores ciphertext"| node_prisma
node_notification_controller -->|"reads notifications"| node_prisma
node_socket -->|"initializes"| node_socket_server
node_socket_server -->|"creates messages"| node_message_service
node_socket_server -->|"tracks presence"| node_socket_presence
node_socket_presence -->|"stores presence"| node_redis
node_socket_notifications -->|"uses socket server"| node_socket
node_socket_notifications -->|"looks up sockets"| node_socket_presence
node_server -->|"runs cleanup"| node_prisma

click node_server "https://github.com/denyscuevas/learntogether-server/blob/dev/src/index.js"
click node_auth_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/auth.ts"
click node_auth_controller "https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/AuthController.ts"
click node_auth_guard "https://github.com/denyscuevas/learntogether-server/blob/dev/src/middleware/verifyUserMiddleware.ts"
click node_profile_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/profile.ts"
click node_profile_controller "https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/ProfileController.ts"
click node_matching_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/matches.ts"
click node_matching "https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/MatchingController.ts"
click node_requests_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/requests.ts"
click node_requests "https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/RequestController.ts"
click node_thread_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/thread.ts"
click node_message_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/message.ts"
click node_messaging "https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/MessagingController.ts"
click node_message_service "https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/message.ts"
click node_notification_routes "https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/notifications.ts"
click node_notification_controller "https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/NotificationController.ts"
click node_socket "https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/socket.ts"
click node_socket_server "https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/socketServer.ts"
click node_socket_notifications "https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/notifications.ts"
click node_socket_presence "https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/redisSocketService.ts"
click node_prisma "https://github.com/denyscuevas/learntogether-server/blob/dev/src/config/prismaClient.ts"
click node_redis "https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/redis.ts"
click node_mailer "https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/mailer.ts"
click node_email_queue "https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/emailQueue.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_auth_routes,node_auth_controller,node_auth_guard toneBlue
class node_profile_routes,node_profile_controller,node_matching_routes,node_matching toneAmber
class node_requests_routes,node_requests,node_thread_routes,node_message_routes,node_messaging,node_message_service toneMint
class node_notification_routes,node_notification_controller,node_socket,node_socket_server,node_socket_notifications,node_socket_presence toneRose
class node_prisma,node_redis,node_cloudinary,node_mailer,node_email_queue,node_student toneIndigo
```

## Components

### API and identity

- [HTTP and socket server](https://github.com/denyscuevas/learntogether-server/blob/dev/src/index.js): `src/index.js`
- [Auth routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/auth.ts): `src/routes/auth.ts`
- [Authentication](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/AuthController.ts): `src/controllers/AuthController.ts`
- [JWT authorization](https://github.com/denyscuevas/learntogether-server/blob/dev/src/middleware/verifyUserMiddleware.ts): `src/middleware/verifyUserMiddleware.ts`

### Profiles and matching

- [Profile routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/profile.ts): `src/routes/profile.ts`
- [Profile management](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/ProfileController.ts): `src/controllers/ProfileController.ts`
- [Match routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/matches.ts): `src/routes/matches.ts`
- [Recommendations and search](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/MatchingController.ts): `src/controllers/MatchingController.ts`

### Requests and messaging

- [Request routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/requests.ts): `src/routes/requests.ts`
- [Connection requests](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/RequestController.ts): `src/controllers/RequestController.ts`
- [Thread routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/thread.ts): `src/routes/thread.ts`
- [Message routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/message.ts): `src/routes/message.ts`
- [Thread and message API](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/MessagingController.ts): `src/controllers/MessagingController.ts`
- [Encrypted message service](https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/message.ts): `src/services/message.ts`

### Realtime and notifications

- [Notification routes](https://github.com/denyscuevas/learntogether-server/blob/dev/src/routes/notifications.ts): `src/routes/notifications.ts`
- [Notification API](https://github.com/denyscuevas/learntogether-server/blob/dev/src/controllers/NotificationController.ts): `src/controllers/NotificationController.ts`
- [Socket.IO server](https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/socket.ts): `src/socket-server/socket.ts`
- [Socket events](https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/socketServer.ts): `src/socket-server/socketServer.ts`
- [Live notifications](https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/notifications.ts): `src/socket-server/notifications.ts`
- [Socket presence store](https://github.com/denyscuevas/learntogether-server/blob/dev/src/socket-server/redisSocketService.ts): `src/socket-server/redisSocketService.ts`

### Data and integrations

- [PostgreSQL via Prisma](https://github.com/denyscuevas/learntogether-server/blob/dev/src/config/prismaClient.ts): `src/config/prismaClient.ts`
- [Redis cache](https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/redis.ts): `src/services/redis.ts`
- **Cloudinary image hosting**
- [Email delivery](https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/mailer.ts): `src/services/mailer.ts`
- [Email queue](https://github.com/denyscuevas/learntogether-server/blob/dev/src/services/emailQueue.ts): `src/services/emailQueue.ts`

### Other components

- **Student**

## Connections

- Student → HTTP and socket server: uses API (evidence: `src/index.js`)
- HTTP and socket server → Auth routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Profile routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Match routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Request routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Thread routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Message routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Notification routes: mounts (evidence: `src/index.js`)
- HTTP and socket server → Socket.IO server: creates (evidence: `src/index.js`)
- Auth routes → Authentication: routes to (evidence: `src/routes/auth.ts`)
- Auth routes → JWT authorization: guards routes (evidence: `src/routes/auth.ts`)
- Profile routes → Profile management: routes to (evidence: `src/routes/profile.ts`)
- Profile routes → JWT authorization: guards routes (evidence: `src/routes/profile.ts`)
- Match routes → Recommendations and search: routes to (evidence: `src/routes/matches.ts`)
- Match routes → JWT authorization: guards routes (evidence: `src/routes/matches.ts`)
- Request routes → Connection requests: routes to (evidence: `src/routes/requests.ts`)
- Request routes → JWT authorization: guards routes (evidence: `src/routes/requests.ts`)
- Thread routes → Thread and message API: routes to (evidence: `src/routes/thread.ts`)
- Thread routes → JWT authorization: guards routes (evidence: `src/routes/thread.ts`)
- Message routes → Thread and message API: routes to (evidence: `src/routes/message.ts`)
- Message routes → JWT authorization: guards routes (evidence: `src/routes/message.ts`)
- Notification routes → Notification API: routes to (evidence: `src/routes/notifications.ts`)
- Notification routes → JWT authorization: guards routes (evidence: `src/routes/notifications.ts`)
- Authentication → PostgreSQL via Prisma: reads and writes (evidence: `src/controllers/AuthController.ts`)
- Authentication → Email queue: queues email (evidence: `src/controllers/AuthController.ts`)
- Email queue → Email delivery: dispatches email (evidence: `src/services/emailQueue.ts`)
- Profile management → PostgreSQL via Prisma: reads and writes (evidence: `src/controllers/ProfileController.ts`)
- Profile management → Redis cache: caches profiles (evidence: `src/controllers/ProfileController.ts`)
- Profile management → Cloudinary image hosting: uploads images (evidence: `src/controllers/ProfileController.ts`)
- Recommendations and search → PostgreSQL via Prisma: queries candidates (evidence: `src/controllers/MatchingController.ts`)
- Recommendations and search → Redis cache: caches matches (evidence: `src/controllers/MatchingController.ts`)
- Recommendations and search → Socket presence store: gets online status
- Connection requests → PostgreSQL via Prisma: updates requests (evidence: `src/controllers/RequestController.ts`)
- Connection requests → Encrypted message service: creates message (evidence: `src/controllers/RequestController.ts`)
- Connection requests → Redis cache: invalidates cache (evidence: `src/controllers/RequestController.ts`)
- Connection requests → Live notifications: sends notification (evidence: `src/controllers/RequestController.ts`)
- Thread and message API → PostgreSQL via Prisma: queries threads (evidence: `src/controllers/MessagingController.ts`)
- Thread and message API → Encrypted message service: decrypts messages (evidence: `src/controllers/MessagingController.ts`)
- Encrypted message service → PostgreSQL via Prisma: stores ciphertext (evidence: `src/services/message.ts`)
- Notification API → PostgreSQL via Prisma: reads notifications (evidence: `src/controllers/NotificationController.ts`)
- Socket.IO server → Socket events: initializes (evidence: `src/socket-server/socket.ts`)
- Socket events → Encrypted message service: creates messages (evidence: `src/socket-server/socketServer.ts`)
- Socket events → Socket presence store: tracks presence (evidence: `src/socket-server/socketServer.ts`)
- Socket presence store → Redis cache: stores presence (evidence: `src/socket-server/redisSocketService.ts`)
- Live notifications → Socket.IO server: uses socket server (evidence: `src/socket-server/notifications.ts`)
- Live notifications → Socket presence store: looks up sockets (evidence: `src/socket-server/notifications.ts`)
- HTTP and socket server → PostgreSQL via Prisma: runs cleanup (evidence: `src/index.js`)
