# gokulreddy05/backend-blog-api architecture

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

- Interactive diagram: https://gitdiagram.com/gokulreddy05/backend-blog-api
- Repository: https://github.com/gokulreddy05/backend-blog-api

## Overview

This is an Express REST API for user authentication and blog posts with comments. Requests enter through the server’s mounted routes; authentication endpoints register users or return access tokens, while protected post and comment endpoints validate bearer tokens before controllers call domain services. Services implement persistence through Prisma backed by PostgreSQL. The README also documents post search, publication filtering, and pagination. Route, controller, service, and database edges are grounded in the supplied source index or excerpts; schema and migration details are not expanded beyond the README because their contents were not sampled.

Main entry points: [`src/config/db.js`](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/config/db.js) (Prisma client), [`src/server.js`](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/server.js) (Express server), [`src/routes/postRoute.js`](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/postRoute.js) (Post routes), [`src/routes/commentRoute.js`](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/commentRoute.js) (Comment routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_server["Express server<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>[authRoute.js]"]
  node_post_routes["Post routes<br/>[postRoute.js]"]
  node_comment_routes["Comment routes<br/>[commentRoute.js]"]
end

subgraph group_identity["Identity"]
  node_auth_controller["Auth handlers<br/>[authController.js]"]
  node_auth_middleware["JWT guard<br/>[authMiddleware.js]"]
  node_auth_service["Auth operations<br/>[authService.js]"]
end

subgraph group_content["Blog Content"]
  node_post_controller["Post handlers<br/>[postController.js]"]
  node_post_service["Post operations<br/>[postService.js]"]
  node_comment_controller["Comment handlers"]
  node_comment_service["Comment operations<br/>[commentService.js]"]
end

subgraph group_persistence["Persistence"]
  node_prisma_schema["Data model<br/>[schema.prisma]"]
  node_db_client["Prisma client<br/>[db.js]"]
  node_postgres[("PostgreSQL")]
end

node_client(("API caller"))

node_client -->|"sends requests"| node_server
node_server -->|"mounts at /api/auth"| node_auth_routes
node_server -->|"mounts at /api/posts"| node_post_routes
node_server -->|"mounts at /api/posts"| node_comment_routes
node_auth_routes -->|"routes to"| node_auth_controller
node_post_routes -->|"routes to"| node_post_controller
node_comment_routes -->|"routes to"| node_comment_controller
node_post_routes -->|"guards writes"| node_auth_middleware
node_comment_routes -->|"guards endpoints"| node_auth_middleware
node_auth_controller -->|"calls"| node_auth_service
node_post_controller -->|"calls"| node_post_service
node_comment_controller -->|"calls"| node_comment_service
node_auth_service -->|"queries users"| node_db_client
node_post_service -->|"queries posts"| node_db_client
node_comment_service -->|"queries comments"| node_db_client
node_server -->|"connects at startup"| node_db_client
node_db_client -->|"uses adapter pool"| node_postgres
node_prisma_schema -.->|"defines ORM model"| node_db_client

click node_server "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/server.js"
click node_auth_routes "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/authRoute.js"
click node_post_routes "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/postRoute.js"
click node_comment_routes "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/commentRoute.js"
click node_auth_controller "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/controllers/authController.js"
click node_auth_middleware "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/middleware/authMiddleware.js"
click node_auth_service "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/services/authService.js"
click node_post_controller "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/controllers/postController.js"
click node_post_service "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/services/postService.js"
click node_comment_controller "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/controllers/commentController.js"
click node_comment_service "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/services/commentService.js"
click node_prisma_schema "https://github.com/gokulreddy05/backend-blog-api/blob/main/prisma/schema.prisma"
click node_db_client "https://github.com/gokulreddy05/backend-blog-api/blob/main/src/config/db.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_auth_routes,node_post_routes,node_comment_routes toneBlue
class node_auth_controller,node_auth_middleware,node_auth_service toneAmber
class node_post_controller,node_post_service,node_comment_controller,node_comment_service,node_client toneMint
class node_prisma_schema,node_db_client,node_postgres toneRose
```

## Components

### HTTP API

- [Express server](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/server.js): `src/server.js`
- [Auth routes](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/authRoute.js): `src/routes/authRoute.js`
- [Post routes](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/postRoute.js): `src/routes/postRoute.js`
- [Comment routes](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/routes/commentRoute.js): `src/routes/commentRoute.js`

### Identity

- [Auth handlers](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [JWT guard](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/middleware/authMiddleware.js): `src/middleware/authMiddleware.js`
- [Auth operations](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/services/authService.js): `src/services/authService.js`

### Blog Content

- [Post handlers](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/controllers/postController.js): `src/controllers/postController.js`
- [Post operations](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/services/postService.js): `src/services/postService.js`
- [Comment handlers](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/controllers/commentController.js): `src/controllers/commentController.js`
- [Comment operations](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/services/commentService.js): `src/services/commentService.js`

### Persistence

- [Data model](https://github.com/gokulreddy05/backend-blog-api/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Prisma client](https://github.com/gokulreddy05/backend-blog-api/blob/main/src/config/db.js): `src/config/db.js`
- **PostgreSQL**

### Other components

- **API caller**

## Connections

- API caller → Express server: sends requests (evidence: `README.md`)
- Express server → Auth routes: mounts at /api/auth (evidence: `src/server.js`)
- Express server → Post routes: mounts at /api/posts (evidence: `src/server.js`)
- Express server → Comment routes: mounts at /api/posts (evidence: `src/server.js`)
- Auth routes → Auth handlers: routes to (evidence: `src/routes/authRoute.js`)
- Post routes → Post handlers: routes to (evidence: `src/routes/postRoute.js`)
- Comment routes → Comment handlers: routes to (evidence: `src/routes/commentRoute.js`)
- Post routes → JWT guard: guards writes (evidence: `src/routes/postRoute.js`)
- Comment routes → JWT guard: guards endpoints (evidence: `src/routes/commentRoute.js`)
- Auth handlers → Auth operations: calls (evidence: `src/controllers/authController.js`)
- Post handlers → Post operations: calls (evidence: `src/controllers/postController.js`)
- Comment handlers → Comment operations: calls (evidence: `src/controllers/commentController.js`)
- Auth operations → Prisma client: queries users (evidence: `src/services/authService.js`)
- Post operations → Prisma client: queries posts (evidence: `src/services/postService.js`)
- Comment operations → Prisma client: queries comments (evidence: `src/services/commentService.js`)
- Express server → Prisma client: connects at startup (evidence: `src/server.js`)
- Prisma client → PostgreSQL: uses adapter pool (evidence: `src/config/db.js`)
- Data model → Prisma client: defines ORM model
