# narayan-bhattarai/news-portal-backend architecture

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

- Interactive diagram: https://gitdiagram.com/narayan-bhattarai/news-portal-backend
- Repository: https://github.com/narayan-bhattarai/news-portal-backend

## Overview

This is an ASP.NET Core news-portal API: readers and staff use HTTP endpoints for news, categories, pages, comments, contact submissions, uploads, and account features; staff also have a live chat. Controllers and the SignalR hub handle requests, while the EF Core context persists domain data. The graph includes these distinct capabilities, plus authentication and request hosting. Some controller implementations are unsampled; their paths and capabilities are supported by the source index, but only documented or excerpt-visible relationships are linked.

Main entry points: [`Data/NewsContext.cs`](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Data/NewsContext.cs) (News data context), [`Program.cs`](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Program.cs) (ASP.NET API host), [`Controllers/AuthController.cs`](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/AuthController.cs) (Authentication API), [`Controllers/ArticlesController.cs`](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ArticlesController.cs) (Articles API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_content["News content"]
  node_articles["Articles API"]
  node_categories["Categories API"]
  node_pages["Pages API<br/>[PagesController.cs]"]
  node_uploads["Uploads API"]
  node_article_model["Article model<br/>[Article.cs]"]
end

subgraph group_community["Community features"]
  node_comments["Comments API"]
  node_contact["Contact API"]
  node_chat_api["Chat history API<br/>[ChatController.cs]"]
  node_chat_hub["Live chat hub<br/>[ChatHub.cs]"]
  node_comment_model["Comment model<br/>[Comment.cs]"]
  node_chat_model["Chat message model<br/>[ChatMessage.cs]"]
end

subgraph group_identity["Identity and access"]
  node_auth["Authentication API<br/>[AuthController.cs]"]
  node_users["Users API<br/>[UsersController.cs]"]
  node_user_model["User model<br/>[User.cs]"]
  node_login_request["Login request<br/>[LoginRequest.cs]"]
  node_dynamic_models["Request models<br/>[DynamicModels.cs]"]
end

subgraph group_platform["API runtime"]
  node_context[("News data context<br/>[NewsContext.cs]")]
  node_database[("PostgreSQL database")]
  node_api_host["ASP.NET API host<br/>[Program.cs]"]
  node_error_middleware["Exception handling"]
end

node_readers(("Readers and staff"))
node_facebook["Facebook identity service"]

node_readers -->|"send requests"| node_api_host
node_api_host -->|"routes requests"| node_articles
node_api_host -->|"maps hub"| node_chat_hub
node_articles -->|"reads and writes"| node_context
node_categories -->|"reads categories"| node_context
node_pages -->|"reads pages"| node_context
node_contact -->|"uses context"| node_context
node_comments -->|"reads and writes"| node_context
node_chat_api -->|"reads and writes"| node_context
node_chat_hub -->|"reads and writes"| node_context
node_auth -->|"verifies token"| node_facebook
node_auth -->|"manages accounts"| node_user_model
node_auth -->|"accepts credentials"| node_login_request
node_users -->|"manages users"| node_user_model
node_articles -->|"queries articles"| node_article_model
node_comments -->|"creates comments"| node_comment_model
node_chat_api -->|"queries messages"| node_chat_model
node_chat_hub -->|"persists messages"| node_chat_model
node_context -.->|"persists domain data"| node_database
node_api_host -->|"configures database"| node_context
node_api_host -->|"configures identity"| node_user_model
node_api_host -.->|"uses middleware"| node_error_middleware

click node_articles "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ArticlesController.cs"
click node_categories "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/CategoriesController.cs"
click node_pages "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/PagesController.cs"
click node_uploads "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/UploadsController.cs"
click node_article_model "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/Article.cs"
click node_comments "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/CommentsController.cs"
click node_contact "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ContactController.cs"
click node_chat_api "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ChatController.cs"
click node_chat_hub "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Hubs/ChatHub.cs"
click node_comment_model "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/Comment.cs"
click node_chat_model "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/ChatMessage.cs"
click node_auth "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/AuthController.cs"
click node_users "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/UsersController.cs"
click node_user_model "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/User.cs"
click node_login_request "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/LoginRequest.cs"
click node_dynamic_models "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/DynamicModels.cs"
click node_context "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Data/NewsContext.cs"
click node_api_host "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Program.cs"
click node_error_middleware "https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Middleware/ExceptionHandlingMiddleware.cs"

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_articles,node_categories,node_pages,node_uploads,node_article_model toneBlue
class node_comments,node_contact,node_chat_api,node_chat_hub,node_comment_model,node_chat_model toneAmber
class node_auth,node_users,node_user_model,node_login_request,node_dynamic_models toneMint
class node_context,node_database,node_api_host,node_error_middleware toneRose
class node_readers,node_facebook toneIndigo
```

## Components

### News content

- [Articles API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ArticlesController.cs): `Controllers/ArticlesController.cs`
- [Categories API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/CategoriesController.cs): `Controllers/CategoriesController.cs`
- [Pages API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/PagesController.cs): `Controllers/PagesController.cs`
- [Uploads API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/UploadsController.cs): `Controllers/UploadsController.cs`
- [Article model](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/Article.cs): `Models/Article.cs`

### Community features

- [Comments API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/CommentsController.cs): `Controllers/CommentsController.cs`
- [Contact API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ContactController.cs): `Controllers/ContactController.cs`
- [Chat history API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/ChatController.cs): `Controllers/ChatController.cs`
- [Live chat hub](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Hubs/ChatHub.cs): `Hubs/ChatHub.cs`
- [Comment model](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/Comment.cs): `Models/Comment.cs`
- [Chat message model](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/ChatMessage.cs): `Models/ChatMessage.cs`

### Identity and access

- [Authentication API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/AuthController.cs): `Controllers/AuthController.cs`
- [Users API](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Controllers/UsersController.cs): `Controllers/UsersController.cs`
- [User model](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/User.cs): `Models/User.cs`
- [Login request](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/LoginRequest.cs): `Models/LoginRequest.cs`
- [Request models](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Models/DynamicModels.cs): `Models/DynamicModels.cs`

### API runtime

- [News data context](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Data/NewsContext.cs): `Data/NewsContext.cs`
- **PostgreSQL database**
- [ASP.NET API host](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Program.cs): `Program.cs`
- [Exception handling](https://github.com/narayan-bhattarai/news-portal-backend/blob/main/Middleware/ExceptionHandlingMiddleware.cs): `Middleware/ExceptionHandlingMiddleware.cs`

### Other components

- **Readers and staff**
- **Facebook identity service**

## Connections

- Readers and staff → ASP.NET API host: send requests (evidence: `Program.cs`)
- ASP.NET API host → Articles API: routes requests (evidence: `Program.cs`)
- ASP.NET API host → Live chat hub: maps hub (evidence: `Program.cs`)
- Articles API → News data context: reads and writes (evidence: `Controllers/ArticlesController.cs`)
- Categories API → News data context: reads categories (evidence: `Controllers/CategoriesController.cs`)
- Pages API → News data context: reads pages (evidence: `Controllers/PagesController.cs`)
- Contact API → News data context: uses context (evidence: `Controllers/ContactController.cs`)
- Comments API → News data context: reads and writes (evidence: `Controllers/CommentsController.cs`)
- Chat history API → News data context: reads and writes (evidence: `Controllers/ChatController.cs`)
- Live chat hub → News data context: reads and writes (evidence: `Hubs/ChatHub.cs`)
- Authentication API → Facebook identity service: verifies token (evidence: `Controllers/AuthController.cs`)
- Authentication API → User model: manages accounts (evidence: `Controllers/AuthController.cs`)
- Authentication API → Login request: accepts credentials (evidence: `Controllers/AuthController.cs`)
- Users API → User model: manages users (evidence: `Controllers/UsersController.cs`)
- Articles API → Article model: queries articles (evidence: `Controllers/ArticlesController.cs`)
- Comments API → Comment model: creates comments (evidence: `Controllers/CommentsController.cs`)
- Chat history API → Chat message model: queries messages (evidence: `Controllers/ChatController.cs`)
- Live chat hub → Chat message model: persists messages (evidence: `Hubs/ChatHub.cs`)
- News data context → PostgreSQL database: persists domain data
- ASP.NET API host → News data context: configures database (evidence: `Program.cs`)
- ASP.NET API host → User model: configures identity (evidence: `Program.cs`)
- ASP.NET API host → Exception handling: uses middleware (evidence: `Program.cs`)
