# hasibulhasanjoy/talkwide-backend architecture

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

- Interactive diagram: https://gitdiagram.com/hasibulhasanjoy/talkwide-backend
- Repository: https://github.com/hasibulhasanjoy/talkwide-backend

## Overview

Talkwide is a social discussion backend. The main workflow accepts client HTTP requests, mounts API routes, and handles domain operations such as authentication, posts, comments, communities, and search before returning JSON responses. The documented architecture separates middleware, controllers, services, and Mongoose models; sampled controller imports and calls substantiate several domain-service links. The README documents additional capabilities, including feeds, voting, nested comments, moderation, and security. Some route handlers and community subservice wiring were not sampled, so those relationships are omitted or marked unverified.

Main entry points: [`src/app.ts`](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/app.ts) (Express Application), [`src/models/user.model.ts`](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/user.model.ts) (User Accounts), [`src/services/auth.service.ts`](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/auth.service.ts) (Account Services), [`src/services/post.service.ts`](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/post.service.ts) (Feed And Voting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["API Platform"]
  node_app["Express Application<br/>[app.ts]"]
  node_security["Security Middleware"]
  node_validation["Request Validation"]
  node_errors["Error Handling"]
  node_database[("MongoDB<br/>[db.ts]")]
end

subgraph group_identity["Identity"]
  node_auth_routes["Auth Routes<br/>[oauth.route.ts]"]
  node_auth_controller["Authentication<br/>[auth.controller.ts]"]
  node_oauth_controller["Google OAuth"]
  node_auth_service["Account Services<br/>[auth.service.ts]"]
  node_email["Email Delivery<br/>[mail.service.ts]"]
  node_user_store[("User Accounts<br/>[user.model.ts]")]
end

subgraph group_content["Posts And Comments"]
  node_post_routes["Post Routes<br/>[post.route.ts]"]
  node_post_controller["Post Operations<br/>[post.controller.ts]"]
  node_post_service["Feed And Voting<br/>[post.service.ts]"]
  node_post_store[("Posts<br/>[post.model.ts]")]
  node_media["Cloudinary Media"]
  node_comment_routes["Comment Routes<br/>[comment.route.ts]"]
  node_comment_controller["Comment Operations"]
  node_comment_service["Comment Trees<br/>[comment.service.ts]"]
  node_comment_store[("Comments<br/>[comment.model.ts]")]
end

subgraph group_communities["Communities"]
  node_community_routes["Community Routes<br/>[community.route.ts]"]
  node_community_controller["Community Operations"]
  node_community_service["Community Services"]
  node_community_store[("Communities<br/>[community.model.ts]")]
end

subgraph group_discovery["Discovery"]
  node_search_routes["Search Routes<br/>[search.route.ts]"]
  node_search_controller["Search Endpoint"]
  node_search_service["Unified Search<br/>[search.service.ts]"]
end

node_client(("HTTP Client"))

node_client -->|"sends requests"| node_app
node_app -->|"applies sanitization"| node_security
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_post_routes
node_app -->|"mounts"| node_comment_routes
node_app -->|"mounts"| node_community_routes
node_app -->|"mounts"| node_search_routes
node_app -->|"handles errors"| node_errors
node_auth_routes -->|"routes to"| node_oauth_controller
node_search_routes -->|"routes to"| node_search_controller
node_auth_controller -->|"calls"| node_auth_service
node_auth_controller -->|"sends mail"| node_email
node_oauth_controller -->|"queries"| node_user_store
node_auth_service -->|"creates accounts"| node_user_store
node_auth_service -.-> node_email
node_post_controller -->|"calls"| node_post_service
node_post_controller -->|"uploads media"| node_media
node_post_service -->|"queries"| node_post_store
node_post_service -.->|"updates karma"| node_user_store
node_comment_controller -->|"calls"| node_comment_service
node_comment_service -->|"manages trees"| node_comment_store
node_comment_service -->|"updates counts"| node_post_store
node_community_controller -->|"calls"| node_community_service
node_community_service -.->|"manages communities"| node_community_store
node_community_service -.-> node_post_store
node_search_routes -->|"validates requests"| node_validation
node_search_controller -->|"queries"| node_search_service
node_search_service -->|"searches users"| node_user_store
node_search_service -->|"searches communities"| node_community_store

click node_app "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/app.ts"
click node_security "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/middlewares/sanitize.middleware.ts"
click node_validation "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/middlewares/validate.middleware.ts"
click node_errors "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/middlewares/error.middleware.ts"
click node_database "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/config/db.ts"
click node_auth_routes "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/oauth.route.ts"
click node_auth_controller "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/auth.controller.ts"
click node_oauth_controller "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/oauth.controller.ts"
click node_auth_service "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/auth.service.ts"
click node_email "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/mail.service.ts"
click node_user_store "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/user.model.ts"
click node_post_routes "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/post.route.ts"
click node_post_controller "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/post.controller.ts"
click node_post_service "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/post.service.ts"
click node_post_store "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/post.model.ts"
click node_media "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/cloudinary.service.ts"
click node_comment_routes "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/comment.route.ts"
click node_comment_controller "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/comment.controller.ts"
click node_comment_service "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/comment.service.ts"
click node_comment_store "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/comment.model.ts"
click node_community_routes "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/community.route.ts"
click node_community_controller "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/community.controller.ts"
click node_community_service "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/community.service.ts"
click node_community_store "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/community.model.ts"
click node_search_routes "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/search.route.ts"
click node_search_controller "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/search.controller.ts"
click node_search_service "https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/search.service.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_app,node_security,node_validation,node_errors,node_database,node_client toneBlue
class node_auth_routes,node_auth_controller,node_oauth_controller,node_auth_service,node_email,node_user_store toneAmber
class node_post_routes,node_post_controller,node_post_service,node_post_store,node_media,node_comment_routes,node_comment_controller,node_comment_service,node_comment_store toneMint
class node_community_routes,node_community_controller,node_community_service,node_community_store toneRose
class node_search_routes,node_search_controller,node_search_service toneIndigo
```

## Components

### API Platform

- [Express Application](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/app.ts): `src/app.ts`
- [Security Middleware](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/middlewares/sanitize.middleware.ts): `src/middlewares/sanitize.middleware.ts`
- [Request Validation](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/middlewares/validate.middleware.ts): `src/middlewares/validate.middleware.ts`
- [Error Handling](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/middlewares/error.middleware.ts): `src/middlewares/error.middleware.ts`
- [MongoDB](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/config/db.ts): `src/config/db.ts`

### Identity

- [Auth Routes](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/oauth.route.ts): `src/routes/oauth.route.ts`
- [Authentication](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/auth.controller.ts): `src/controllers/auth.controller.ts`
- [Google OAuth](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/oauth.controller.ts): `src/controllers/oauth.controller.ts`
- [Account Services](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/auth.service.ts): `src/services/auth.service.ts`
- [Email Delivery](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/mail.service.ts): `src/services/mail.service.ts`
- [User Accounts](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/user.model.ts): `src/models/user.model.ts`

### Posts And Comments

- [Post Routes](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/post.route.ts): `src/routes/post.route.ts`
- [Post Operations](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/post.controller.ts): `src/controllers/post.controller.ts`
- [Feed And Voting](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/post.service.ts): `src/services/post.service.ts`
- [Posts](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/post.model.ts): `src/models/post.model.ts`
- [Cloudinary Media](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/cloudinary.service.ts): `src/services/cloudinary.service.ts`
- [Comment Routes](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/comment.route.ts): `src/routes/comment.route.ts`
- [Comment Operations](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/comment.controller.ts): `src/controllers/comment.controller.ts`
- [Comment Trees](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/comment.service.ts): `src/services/comment.service.ts`
- [Comments](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/comment.model.ts): `src/models/comment.model.ts`

### Communities

- [Community Routes](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/community.route.ts): `src/routes/community.route.ts`
- [Community Operations](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/community.controller.ts): `src/controllers/community.controller.ts`
- [Community Services](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/community.service.ts): `src/services/community.service.ts`
- [Communities](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/models/community.model.ts): `src/models/community.model.ts`

### Discovery

- [Search Routes](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/routes/search.route.ts): `src/routes/search.route.ts`
- [Search Endpoint](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/controllers/search.controller.ts): `src/controllers/search.controller.ts`
- [Unified Search](https://github.com/hasibulhasanjoy/talkwide-backend/blob/main/src/services/search.service.ts): `src/services/search.service.ts`

### Other components

- **HTTP Client**

## Connections

- HTTP Client → Express Application: sends requests
- Express Application → Security Middleware: applies sanitization (evidence: `src/app.ts`)
- Express Application → Auth Routes: mounts (evidence: `src/app.ts`)
- Express Application → Post Routes: mounts (evidence: `src/app.ts`)
- Express Application → Comment Routes: mounts (evidence: `src/app.ts`)
- Express Application → Community Routes: mounts (evidence: `src/app.ts`)
- Express Application → Search Routes: mounts (evidence: `src/app.ts`)
- Express Application → Error Handling: handles errors (evidence: `src/app.ts`)
- Auth Routes → Google OAuth: routes to (evidence: `src/routes/oauth.route.ts`)
- Search Routes → Search Endpoint: routes to (evidence: `src/routes/search.route.ts`)
- Authentication → Account Services: calls (evidence: `src/controllers/auth.controller.ts`)
- Authentication → Email Delivery: sends mail (evidence: `src/controllers/auth.controller.ts`)
- Google OAuth → User Accounts: queries (evidence: `src/controllers/oauth.controller.ts`)
- Account Services → User Accounts: creates accounts (evidence: `src/services/auth.service.ts`)
- Account Services → Email Delivery
- Post Operations → Feed And Voting: calls (evidence: `src/controllers/post.controller.ts`)
- Post Operations → Cloudinary Media: uploads media (evidence: `src/controllers/post.controller.ts`)
- Feed And Voting → Posts: queries (evidence: `src/services/post.service.ts`)
- Feed And Voting → User Accounts: updates karma (evidence: `src/services/post.service.ts`)
- Comment Operations → Comment Trees: calls (evidence: `src/controllers/comment.controller.ts`)
- Comment Trees → Comments: manages trees (evidence: `src/services/comment.service.ts`)
- Comment Trees → Posts: updates counts (evidence: `src/services/comment.service.ts`)
- Community Operations → Community Services: calls (evidence: `src/controllers/community.controller.ts`)
- Community Services → Communities: manages communities
- Community Services → Posts
- Search Routes → Request Validation: validates requests (evidence: `src/routes/search.route.ts`)
- Search Endpoint → Unified Search: queries
- Unified Search → User Accounts: searches users (evidence: `src/services/search.service.ts`)
- Unified Search → Communities: searches communities (evidence: `src/services/search.service.ts`)
