# antimatterr/psygateway architecture

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

- Interactive diagram: https://gitdiagram.com/antimatterr/psygateway
- Repository: https://github.com/antimatterr/psygateway

## Overview

This repository implements an API gateway alongside product and user HTTP services. The principal flow is an API caller reaching the gateway, which matches a configured route, applies its basic authorization check when required, resolves a backend, and proxies the request. The backend services query PostgreSQL and return JSON. The README is empty, and the gateway excerpt omits some implementation details, so the diagram includes only relationships supported by the sampled source and tree.

Main entry points: [`internal/discovery/consul.go`](https://github.com/antimatterr/psygateway/blob/main/internal/discovery/consul.go) (Discovery client), [`main.go`](https://github.com/antimatterr/psygateway/blob/main/main.go) (Route matching), [`services/products/main.go`](https://github.com/antimatterr/psygateway/blob/main/services/products/main.go) (Product service), [`services/users/main.go`](https://github.com/antimatterr/psygateway/blob/main/services/users/main.go) (User service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["API gateway"]
  node_gateway_server["Gateway server<br/>[main.go]"]
  node_route_config["Route configuration<br/>[main.go]"]
  node_route_match["Route matching<br/>[main.go]"]
  node_auth["Basic authorization<br/>[main.go]"]
  node_proxy["Request proxy<br/>[main.go]"]
end

subgraph group_services["Backend services"]
  node_product_service["Product service<br/>[main.go]"]
  node_user_service["User service<br/>[main.go]"]
end

subgraph group_discovery["Service discovery"]
  node_discovery_client["Discovery client<br/>[consul.go]"]
  node_consul[("Consul")]
end

subgraph group_data["Persistence and logging"]
  node_route_store[("Route database<br/>[routes.sql]")]
  node_product_data[("Product data<br/>[products.sql]")]
  node_user_data[("User data<br/>[users.sql]")]
  node_logger["Logger<br/>[logger.go]"]
end

node_caller(("API caller"))

node_caller -->|"sends request"| node_gateway_server
node_gateway_server -->|"dispatches"| node_route_match
node_route_match -->|"checks routes"| node_route_config
node_route_config -->|"loads enabled routes"| node_route_store
node_route_match -->|"checks protected route"| node_auth
node_route_match -->|"dispatches matched route"| node_proxy
node_proxy -->|"resolves target"| node_discovery_client
node_discovery_client -->|"queries healthy services"| node_consul
node_proxy -->|"proxies product requests"| node_product_service
node_proxy -->|"proxies user requests"| node_user_service
node_product_service -->|"queries products"| node_product_data
node_user_service -->|"queries users"| node_user_data
node_product_service -->|"registers service"| node_discovery_client
node_user_service -->|"registers and deregisters"| node_discovery_client
node_discovery_client -->|"registers services"| node_consul
node_gateway_server -->|"logs events"| node_logger
node_product_service -->|"logs events"| node_logger
node_user_service -->|"logs events"| node_logger

click node_gateway_server "https://github.com/antimatterr/psygateway/blob/main/main.go"
click node_route_config "https://github.com/antimatterr/psygateway/blob/main/main.go"
click node_route_store "https://github.com/antimatterr/psygateway/blob/main/postgres-init/routes.sql"
click node_route_match "https://github.com/antimatterr/psygateway/blob/main/main.go"
click node_auth "https://github.com/antimatterr/psygateway/blob/main/main.go"
click node_proxy "https://github.com/antimatterr/psygateway/blob/main/main.go"
click node_discovery_client "https://github.com/antimatterr/psygateway/blob/main/internal/discovery/consul.go"
click node_product_service "https://github.com/antimatterr/psygateway/blob/main/services/products/main.go"
click node_user_service "https://github.com/antimatterr/psygateway/blob/main/services/users/main.go"
click node_product_data "https://github.com/antimatterr/psygateway/blob/main/postgres-init/products.sql"
click node_user_data "https://github.com/antimatterr/psygateway/blob/main/postgres-init/users.sql"
click node_logger "https://github.com/antimatterr/psygateway/blob/main/internal/logger/logger.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_gateway_server,node_route_config,node_route_match,node_auth,node_proxy toneBlue
class node_product_service,node_user_service toneAmber
class node_discovery_client,node_consul,node_caller toneMint
class node_route_store,node_product_data,node_user_data,node_logger toneRose
```

## Components

### API gateway

- [Gateway server](https://github.com/antimatterr/psygateway/blob/main/main.go): `main.go`
- [Route configuration](https://github.com/antimatterr/psygateway/blob/main/main.go): `main.go`
- [Route matching](https://github.com/antimatterr/psygateway/blob/main/main.go): `main.go`
- [Basic authorization](https://github.com/antimatterr/psygateway/blob/main/main.go): `main.go`
- [Request proxy](https://github.com/antimatterr/psygateway/blob/main/main.go): `main.go`

### Backend services

- [Product service](https://github.com/antimatterr/psygateway/blob/main/services/products/main.go): `services/products/main.go`
- [User service](https://github.com/antimatterr/psygateway/blob/main/services/users/main.go): `services/users/main.go`

### Service discovery

- [Discovery client](https://github.com/antimatterr/psygateway/blob/main/internal/discovery/consul.go): `internal/discovery/consul.go`
- **Consul**

### Persistence and logging

- [Route database](https://github.com/antimatterr/psygateway/blob/main/postgres-init/routes.sql): `postgres-init/routes.sql`
- [Product data](https://github.com/antimatterr/psygateway/blob/main/postgres-init/products.sql): `postgres-init/products.sql`
- [User data](https://github.com/antimatterr/psygateway/blob/main/postgres-init/users.sql): `postgres-init/users.sql`
- [Logger](https://github.com/antimatterr/psygateway/blob/main/internal/logger/logger.go): `internal/logger/logger.go`

### Other components

- **API caller**

## Connections

- API caller → Gateway server: sends request
- Gateway server → Route matching: dispatches
- Route matching → Route configuration: checks routes
- Route configuration → Route database: loads enabled routes
- Route matching → Basic authorization: checks protected route
- Route matching → Request proxy: dispatches matched route
- Request proxy → Discovery client: resolves target
- Discovery client → Consul: queries healthy services
- Request proxy → Product service: proxies product requests
- Request proxy → User service: proxies user requests
- Product service → Product data: queries products
- User service → User data: queries users
- Product service → Discovery client: registers service
- User service → Discovery client: registers and deregisters
- Discovery client → Consul: registers services
- Gateway server → Logger: logs events
- Product service → Logger: logs events
- User service → Logger: logs events
