# roshanrajan427-code/msbackend architecture

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

- Interactive diagram: https://gitdiagram.com/roshanrajan427-code/msbackend
- Repository: https://github.com/roshanrajan427-code/msbackend

## Overview

Mini Shop Backend is an HTTP API for seller-managed shops and products and customer orders. Customers verify a phone number, register or authenticate, browse shops/products, then place and track orders; sellers manage shops and inventory, review orders, and accept or reject them. The sampled handlers delegate persistence to repositories backed by PostgreSQL; product image uploads also use S3. Routes and wiring are visible in main.go. Some repository files and handler sections were not sampled, so those links are omitted where call evidence is unavailable.

Main entry points: [`main.go`](https://github.com/roshanrajan427-code/msbackend/blob/main/main.go) (HTTP routes), [`handlers/product_handler.go`](https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/product_handler.go) (Product catalog), [`handlers/auth_handler.go`](https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/auth_handler.go) (Authentication), [`repository/shop_repository.go`](https://github.com/roshanrajan427-code/msbackend/blob/main/repository/shop_repository.go) (Shop records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["HTTP routes<br/>[main.go]"]
  node_uploads["Local image files<br/>[main.go]"]
end

subgraph group_identity["Identity"]
  node_authmw["JWT middleware<br/>[middleware.go]"]
  node_jwt["JWT tokens<br/>[jwt.go]"]
  node_authh["Authentication<br/>[auth_handler.go]"]
end

subgraph group_commerce["Commerce"]
  node_shopsh["Shop management<br/>[shop_handler.go]"]
  node_productsh["Product catalog<br/>[product_handler.go]"]
  node_orderh["Order workflow<br/>[order_handler.go]"]
end

subgraph group_storage["Persistence and media"]
  node_userrepo["User records<br/>[user_repository.go]"]
  node_shoprepo["Shop records<br/>[shop_repository.go]"]
  node_productrepo["Product records"]
  node_orderrepo["Order records"]
  node_dbpool["Database pool<br/>[db.go]"]
end

node_customer(("Customer"))
node_seller(("Seller"))
node_postgres[("PostgreSQL")]
node_s3[("S3 image storage")]

node_customer -->|"uses API"| node_server
node_seller -->|"uses API"| node_server
node_server -->|"routes auth"| node_authh
node_server -->|"routes shops"| node_shopsh
node_server -->|"routes products"| node_productsh
node_server -->|"routes orders"| node_orderh
node_server -->|"protects routes"| node_authmw
node_authh -->|"looks up users"| node_userrepo
node_authh -->|"issues tokens"| node_jwt
node_authmw -.->|"validates tokens"| node_jwt
node_shopsh -->|"manages shops"| node_shoprepo
node_productsh -->|"checks ownership"| node_shoprepo
node_productsh -->|"manages products"| node_productrepo
node_orderh -->|"places and tracks"| node_orderrepo
node_dbpool -->|"opens connection"| node_postgres
node_shoprepo -.->|"reads and writes"| node_postgres
node_productrepo -.->|"reads and writes"| node_postgres
node_orderrepo -.->|"reserves stock"| node_postgres
node_userrepo -.->|"reads and writes"| node_postgres
node_productsh -->|"uploads images"| node_s3
node_server -->|"serves files"| node_uploads

click node_server "https://github.com/roshanrajan427-code/msbackend/blob/main/main.go"
click node_authmw "https://github.com/roshanrajan427-code/msbackend/blob/main/auth/middleware.go"
click node_jwt "https://github.com/roshanrajan427-code/msbackend/blob/main/auth/jwt.go"
click node_authh "https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/auth_handler.go"
click node_userrepo "https://github.com/roshanrajan427-code/msbackend/blob/main/repository/user_repository.go"
click node_shopsh "https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/shop_handler.go"
click node_shoprepo "https://github.com/roshanrajan427-code/msbackend/blob/main/repository/shop_repository.go"
click node_productsh "https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/product_handler.go"
click node_productrepo "https://github.com/roshanrajan427-code/msbackend/blob/main/repository/product_repository.go"
click node_orderh "https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/order_handler.go"
click node_orderrepo "https://github.com/roshanrajan427-code/msbackend/blob/main/repository/order_repository.go"
click node_dbpool "https://github.com/roshanrajan427-code/msbackend/blob/main/database/db.go"
click node_uploads "https://github.com/roshanrajan427-code/msbackend/blob/main/main.go"

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_uploads toneBlue
class node_authmw,node_jwt,node_authh,node_postgres,node_s3 toneAmber
class node_shopsh,node_productsh,node_orderh toneMint
class node_userrepo,node_shoprepo,node_productrepo,node_orderrepo,node_dbpool toneRose
class node_customer,node_seller toneIndigo
```

## Components

### HTTP API

- [HTTP routes](https://github.com/roshanrajan427-code/msbackend/blob/main/main.go): `main.go`
- [Local image files](https://github.com/roshanrajan427-code/msbackend/blob/main/main.go): `main.go`

### Identity

- [JWT middleware](https://github.com/roshanrajan427-code/msbackend/blob/main/auth/middleware.go): `auth/middleware.go`
- [JWT tokens](https://github.com/roshanrajan427-code/msbackend/blob/main/auth/jwt.go): `auth/jwt.go`
- [Authentication](https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/auth_handler.go): `handlers/auth_handler.go`

### Commerce

- [Shop management](https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/shop_handler.go): `handlers/shop_handler.go`
- [Product catalog](https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/product_handler.go): `handlers/product_handler.go`
- [Order workflow](https://github.com/roshanrajan427-code/msbackend/blob/main/handlers/order_handler.go): `handlers/order_handler.go`

### Persistence and media

- [User records](https://github.com/roshanrajan427-code/msbackend/blob/main/repository/user_repository.go): `repository/user_repository.go`
- [Shop records](https://github.com/roshanrajan427-code/msbackend/blob/main/repository/shop_repository.go): `repository/shop_repository.go`
- [Product records](https://github.com/roshanrajan427-code/msbackend/blob/main/repository/product_repository.go): `repository/product_repository.go`
- [Order records](https://github.com/roshanrajan427-code/msbackend/blob/main/repository/order_repository.go): `repository/order_repository.go`
- [Database pool](https://github.com/roshanrajan427-code/msbackend/blob/main/database/db.go): `database/db.go`

### Other components

- **Customer**
- **Seller**
- **PostgreSQL**
- **S3 image storage**

## Connections

- Customer → HTTP routes: uses API (evidence: `main.go`)
- Seller → HTTP routes: uses API (evidence: `main.go`)
- HTTP routes → Authentication: routes auth (evidence: `main.go`)
- HTTP routes → Shop management: routes shops (evidence: `main.go`)
- HTTP routes → Product catalog: routes products (evidence: `main.go`)
- HTTP routes → Order workflow: routes orders (evidence: `main.go`)
- HTTP routes → JWT middleware: protects routes (evidence: `main.go`)
- Authentication → User records: looks up users (evidence: `handlers/auth_handler.go`)
- Authentication → JWT tokens: issues tokens (evidence: `handlers/auth_handler.go`)
- JWT middleware → JWT tokens: validates tokens
- Shop management → Shop records: manages shops (evidence: `handlers/shop_handler.go`)
- Product catalog → Shop records: checks ownership (evidence: `handlers/product_handler.go`)
- Product catalog → Product records: manages products (evidence: `handlers/product_handler.go`)
- Order workflow → Order records: places and tracks (evidence: `handlers/order_handler.go`)
- Database pool → PostgreSQL: opens connection (evidence: `database/db.go`)
- Shop records → PostgreSQL: reads and writes
- Product records → PostgreSQL: reads and writes
- Order records → PostgreSQL: reserves stock
- User records → PostgreSQL: reads and writes
- Product catalog → S3 image storage: uploads images
- HTTP routes → Local image files: serves files (evidence: `main.go`)
