# mcaqnn1/gochat architecture

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

- Interactive diagram: https://gitdiagram.com/mcaqnn1/gochat
- Repository: https://github.com/mcaqnn1/gochat

## Overview

This Go chat backend exposes HTTP authentication/user endpoints and a gRPC room-creation endpoint. The visible registration/login flow validates users, hashes passwords through the user service, persists records, and issues JWTs; room creation is handled through gRPC. The source excerpts show startup wiring and selected request paths, but the README is empty and substantial service, room-storage, Redis, and HTTP-server details were not sampled, so uncertain connections are omitted.

Main entry points: [`cmd/app/main.go`](https://github.com/mcaqnn1/gochat/blob/main/cmd/app/main.go) (Application startup), [`internal/handler/auth.go`](https://github.com/mcaqnn1/gochat/blob/main/internal/handler/auth.go) (Auth endpoints), [`internal/transport/grpcserver/server.go`](https://github.com/mcaqnn1/gochat/blob/main/internal/transport/grpcserver/server.go) (gRPC server), [`internal/service/user.go`](https://github.com/mcaqnn1/gochat/blob/main/internal/service/user.go) (User operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API transports"]
  node_bootstrap["Application startup<br/>[main.go]"]
  node_http_server["HTTP server<br/>[server.go]"]
  node_http_router["HTTP routes<br/>[router.go]"]
  node_auth_handler["Auth endpoints<br/>[auth.go]"]
  node_user_handler["User endpoints<br/>[user.go]"]
  node_grpc_server["gRPC server<br/>[server.go]"]
  node_room_handler["Room endpoint<br/>[room.go]"]
  node_grpc_contract["Room gRPC contract<br/>[room.proto]"]
end

subgraph group_domain["Domain services"]
  node_user_service["User operations<br/>[user.go]"]
  node_room_service["Room operations<br/>[room.go]"]
  node_email_service["Email delivery<br/>[email_service.go]"]
  node_models["Domain models<br/>[models.go]"]
end

subgraph group_identity["Identity security"]
  node_auth_service["Token service<br/>[auth_service.go]"]
  node_jwt_manager["JWT manager<br/>[manager.go]"]
  node_password_hash["Password hashing<br/>[password.go]"]
  node_auth_middleware["Auth middleware<br/>[middleware.go]"]
end

subgraph group_persistence["Persistence"]
  node_user_storage["User repository<br/>[user.go]"]
  node_room_storage["Room repository<br/>[room.go]"]
  node_postgres[("PostgreSQL pool<br/>[postgres.go]")]
  node_redis[("Redis cache<br/>[cache.go]")]
  node_config["Configuration<br/>[config.go]"]
end

node_client(("API client"))
node_grpc_client(("gRPC client"))
node_smtp["SMTP service"]

node_client -->|"sends requests"| node_http_server
node_http_server -->|"serves routes"| node_http_router
node_http_router -->|"routes auth"| node_auth_handler
node_client -->|"registers or logs in"| node_auth_handler
node_auth_handler -->|"looks up and creates"| node_user_service
node_auth_handler -->|"checks password"| node_password_hash
node_auth_handler -->|"generates or validates"| node_auth_service
node_auth_handler -->|"requests welcome email"| node_email_service
node_email_service -->|"sends mail"| node_smtp
node_user_service -->|"uses repository"| node_user_storage
node_user_storage -->|"queries users"| node_postgres
node_auth_service -->|"delegates tokens"| node_jwt_manager
node_auth_middleware -->|"validates tokens"| node_jwt_manager
node_grpc_client -->|"calls room API"| node_grpc_server
node_grpc_server -->|"registers service"| node_room_handler
node_grpc_contract -.->|"defines service"| node_grpc_server
node_room_handler -->|"creates room"| node_room_service
node_room_service -->|"uses repository"| node_room_storage
node_bootstrap -->|"loads settings"| node_config
node_bootstrap -->|"opens pool"| node_postgres
node_bootstrap -->|"opens cache"| node_redis
node_bootstrap -->|"starts server"| node_http_server
node_bootstrap -->|"starts server"| node_grpc_server
node_bootstrap -->|"constructs handler"| node_room_handler
node_user_service -->|"uses models"| node_models
node_room_service -->|"uses models"| node_models

click node_bootstrap "https://github.com/mcaqnn1/gochat/blob/main/cmd/app/main.go"
click node_http_server "https://github.com/mcaqnn1/gochat/blob/main/internal/transport/http/server.go"
click node_http_router "https://github.com/mcaqnn1/gochat/blob/main/internal/transport/http/router.go"
click node_auth_handler "https://github.com/mcaqnn1/gochat/blob/main/internal/handler/auth.go"
click node_user_handler "https://github.com/mcaqnn1/gochat/blob/main/internal/handler/user.go"
click node_grpc_server "https://github.com/mcaqnn1/gochat/blob/main/internal/transport/grpcserver/server.go"
click node_room_handler "https://github.com/mcaqnn1/gochat/blob/main/internal/handler/room.go"
click node_user_service "https://github.com/mcaqnn1/gochat/blob/main/internal/service/user.go"
click node_room_service "https://github.com/mcaqnn1/gochat/blob/main/internal/service/room.go"
click node_email_service "https://github.com/mcaqnn1/gochat/blob/main/internal/service/email_service.go"
click node_models "https://github.com/mcaqnn1/gochat/blob/main/internal/model/models.go"
click node_auth_service "https://github.com/mcaqnn1/gochat/blob/main/internal/service/auth_service.go"
click node_jwt_manager "https://github.com/mcaqnn1/gochat/blob/main/internal/pkg/jwt/manager.go"
click node_password_hash "https://github.com/mcaqnn1/gochat/blob/main/internal/pkg/hash/password.go"
click node_auth_middleware "https://github.com/mcaqnn1/gochat/blob/main/internal/transport/middleware.go"
click node_user_storage "https://github.com/mcaqnn1/gochat/blob/main/internal/storage/user.go"
click node_room_storage "https://github.com/mcaqnn1/gochat/blob/main/internal/storage/room.go"
click node_postgres "https://github.com/mcaqnn1/gochat/blob/main/internal/utils/database/pg/postgres.go"
click node_redis "https://github.com/mcaqnn1/gochat/blob/main/internal/utils/database/redis/cache.go"
click node_config "https://github.com/mcaqnn1/gochat/blob/main/internal/utils/configs/config.go"
click node_grpc_contract "https://github.com/mcaqnn1/gochat/blob/main/proto/room.proto"

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_bootstrap,node_http_server,node_http_router,node_auth_handler,node_user_handler,node_grpc_server,node_room_handler,node_grpc_contract,node_client,node_grpc_client toneBlue
class node_user_service,node_room_service,node_email_service,node_models toneAmber
class node_auth_service,node_jwt_manager,node_password_hash,node_auth_middleware toneMint
class node_user_storage,node_room_storage,node_postgres,node_redis,node_config toneRose
class node_smtp toneIndigo
```

## Components

### API transports

- [Application startup](https://github.com/mcaqnn1/gochat/blob/main/cmd/app/main.go): `cmd/app/main.go`
- [HTTP server](https://github.com/mcaqnn1/gochat/blob/main/internal/transport/http/server.go): `internal/transport/http/server.go`
- [HTTP routes](https://github.com/mcaqnn1/gochat/blob/main/internal/transport/http/router.go): `internal/transport/http/router.go`
- [Auth endpoints](https://github.com/mcaqnn1/gochat/blob/main/internal/handler/auth.go): `internal/handler/auth.go`
- [User endpoints](https://github.com/mcaqnn1/gochat/blob/main/internal/handler/user.go): `internal/handler/user.go`
- [gRPC server](https://github.com/mcaqnn1/gochat/blob/main/internal/transport/grpcserver/server.go): `internal/transport/grpcserver/server.go`
- [Room endpoint](https://github.com/mcaqnn1/gochat/blob/main/internal/handler/room.go): `internal/handler/room.go`
- [Room gRPC contract](https://github.com/mcaqnn1/gochat/blob/main/proto/room.proto): `proto/room.proto`

### Domain services

- [User operations](https://github.com/mcaqnn1/gochat/blob/main/internal/service/user.go): `internal/service/user.go`
- [Room operations](https://github.com/mcaqnn1/gochat/blob/main/internal/service/room.go): `internal/service/room.go`
- [Email delivery](https://github.com/mcaqnn1/gochat/blob/main/internal/service/email_service.go): `internal/service/email_service.go`
- [Domain models](https://github.com/mcaqnn1/gochat/blob/main/internal/model/models.go): `internal/model/models.go`

### Identity security

- [Token service](https://github.com/mcaqnn1/gochat/blob/main/internal/service/auth_service.go): `internal/service/auth_service.go`
- [JWT manager](https://github.com/mcaqnn1/gochat/blob/main/internal/pkg/jwt/manager.go): `internal/pkg/jwt/manager.go`
- [Password hashing](https://github.com/mcaqnn1/gochat/blob/main/internal/pkg/hash/password.go): `internal/pkg/hash/password.go`
- [Auth middleware](https://github.com/mcaqnn1/gochat/blob/main/internal/transport/middleware.go): `internal/transport/middleware.go`

### Persistence

- [User repository](https://github.com/mcaqnn1/gochat/blob/main/internal/storage/user.go): `internal/storage/user.go`
- [Room repository](https://github.com/mcaqnn1/gochat/blob/main/internal/storage/room.go): `internal/storage/room.go`
- [PostgreSQL pool](https://github.com/mcaqnn1/gochat/blob/main/internal/utils/database/pg/postgres.go): `internal/utils/database/pg/postgres.go`
- [Redis cache](https://github.com/mcaqnn1/gochat/blob/main/internal/utils/database/redis/cache.go): `internal/utils/database/redis/cache.go`
- [Configuration](https://github.com/mcaqnn1/gochat/blob/main/internal/utils/configs/config.go): `internal/utils/configs/config.go`

### Other components

- **API client**
- **gRPC client**
- **SMTP service**

## Connections

- API client → HTTP server: sends requests
- HTTP server → HTTP routes: serves routes
- HTTP routes → Auth endpoints: routes auth (evidence: `internal/transport/http/router.go`)
- API client → Auth endpoints: registers or logs in (evidence: `internal/handler/auth.go`)
- Auth endpoints → User operations: looks up and creates (evidence: `internal/handler/auth.go`)
- Auth endpoints → Password hashing: checks password (evidence: `internal/handler/auth.go`)
- Auth endpoints → Token service: generates or validates (evidence: `internal/handler/auth.go`)
- Auth endpoints → Email delivery: requests welcome email (evidence: `internal/handler/auth.go`)
- Email delivery → SMTP service: sends mail (evidence: `internal/service/email_service.go`)
- User operations → User repository: uses repository (evidence: `internal/service/user.go`)
- User repository → PostgreSQL pool: queries users (evidence: `internal/storage/user.go`)
- Token service → JWT manager: delegates tokens (evidence: `internal/service/auth_service.go`)
- Auth middleware → JWT manager: validates tokens (evidence: `internal/transport/middleware.go`)
- gRPC client → gRPC server: calls room API (evidence: `internal/transport/grpcserver/server.go`)
- gRPC server → Room endpoint: registers service (evidence: `internal/transport/grpcserver/server.go`)
- Room gRPC contract → gRPC server: defines service
- Room endpoint → Room operations: creates room (evidence: `internal/handler/room.go`)
- Room operations → Room repository: uses repository (evidence: `internal/service/room.go`)
- Application startup → Configuration: loads settings (evidence: `cmd/app/main.go`)
- Application startup → PostgreSQL pool: opens pool (evidence: `cmd/app/main.go`)
- Application startup → Redis cache: opens cache (evidence: `cmd/app/main.go`)
- Application startup → HTTP server: starts server (evidence: `cmd/app/main.go`)
- Application startup → gRPC server: starts server (evidence: `cmd/app/main.go`)
- Application startup → Room endpoint: constructs handler (evidence: `cmd/app/main.go`)
- User operations → Domain models: uses models (evidence: `internal/service/user.go`)
- Room operations → Domain models: uses models (evidence: `internal/service/room.go`)
