# tieuhoang-dev/livetream_app architecture

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

- Interactive diagram: https://gitdiagram.com/tieuhoang-dev/livetream_app
- Repository: https://github.com/tieuhoang-dev/livetream_app

## Overview

This repository is a livestream-commerce backend: users authenticate, manage products and orders, pay or refund, and interact with livestreams and chat. The visible runtime entry point initializes databases and workers before registering HTTP routes. The graph preserves the documented route areas and the indexed core service modules; several controller and service implementations were not excerpted, so their internal calls are not inferred. Chat queue-to-worker persistence and livestream handler calls are shown where excerpts provide direct evidence.

Main entry points: [`routes/user.go`](https://github.com/tieuhoang-dev/livetream_app/blob/main/routes/user.go) (API routes), [`controller/controller/livestream.go`](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/livestream.go) (Livestream handlers), [`cmd/main.go`](https://github.com/tieuhoang-dev/livetream_app/blob/main/cmd/main.go) (Application startup), [`controller/services/chat_worker_service.go`](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/chat_worker_service.go) (Chat persistence workers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and routing"]
  node_server["Application startup<br/>[main.go]"]
  node_routes["API routes<br/>[user.go]"]
  node_auth["Authentication middleware<br/>[auth.go]"]
end

subgraph group_accounts["Accounts and commerce"]
  node_users["User handlers<br/>[User.go]"]
  node_user_service["User service<br/>[User.go]"]
  node_products["Product handlers<br/>[products.go]"]
  node_product_service["Product service<br/>[products.go]"]
  node_orders["Order handlers<br/>[order_queries.go]"]
  node_order_service["Order service<br/>[orders.go]"]
  node_transactions["Transaction handlers<br/>[transactions.go]"]
  node_transaction_service["Transaction service<br/>[transactions.go]"]
end

subgraph group_live["Livestream and chat"]
  node_live_handlers["Livestream handlers<br/>[livestream.go]"]
  node_live_service["Livestream service<br/>[livestreams.go]"]
  node_chat_queue["Chat queue producer"]
  node_chat_workers["Chat persistence workers"]
end

subgraph group_persistence["Persistence"]
  node_sql[("SQL database")]
  node_redis["Redis stream"]
  node_mongo[("Mongo chat store")]
  node_models["Domain models<br/>[user_model.go]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_routes
node_routes -->|"routes user requests"| node_users
node_routes -->|"protects routes"| node_auth
node_routes -->|"routes order requests"| node_orders
node_routes -->|"routes sales requests"| node_transactions
node_routes -->|"routes livestream and chat"| node_live_handlers
node_server -->|"registers routes"| node_routes
node_server -->|"runs migrations"| node_models
node_server -->|"sets database"| node_live_handlers
node_server -->|"starts workers"| node_chat_workers
node_live_handlers -->|"queues messages"| node_chat_queue
node_live_handlers -->|"ends livestream"| node_live_service
node_chat_queue -->|"appends messages"| node_redis
node_chat_workers -->|"reads and acknowledges"| node_redis
node_chat_workers -->|"inserts chat batches"| node_mongo
node_live_handlers -->|"creates and queries streams"| node_sql

click node_server "https://github.com/tieuhoang-dev/livetream_app/blob/main/cmd/main.go"
click node_routes "https://github.com/tieuhoang-dev/livetream_app/blob/main/routes/user.go"
click node_auth "https://github.com/tieuhoang-dev/livetream_app/blob/main/middlewares/auth.go"
click node_users "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/User.go"
click node_user_service "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/User.go"
click node_products "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/products.go"
click node_product_service "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/products.go"
click node_orders "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/order_queries.go"
click node_order_service "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/orders.go"
click node_transactions "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/transactions.go"
click node_transaction_service "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/transactions.go"
click node_live_handlers "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/livestream.go"
click node_live_service "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/livestreams.go"
click node_chat_queue "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/chat_queue_service.go"
click node_chat_workers "https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/chat_worker_service.go"
click node_models "https://github.com/tieuhoang-dev/livetream_app/blob/main/models/user_model.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_routes,node_auth,node_client toneBlue
class node_users,node_user_service,node_products,node_product_service,node_orders,node_order_service,node_transactions,node_transaction_service toneAmber
class node_live_handlers,node_live_service,node_chat_queue,node_chat_workers toneMint
class node_sql,node_redis,node_mongo,node_models toneRose
```

## Components

### Runtime and routing

- [Application startup](https://github.com/tieuhoang-dev/livetream_app/blob/main/cmd/main.go): `cmd/main.go`
- [API routes](https://github.com/tieuhoang-dev/livetream_app/blob/main/routes/user.go): `routes/user.go`
- [Authentication middleware](https://github.com/tieuhoang-dev/livetream_app/blob/main/middlewares/auth.go): `middlewares/auth.go`

### Accounts and commerce

- [User handlers](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/User.go): `controller/controller/User.go`
- [User service](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/User.go): `controller/services/User.go`
- [Product handlers](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/products.go): `controller/controller/products.go`
- [Product service](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/products.go): `controller/services/products.go`
- [Order handlers](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/order_queries.go): `controller/controller/order_queries.go`
- [Order service](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/orders.go): `controller/services/orders.go`
- [Transaction handlers](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/transactions.go): `controller/controller/transactions.go`
- [Transaction service](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/transactions.go): `controller/services/transactions.go`

### Livestream and chat

- [Livestream handlers](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/controller/livestream.go): `controller/controller/livestream.go`
- [Livestream service](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/livestreams.go): `controller/services/livestreams.go`
- [Chat queue producer](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/chat_queue_service.go): `controller/services/chat_queue_service.go`
- [Chat persistence workers](https://github.com/tieuhoang-dev/livetream_app/blob/main/controller/services/chat_worker_service.go): `controller/services/chat_worker_service.go`

### Persistence

- **SQL database**
- **Redis stream**
- **Mongo chat store**
- [Domain models](https://github.com/tieuhoang-dev/livetream_app/blob/main/models/user_model.go): `models/user_model.go`

### Other components

- **API client**

## Connections

- API client → API routes: sends requests (evidence: `routes/user.go`)
- API routes → User handlers: routes user requests (evidence: `routes/user.go`)
- API routes → Authentication middleware: protects routes (evidence: `routes/user.go`)
- API routes → Order handlers: routes order requests (evidence: `routes/user.go`)
- API routes → Transaction handlers: routes sales requests (evidence: `routes/user.go`)
- API routes → Livestream handlers: routes livestream and chat (evidence: `routes/user.go`)
- Application startup → API routes: registers routes (evidence: `cmd/main.go`)
- Application startup → Domain models: runs migrations (evidence: `cmd/main.go`)
- Application startup → Livestream handlers: sets database (evidence: `cmd/main.go`)
- Application startup → Chat persistence workers: starts workers (evidence: `cmd/main.go`)
- Livestream handlers → Chat queue producer: queues messages (evidence: `controller/controller/livestream.go`)
- Livestream handlers → Livestream service: ends livestream (evidence: `controller/controller/livestream.go`)
- Chat queue producer → Redis stream: appends messages (evidence: `controller/services/chat_queue_service.go`)
- Chat persistence workers → Redis stream: reads and acknowledges (evidence: `controller/services/chat_worker_service.go`)
- Chat persistence workers → Mongo chat store: inserts chat batches (evidence: `controller/services/chat_worker_service.go`)
- Livestream handlers → SQL database: creates and queries streams (evidence: `controller/controller/livestream.go`)
