# applikatla/cosmonic-grpc architecture

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

- Interactive diagram: https://gitdiagram.com/applikatla/cosmonic-grpc
- Repository: https://github.com/applikatla/cosmonic-grpc

## Overview

This repository is a small modular gRPC framework demonstrated by a Hello module. A client’s store or retrieve request enters the Gin-hosted HTTP gateway or the gRPC server, reaches the Hello handler, then the service and keeper, which read or write PostgreSQL-backed state. The app registers modules and exposes their gRPC and gateway registrations. The README also describes typed protobuf APIs, REST mappings, and database-backed modules. Security features are discussed as extension guidance, but the sampled runtime does not show their implementation.

Main entry points: [`cmd/server/main.go`](https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go) (Server bootstrap), [`x/hello/module.go`](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/module.go) (Hello module wiring), [`x/hello/types/hello.pb.gw.go`](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/types/hello.pb.gw.go) (Gateway bindings), [`x/hello/grpc/hello.go`](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/grpc/hello.go) (RPC handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime wiring"]
  node_server["Server bootstrap<br/>[main.go]"]
  node_app["App registry<br/>[app.go]"]
  node_module_contract["Module interface<br/>[module.go]"]
end

subgraph group_transport["API transport"]
  node_gin["HTTP ingress<br/>[main.go]"]
  node_gateway["Gateway bindings<br/>[hello.pb.gw.go]"]
  node_grpc_server["gRPC server<br/>[main.go]"]
  node_proto["Hello API contract<br/>[hello.proto]"]
end

subgraph group_hello["Hello module"]
  node_module["Hello module wiring<br/>[module.go]"]
  node_handler["RPC handler<br/>[hello.go]"]
  node_service["Hello service<br/>[hello.go]"]
  node_keeper["State keeper<br/>[keeper.go]"]
end

subgraph group_persistence["Persistence"]
  node_db_setup["Database setup<br/>[db.go]"]
  node_hello_model["Hello model<br/>[models.go]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends HTTP"| node_gin
node_client -->|"calls RPC"| node_grpc_server
node_gin -->|"wraps gateway"| node_gateway
node_gateway -->|"dials endpoint"| node_grpc_server
node_proto -.->|"defines HTTP mapping"| node_gateway
node_server -->|"opens database"| node_db_setup
node_server -->|"runs migration"| node_hello_model
node_server -->|"creates registry"| node_app
node_server -->|"registers module"| node_module
node_app -->|"stores modules"| node_module_contract
node_server -->|"dispatches registration"| node_module_contract
node_module -->|"constructs handler"| node_handler
node_module -->|"registers service"| node_grpc_server
node_module -->|"registers gateway"| node_gateway
node_grpc_server -->|"dispatches RPC"| node_handler
node_handler -->|"calls service"| node_service
node_service -->|"calls state methods"| node_keeper
node_keeper -->|"reads and writes"| node_hello_model
node_db_setup -->|"connects"| node_postgres
node_hello_model -.->|"persists records"| node_postgres

click node_server "https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go"
click node_app "https://github.com/applikatla/cosmonic-grpc/blob/master/app/app.go"
click node_module_contract "https://github.com/applikatla/cosmonic-grpc/blob/master/app/module.go"
click node_gin "https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go"
click node_gateway "https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/types/hello.pb.gw.go"
click node_grpc_server "https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go"
click node_proto "https://github.com/applikatla/cosmonic-grpc/blob/master/proto/hello/hello.proto"
click node_module "https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/module.go"
click node_handler "https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/grpc/hello.go"
click node_service "https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/service/hello.go"
click node_keeper "https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/keeper/keeper.go"
click node_db_setup "https://github.com/applikatla/cosmonic-grpc/blob/master/internal/db/db.go"
click node_hello_model "https://github.com/applikatla/cosmonic-grpc/blob/master/internal/db/models.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_app,node_module_contract,node_client toneBlue
class node_gin,node_gateway,node_grpc_server,node_proto,node_postgres toneAmber
class node_module,node_handler,node_service,node_keeper toneMint
class node_db_setup,node_hello_model toneRose
```

## Components

### Runtime wiring

- [Server bootstrap](https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go): `cmd/server/main.go`
- [App registry](https://github.com/applikatla/cosmonic-grpc/blob/master/app/app.go): `app/app.go`
- [Module interface](https://github.com/applikatla/cosmonic-grpc/blob/master/app/module.go): `app/module.go`

### API transport

- [HTTP ingress](https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go): `cmd/server/main.go`
- [Gateway bindings](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/types/hello.pb.gw.go): `x/hello/types/hello.pb.gw.go`
- [gRPC server](https://github.com/applikatla/cosmonic-grpc/blob/master/cmd/server/main.go): `cmd/server/main.go`
- [Hello API contract](https://github.com/applikatla/cosmonic-grpc/blob/master/proto/hello/hello.proto): `proto/hello/hello.proto`

### Hello module

- [Hello module wiring](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/module.go): `x/hello/module.go`
- [RPC handler](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/grpc/hello.go): `x/hello/grpc/hello.go`
- [Hello service](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/service/hello.go): `x/hello/service/hello.go`
- [State keeper](https://github.com/applikatla/cosmonic-grpc/blob/master/x/hello/keeper/keeper.go): `x/hello/keeper/keeper.go`

### Persistence

- [Database setup](https://github.com/applikatla/cosmonic-grpc/blob/master/internal/db/db.go): `internal/db/db.go`
- [Hello model](https://github.com/applikatla/cosmonic-grpc/blob/master/internal/db/models.go): `internal/db/models.go`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → HTTP ingress: sends HTTP (evidence: `README.md`)
- API client → gRPC server: calls RPC (evidence: `README.md`)
- HTTP ingress → Gateway bindings: wraps gateway (evidence: `cmd/server/main.go`)
- Gateway bindings → gRPC server: dials endpoint
- Hello API contract → Gateway bindings: defines HTTP mapping
- Server bootstrap → Database setup: opens database (evidence: `cmd/server/main.go`)
- Server bootstrap → Hello model: runs migration (evidence: `cmd/server/main.go`)
- Server bootstrap → App registry: creates registry (evidence: `cmd/server/main.go`)
- Server bootstrap → Hello module wiring: registers module (evidence: `cmd/server/main.go`)
- App registry → Module interface: stores modules (evidence: `app/app.go`)
- Server bootstrap → Module interface: dispatches registration (evidence: `cmd/server/main.go`)
- Hello module wiring → RPC handler: constructs handler (evidence: `x/hello/module.go`)
- Hello module wiring → gRPC server: registers service (evidence: `x/hello/module.go`)
- Hello module wiring → Gateway bindings: registers gateway (evidence: `x/hello/module.go`)
- gRPC server → RPC handler: dispatches RPC
- RPC handler → Hello service: calls service (evidence: `x/hello/grpc/hello.go`)
- Hello service → State keeper: calls state methods (evidence: `x/hello/service/hello.go`)
- State keeper → Hello model: reads and writes (evidence: `x/hello/keeper/keeper.go`)
- Database setup → PostgreSQL: connects (evidence: `internal/db/db.go`)
- Hello model → PostgreSQL: persists records
