# c0braaaa/cflix-backend architecture

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

- Interactive diagram: https://gitdiagram.com/c0braaaa/cflix-backend
- Repository: https://github.com/c0braaaa/cflix-backend

## Overview

CFlix is a movie-platform backend API. Clients enter through Express routes, which dispatch to request controllers and domain services for authentication, user collections, movie engagement, administration, traffic, and AI recommendations; services use MongoDB-backed models. The README also documents Socket.IO updates and Google/Groq chatbot integrations. Edges follow the supplied excerpts, SOURCE INDEX references, or README; unsampled subsystem links are omitted rather than inferred.

Main entry points: [`src/config/mongodb.js`](https://github.com/c0braaaa/cflix-backend/blob/main/src/config/mongodb.js) (MongoDB connection), [`src/server.js`](https://github.com/c0braaaa/cflix-backend/blob/main/src/server.js) (HTTP and sockets), [`src/services/authServices.js`](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/authServices.js) (Auth and recovery), [`src/routes/v1/index.js`](https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/index.js) (V1 API router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_server["HTTP and sockets<br/>[server.js]"]
  node_v1["V1 API router<br/>[index.js]"]
  node_authroute["Auth routes<br/>[authRoute.js]"]
  node_userroute["User routes<br/>[userRoute.js]"]
  node_reportroute["Report routes<br/>[reportRoute.js]"]
end

subgraph group_identity["Identity and users"]
  node_authmw["Token and role checks<br/>[authMiddleware.js]"]
  node_authctrl["Authentication handlers<br/>[authController.js]"]
  node_authsvc["Auth and recovery<br/>[authServices.js]"]
  node_usersctrl["User handlers<br/>[userController.js]"]
  node_usersvc["Profiles and collections<br/>[userServices.js]"]
end

subgraph group_engagement["Movie engagement"]
  node_commentctrl["Comment handlers"]
  node_commentsvc["Comment operations<br/>[commentServices.js]"]
  node_ratings["Ratings<br/>[ratingServices.js]"]
  node_views["Trending views<br/>[viewsService.js]"]
  node_chatbot["AI recommendations<br/>[chatbotService.js]"]
end

subgraph group_operations["Platform operations"]
  node_reports["Report handling"]
  node_reportservice["Report operations<br/>[reportService.js]"]
  node_notifications["Notifications"]
  node_email["Email delivery<br/>[email.js]"]
end

subgraph group_data["Persistence"]
  node_userstore[("User records<br/>[userModels.js]")]
  node_interactionstore[("User interactions")]
  node_commentstore[("Comments<br/>[commentModel.js]")]
  node_viewstore[("View records<br/>[viewsModel.js]")]
  node_reportstore[("Reports<br/>[reportModel.js]")]
  node_notifystorage[("Notification records")]
  node_mongodb[("MongoDB connection<br/>[mongodb.js]")]
end

node_client(("API client"))
node_google["Google OAuth"]
node_socket(("Socket.IO clients"))

node_client -->|"sends requests"| node_server
node_server -->|"mounts API"| node_v1
node_v1 -->|"mounts routes"| node_authroute
node_v1 -->|"mounts routes"| node_userroute
node_v1 -->|"mounts routes"| node_reportroute
node_authroute -->|"dispatches to"| node_authctrl
node_authroute -->|"guards password change"| node_authmw
node_userroute -->|"dispatches to"| node_usersctrl
node_userroute -->|"guards routes"| node_authmw
node_reportroute -->|"dispatches to"| node_reports
node_reportroute -->|"guards routes"| node_authmw
node_authctrl -->|"calls"| node_authsvc
node_authsvc -->|"reads and writes"| node_userstore
node_authsvc -->|"sends recovery email"| node_email
node_usersctrl -->|"calls"| node_usersvc
node_usersvc -->|"manages profiles"| node_userstore
node_usersvc -->|"manages collections"| node_interactionstore
node_authmw -->|"reads JWT secret"| node_server
node_commentctrl -->|"calls"| node_commentsvc
node_commentsvc -->|"accesses comments"| node_commentstore
node_commentctrl -->|"requests notifications"| node_notifications
node_notifications -->|"reads comment"| node_commentstore
node_notifications -->|"creates notifications"| node_notifystorage
node_ratings -.->|"uses rating API"| node_server
node_views -->|"queries views"| node_viewstore
node_chatbot -->|"uses view data"| node_views
node_reports -->|"calls"| node_reportservice
node_reportservice -->|"manages reports"| node_reportstore
node_server -->|"connects before serving"| node_mongodb
node_mongodb -.->|"provides database access"| node_authsvc
node_mongodb -->|"provides database access"| node_commentstore
node_mongodb -->|"provides database access"| node_userstore
node_mongodb -->|"provides database access"| node_interactionstore
node_mongodb -->|"provides database access"| node_viewstore
node_mongodb -->|"provides database access"| node_reportstore
node_authsvc -->|"verifies identity"| node_google
node_server -->|"broadcasts presence"| node_socket
node_usersctrl -->|"emits account events"| node_socket

click node_server "https://github.com/c0braaaa/cflix-backend/blob/main/src/server.js"
click node_v1 "https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/index.js"
click node_authroute "https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/authRoute.js"
click node_userroute "https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/userRoute.js"
click node_reportroute "https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/reportRoute.js"
click node_authmw "https://github.com/c0braaaa/cflix-backend/blob/main/src/middlewares/authMiddleware.js"
click node_authctrl "https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/authController.js"
click node_authsvc "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/authServices.js"
click node_usersctrl "https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/userController.js"
click node_usersvc "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/userServices.js"
click node_userstore "https://github.com/c0braaaa/cflix-backend/blob/main/src/models/userModels.js"
click node_interactionstore "https://github.com/c0braaaa/cflix-backend/blob/main/src/models/interactionsModel.js"
click node_commentctrl "https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/commentController.js"
click node_commentsvc "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/commentServices.js"
click node_commentstore "https://github.com/c0braaaa/cflix-backend/blob/main/src/models/commentModel.js"
click node_ratings "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/ratingServices.js"
click node_views "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/viewsService.js"
click node_viewstore "https://github.com/c0braaaa/cflix-backend/blob/main/src/models/viewsModel.js"
click node_chatbot "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/chatbotService.js"
click node_reports "https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/reportController.js"
click node_reportservice "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/reportService.js"
click node_reportstore "https://github.com/c0braaaa/cflix-backend/blob/main/src/models/reportModel.js"
click node_notifications "https://github.com/c0braaaa/cflix-backend/blob/main/src/services/notificationService.js"
click node_notifystorage "https://github.com/c0braaaa/cflix-backend/blob/main/src/models/notificationModel.js"
click node_mongodb "https://github.com/c0braaaa/cflix-backend/blob/main/src/config/mongodb.js"
click node_email "https://github.com/c0braaaa/cflix-backend/blob/main/src/utils/email.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_server,node_v1,node_authroute,node_userroute,node_reportroute,node_client,node_socket toneBlue
class node_authmw,node_authctrl,node_authsvc,node_usersctrl,node_usersvc toneAmber
class node_commentctrl,node_commentsvc,node_ratings,node_views,node_chatbot toneMint
class node_reports,node_reportservice,node_notifications,node_email toneRose
class node_userstore,node_interactionstore,node_commentstore,node_viewstore,node_reportstore,node_notifystorage,node_mongodb,node_google toneIndigo
```

## Components

### API entry

- [HTTP and sockets](https://github.com/c0braaaa/cflix-backend/blob/main/src/server.js): `src/server.js`
- [V1 API router](https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/index.js): `src/routes/v1/index.js`
- [Auth routes](https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/authRoute.js): `src/routes/v1/authRoute.js`
- [User routes](https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/userRoute.js): `src/routes/v1/userRoute.js`
- [Report routes](https://github.com/c0braaaa/cflix-backend/blob/main/src/routes/v1/reportRoute.js): `src/routes/v1/reportRoute.js`

### Identity and users

- [Token and role checks](https://github.com/c0braaaa/cflix-backend/blob/main/src/middlewares/authMiddleware.js): `src/middlewares/authMiddleware.js`
- [Authentication handlers](https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [Auth and recovery](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/authServices.js): `src/services/authServices.js`
- [User handlers](https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/userController.js): `src/controllers/userController.js`
- [Profiles and collections](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/userServices.js): `src/services/userServices.js`

### Movie engagement

- [Comment handlers](https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/commentController.js): `src/controllers/commentController.js`
- [Comment operations](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/commentServices.js): `src/services/commentServices.js`
- [Ratings](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/ratingServices.js): `src/services/ratingServices.js`
- [Trending views](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/viewsService.js): `src/services/viewsService.js`
- [AI recommendations](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/chatbotService.js): `src/services/chatbotService.js`

### Platform operations

- [Report handling](https://github.com/c0braaaa/cflix-backend/blob/main/src/controllers/reportController.js): `src/controllers/reportController.js`
- [Report operations](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/reportService.js): `src/services/reportService.js`
- [Notifications](https://github.com/c0braaaa/cflix-backend/blob/main/src/services/notificationService.js): `src/services/notificationService.js`
- [Email delivery](https://github.com/c0braaaa/cflix-backend/blob/main/src/utils/email.js): `src/utils/email.js`

### Persistence

- [User records](https://github.com/c0braaaa/cflix-backend/blob/main/src/models/userModels.js): `src/models/userModels.js`
- [User interactions](https://github.com/c0braaaa/cflix-backend/blob/main/src/models/interactionsModel.js): `src/models/interactionsModel.js`
- [Comments](https://github.com/c0braaaa/cflix-backend/blob/main/src/models/commentModel.js): `src/models/commentModel.js`
- [View records](https://github.com/c0braaaa/cflix-backend/blob/main/src/models/viewsModel.js): `src/models/viewsModel.js`
- [Reports](https://github.com/c0braaaa/cflix-backend/blob/main/src/models/reportModel.js): `src/models/reportModel.js`
- [Notification records](https://github.com/c0braaaa/cflix-backend/blob/main/src/models/notificationModel.js): `src/models/notificationModel.js`
- [MongoDB connection](https://github.com/c0braaaa/cflix-backend/blob/main/src/config/mongodb.js): `src/config/mongodb.js`

### Other components

- **API client**
- **Google OAuth**
- **Socket.IO clients**

## Connections

- API client → HTTP and sockets: sends requests (evidence: `src/server.js`)
- HTTP and sockets → V1 API router: mounts API (evidence: `src/server.js`)
- V1 API router → Auth routes: mounts routes (evidence: `src/routes/v1/index.js`)
- V1 API router → User routes: mounts routes (evidence: `src/routes/v1/index.js`)
- V1 API router → Report routes: mounts routes (evidence: `src/routes/v1/index.js`)
- Auth routes → Authentication handlers: dispatches to (evidence: `src/routes/v1/authRoute.js`)
- Auth routes → Token and role checks: guards password change (evidence: `src/routes/v1/authRoute.js`)
- User routes → User handlers: dispatches to (evidence: `src/routes/v1/userRoute.js`)
- User routes → Token and role checks: guards routes (evidence: `src/routes/v1/userRoute.js`)
- Report routes → Report handling: dispatches to (evidence: `src/routes/v1/reportRoute.js`)
- Report routes → Token and role checks: guards routes (evidence: `src/routes/v1/reportRoute.js`)
- Authentication handlers → Auth and recovery: calls (evidence: `src/controllers/authController.js`)
- Auth and recovery → User records: reads and writes (evidence: `src/services/authServices.js`)
- Auth and recovery → Email delivery: sends recovery email (evidence: `src/services/authServices.js`)
- User handlers → Profiles and collections: calls (evidence: `src/controllers/userController.js`)
- Profiles and collections → User records: manages profiles (evidence: `src/services/userServices.js`)
- Profiles and collections → User interactions: manages collections (evidence: `src/services/userServices.js`)
- Token and role checks → HTTP and sockets: reads JWT secret (evidence: `src/middlewares/authMiddleware.js`)
- Comment handlers → Comment operations: calls (evidence: `src/controllers/commentController.js`)
- Comment operations → Comments: accesses comments (evidence: `src/services/commentServices.js`)
- Comment handlers → Notifications: requests notifications (evidence: `src/controllers/commentController.js`)
- Notifications → Comments: reads comment (evidence: `src/services/notificationService.js`)
- Notifications → Notification records: creates notifications (evidence: `src/services/notificationService.js`)
- Ratings → HTTP and sockets: uses rating API
- Trending views → View records: queries views (evidence: `src/services/viewsService.js`)
- AI recommendations → Trending views: uses view data (evidence: `src/services/chatbotService.js`)
- Report handling → Report operations: calls (evidence: `src/controllers/reportController.js`)
- Report operations → Reports: manages reports (evidence: `src/services/reportService.js`)
- HTTP and sockets → MongoDB connection: connects before serving (evidence: `src/server.js`)
- MongoDB connection → Auth and recovery: provides database access
- MongoDB connection → Comments: provides database access (evidence: `src/models/commentModel.js`)
- MongoDB connection → User records: provides database access (evidence: `src/models/userModels.js`)
- MongoDB connection → User interactions: provides database access (evidence: `src/models/interactionsModel.js`)
- MongoDB connection → View records: provides database access (evidence: `src/models/viewsModel.js`)
- MongoDB connection → Reports: provides database access (evidence: `src/models/reportModel.js`)
- Auth and recovery → Google OAuth: verifies identity (evidence: `src/services/authServices.js`)
- HTTP and sockets → Socket.IO clients: broadcasts presence (evidence: `src/server.js`)
- User handlers → Socket.IO clients: emits account events (evidence: `src/controllers/userController.js`)
