# iamselva3/mentorspace_backend architecture

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

- Interactive diagram: https://gitdiagram.com/iamselva3/mentorspace_backend
- Repository: https://github.com/iamselva3/mentorspace_backend

## Overview

MentorSpace is the backend of a learning platform: teachers author rich articles and review engagement, while students discover content, record reading activity, and manage highlights. Requests enter Express routes, pass authentication and role checks, then reach controllers and use cases that operate on MongoDB repositories. The README also describes media uploads and an AI learning assistant. Several analytics and AI implementations were not sampled, so their internal call paths are not expanded; documented capabilities are retained where useful.

Main entry points: [`src/app.js`](https://github.com/iamselva3/mentorspace_backend/blob/main/src/app.js) (Express app), [`src/middleware/auth.js`](https://github.com/iamselva3/mentorspace_backend/blob/main/src/middleware/auth.js) (Authentication middleware), [`src/controllers/articleController.js`](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/articleController.js) (Article routes and controller), [`src/controllers/highlightController.js`](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/highlightController.js) (Highlight routes and controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_express["Express app<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_authcontroller["Authentication<br/>[authController.js]"]
  node_authusecases["Auth use cases"]
  node_authmw["Authentication middleware<br/>[auth.js]"]
  node_users[("User repository and model<br/>[userRepository.js]")]
end

subgraph group_learning["Learning content"]
  node_articleapi["Article routes and controller"]
  node_articlecases["Article use cases"]
  node_articles[("Article repository and model")]
  node_upload["Media upload<br/>[upload.js]"]
  node_s3[("AWS S3")]
  node_highlightapi["Highlight routes and controller"]
  node_highlightcases["Highlight use cases"]
  node_highlights[("Highlight repository and model")]
end

subgraph group_insights["Engagement and analytics"]
  node_tracking["Engagement tracking"]
  node_analyticsapi["Analytics routes and controller"]
  node_analyticscases["Analytics use cases"]
  node_analytics[("Analytics repository and model")]
end

subgraph group_platform["Learning support"]
  node_ai["AI assistant endpoint<br/>[Aicontroller.js]"]
  node_cohere["Cohere AI"]
end

node_teacher(("Teacher"))
node_student(("Student"))

node_express -->|"mounts"| node_authroutes
node_express -->|"mounts"| node_articleapi
node_express -->|"mounts"| node_analyticsapi
node_express -->|"mounts"| node_highlightapi
node_express -->|"mounts"| node_tracking
node_express -->|"mounts"| node_ai
node_authroutes -->|"routes to"| node_authcontroller
node_authcontroller -->|"invokes"| node_authusecases
node_authroutes -.->|"protects"| node_authmw
node_articleapi -->|"protects"| node_authmw
node_highlightapi -->|"protects"| node_authmw
node_analyticsapi -->|"protects"| node_authmw
node_tracking -->|"protects"| node_authmw
node_authmw -->|"looks up user"| node_users
node_authusecases -->|"uses"| node_users
node_articleapi -->|"invokes"| node_articlecases
node_articleapi -->|"reads article"| node_articles
node_articlecases -->|"uses"| node_articles
node_articleapi -->|"accepts media"| node_upload
node_upload -.->|"stores media"| node_s3
node_highlightapi -->|"invokes"| node_highlightcases
node_highlightapi -->|"deletes highlight"| node_highlights
node_highlightcases -->|"uses"| node_highlights
node_highlightcases -->|"checks article"| node_articles
node_tracking -->|"invokes"| node_analyticscases
node_analyticsapi -.->|"dispatches"| node_analyticscases
node_analyticscases -->|"uses"| node_analytics
node_student -.->|"uses"| node_express
node_teacher -.->|"uses"| node_express
node_express -->|"routes AI requests"| node_ai
node_ai -.->|"requests assistance"| node_cohere

click node_express "https://github.com/iamselva3/mentorspace_backend/blob/main/src/app.js"
click node_authroutes "https://github.com/iamselva3/mentorspace_backend/blob/main/src/routes/authRoutes.js"
click node_authcontroller "https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/authController.js"
click node_authusecases "https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/auth"
click node_authmw "https://github.com/iamselva3/mentorspace_backend/blob/main/src/middleware/auth.js"
click node_users "https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/userRepository.js"
click node_articleapi "https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/articleController.js"
click node_articlecases "https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/article"
click node_articles "https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/articleRepository.js"
click node_upload "https://github.com/iamselva3/mentorspace_backend/blob/main/src/middleware/upload.js"
click node_highlightapi "https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/highlightController.js"
click node_highlightcases "https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/highlight"
click node_highlights "https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/highlightRepository.js"
click node_tracking "https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/trackingController.js"
click node_analyticsapi "https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/analyticsController.js"
click node_analyticscases "https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/analytics"
click node_analytics "https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/analyticsRepository.js"
click node_ai "https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/Aicontroller.js"

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_express,node_authroutes,node_authcontroller,node_authusecases,node_authmw,node_users toneBlue
class node_articleapi,node_articlecases,node_articles,node_upload,node_s3,node_highlightapi,node_highlightcases,node_highlights toneAmber
class node_tracking,node_analyticsapi,node_analyticscases,node_analytics toneMint
class node_ai,node_cohere toneRose
class node_teacher,node_student toneIndigo
```

## Components

### API and access

- [Express app](https://github.com/iamselva3/mentorspace_backend/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/iamselva3/mentorspace_backend/blob/main/src/routes/authRoutes.js): `src/routes/authRoutes.js`
- [Authentication](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [Auth use cases](https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/auth): `src/usecases/auth`
- [Authentication middleware](https://github.com/iamselva3/mentorspace_backend/blob/main/src/middleware/auth.js): `src/middleware/auth.js`
- [User repository and model](https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/userRepository.js): `src/repositories/userRepository.js`

### Learning content

- [Article routes and controller](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/articleController.js): `src/controllers/articleController.js`
- [Article use cases](https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/article): `src/usecases/article`
- [Article repository and model](https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/articleRepository.js): `src/repositories/articleRepository.js`
- [Media upload](https://github.com/iamselva3/mentorspace_backend/blob/main/src/middleware/upload.js): `src/middleware/upload.js`
- **AWS S3**
- [Highlight routes and controller](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/highlightController.js): `src/controllers/highlightController.js`
- [Highlight use cases](https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/highlight): `src/usecases/highlight`
- [Highlight repository and model](https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/highlightRepository.js): `src/repositories/highlightRepository.js`

### Engagement and analytics

- [Engagement tracking](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/trackingController.js): `src/controllers/trackingController.js`
- [Analytics routes and controller](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/analyticsController.js): `src/controllers/analyticsController.js`
- [Analytics use cases](https://github.com/iamselva3/mentorspace_backend/tree/main/src/usecases/analytics): `src/usecases/analytics`
- [Analytics repository and model](https://github.com/iamselva3/mentorspace_backend/blob/main/src/repositories/analyticsRepository.js): `src/repositories/analyticsRepository.js`

### Learning support

- [AI assistant endpoint](https://github.com/iamselva3/mentorspace_backend/blob/main/src/controllers/Aicontroller.js): `src/controllers/Aicontroller.js`
- **Cohere AI**

### Other components

- **Teacher**
- **Student**

## Connections

- Express app → Auth routes: mounts (evidence: `src/app.js`)
- Express app → Article routes and controller: mounts (evidence: `src/app.js`)
- Express app → Analytics routes and controller: mounts (evidence: `src/app.js`)
- Express app → Highlight routes and controller: mounts (evidence: `src/app.js`)
- Express app → Engagement tracking: mounts (evidence: `src/app.js`)
- Express app → AI assistant endpoint: mounts (evidence: `src/app.js`)
- Auth routes → Authentication: routes to (evidence: `src/routes/authRoutes.js`)
- Authentication → Auth use cases: invokes (evidence: `src/controllers/authController.js`)
- Auth routes → Authentication middleware: protects
- Article routes and controller → Authentication middleware: protects (evidence: `src/routes/articleRoutes.js`)
- Highlight routes and controller → Authentication middleware: protects (evidence: `src/routes/highlightRoutes.js`)
- Analytics routes and controller → Authentication middleware: protects (evidence: `src/routes/analyticsRoutes.js`)
- Engagement tracking → Authentication middleware: protects (evidence: `src/routes/trackingRoutes.js`)
- Authentication middleware → User repository and model: looks up user (evidence: `src/middleware/auth.js`)
- Auth use cases → User repository and model: uses (evidence: `src/usecases/auth/verifyTokenUseCase.js`)
- Article routes and controller → Article use cases: invokes (evidence: `src/controllers/articleController.js`)
- Article routes and controller → Article repository and model: reads article (evidence: `src/controllers/articleController.js`)
- Article use cases → Article repository and model: uses (evidence: `src/usecases/article/createArticleUseCase.js`)
- Article routes and controller → Media upload: accepts media (evidence: `src/routes/articleRoutes.js`)
- Media upload → AWS S3: stores media (evidence: `README.md`)
- Highlight routes and controller → Highlight use cases: invokes (evidence: `src/controllers/highlightController.js`)
- Highlight routes and controller → Highlight repository and model: deletes highlight (evidence: `src/controllers/highlightController.js`)
- Highlight use cases → Highlight repository and model: uses (evidence: `src/usecases/highlight/createHighlightUseCase.js`)
- Highlight use cases → Article repository and model: checks article (evidence: `src/usecases/highlight/createHighlightUseCase.js`)
- Engagement tracking → Analytics use cases: invokes (evidence: `src/controllers/trackingController.js`)
- Analytics routes and controller → Analytics use cases: dispatches
- Analytics use cases → Analytics repository and model: uses (evidence: `src/usecases/analytics/getStudentProgressUseCase.js`)
- Student → Express app: uses
- Teacher → Express app: uses
- Express app → AI assistant endpoint: routes AI requests (evidence: `src/app.js`)
- AI assistant endpoint → Cohere AI: requests assistance (evidence: `README.md`)
