# 47monad/apin architecture

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

- Interactive diagram: https://gitdiagram.com/47monad/apin
- Repository: https://github.com/47monad/apin

## Overview

Apin is a Go microservice-initializer toolkit: applications load their own configuration, choose infrastructure shells, and use App to run work and close tracked shells in reverse order. The graph preserves the documented database, messaging, server, logging, and metrics capabilities. Lifecycle and configuration behavior are supported by sampled source; several initializer links and capabilities rely on the README because their implementation files were not sampled.

Main entry points: [`common.go`](https://github.com/47monad/apin/blob/main/common.go) (Closer contract), [`initrs/grpcinitr`](https://github.com/47monad/apin/tree/main/initrs/grpcinitr) (gRPC shells), [`app.go`](https://github.com/47monad/apin/blob/main/app.go) (App lifecycle), [`initrs/httpinitr`](https://github.com/47monad/apin/tree/main/initrs/httpinitr) (HTTP server shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_lifecycle["Application lifecycle"]
  node_app["App lifecycle<br/>[app.go]"]
  node_closer["Closer contract<br/>[common.go]"]
end

subgraph group_configuration["Configuration"]
  node_config_loader["Config loader<br/>[load.go]"]
end

subgraph group_service_shells["Service shells"]
  node_http["HTTP server shell"]
  node_grpc["gRPC shells"]
  node_postgres["PostgreSQL shell"]
  node_mongodb["MongoDB shell"]
  node_etcd["etcd shell"]
  node_rabbitmq["RabbitMQ shell"]
end

subgraph group_observability["Observability"]
  node_zap["Zap logger shell"]
  node_prometheus["Prometheus metrics"]
end

node_application(("Service application"))
node_config_sources["Config and env files"]
node_runnables["Application runnables"]
node_postgres_service[("PostgreSQL service")]
node_mongo_service[("MongoDB service")]
node_etcd_service[("etcd service")]
node_rabbit_service["RabbitMQ service"]
node_http_clients(("HTTP clients"))
node_grpc_clients(("gRPC clients"))

node_application -->|"loads settings"| node_config_loader
node_config_sources -->|"provides values"| node_config_loader
node_config_loader -->|"returns config"| node_application
node_application -->|"constructs shell"| node_http
node_application -->|"constructs shell"| node_grpc
node_application -->|"constructs shell"| node_postgres
node_application -->|"constructs shell"| node_mongodb
node_application -->|"constructs shell"| node_etcd
node_application -->|"constructs shell"| node_rabbitmq
node_application -->|"constructs shell"| node_zap
node_application -.->|"constructs shell"| node_prometheus
node_application -->|"creates and tracks"| node_app
node_application -->|"starts"| node_app
node_app -->|"runs concurrently"| node_runnables
node_app -->|"closes tracked shells"| node_closer
node_http -->|"implements"| node_closer
node_grpc -->|"implements"| node_closer
node_postgres -->|"implements"| node_closer
node_mongodb -->|"implements"| node_closer
node_etcd -->|"implements"| node_closer
node_rabbitmq -->|"implements"| node_closer
node_zap -->|"implements"| node_closer
node_http -->|"serves"| node_http_clients
node_grpc -->|"serves"| node_grpc_clients
node_grpc -.->|"instrumented by"| node_prometheus
node_postgres -->|"connects to"| node_postgres_service
node_mongodb -->|"connects to"| node_mongo_service
node_etcd -->|"connects to"| node_etcd_service
node_rabbitmq -->|"connects to"| node_rabbit_service

click node_config_loader "https://github.com/47monad/apin/blob/main/config/load.go"
click node_app "https://github.com/47monad/apin/blob/main/app.go"
click node_closer "https://github.com/47monad/apin/blob/main/common.go"
click node_http "https://github.com/47monad/apin/tree/main/initrs/httpinitr"
click node_grpc "https://github.com/47monad/apin/tree/main/initrs/grpcinitr"
click node_postgres "https://github.com/47monad/apin/tree/main/initrs/pginitr"
click node_mongodb "https://github.com/47monad/apin/tree/main/initrs/mongoinitr"
click node_etcd "https://github.com/47monad/apin/tree/main/initrs/etcdinitr"
click node_rabbitmq "https://github.com/47monad/apin/tree/main/initrs/rmqinitr"
click node_zap "https://github.com/47monad/apin/tree/main/initrs/zapinitr"
click node_prometheus "https://github.com/47monad/apin/tree/main/initrs/prominitr"

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_app,node_closer,node_http_clients,node_grpc_clients toneBlue
class node_config_loader,node_postgres_service,node_mongo_service,node_etcd_service toneAmber
class node_http,node_grpc,node_postgres,node_mongodb,node_etcd,node_rabbitmq toneMint
class node_zap,node_prometheus toneRose
class node_application,node_config_sources,node_runnables,node_rabbit_service toneIndigo
```

## Components

### Application lifecycle

- [App lifecycle](https://github.com/47monad/apin/blob/main/app.go): `app.go`
- [Closer contract](https://github.com/47monad/apin/blob/main/common.go): `common.go`

### Configuration

- [Config loader](https://github.com/47monad/apin/blob/main/config/load.go): `config/load.go`

### Service shells

- [HTTP server shell](https://github.com/47monad/apin/tree/main/initrs/httpinitr): `initrs/httpinitr`
- [gRPC shells](https://github.com/47monad/apin/tree/main/initrs/grpcinitr): `initrs/grpcinitr`
- [PostgreSQL shell](https://github.com/47monad/apin/tree/main/initrs/pginitr): `initrs/pginitr`
- [MongoDB shell](https://github.com/47monad/apin/tree/main/initrs/mongoinitr): `initrs/mongoinitr`
- [etcd shell](https://github.com/47monad/apin/tree/main/initrs/etcdinitr): `initrs/etcdinitr`
- [RabbitMQ shell](https://github.com/47monad/apin/tree/main/initrs/rmqinitr): `initrs/rmqinitr`

### Observability

- [Zap logger shell](https://github.com/47monad/apin/tree/main/initrs/zapinitr): `initrs/zapinitr`
- [Prometheus metrics](https://github.com/47monad/apin/tree/main/initrs/prominitr): `initrs/prominitr`

### Other components

- **Service application**
- **Config and env files**
- **Application runnables**
- **PostgreSQL service**
- **MongoDB service**
- **etcd service**
- **RabbitMQ service**
- **HTTP clients**
- **gRPC clients**

## Connections

- Service application → Config loader: loads settings
- Config and env files → Config loader: provides values
- Config loader → Service application: returns config
- Service application → HTTP server shell: constructs shell
- Service application → gRPC shells: constructs shell
- Service application → PostgreSQL shell: constructs shell
- Service application → MongoDB shell: constructs shell
- Service application → etcd shell: constructs shell
- Service application → RabbitMQ shell: constructs shell
- Service application → Zap logger shell: constructs shell
- Service application → Prometheus metrics: constructs shell
- Service application → App lifecycle: creates and tracks
- Service application → App lifecycle: starts
- App lifecycle → Application runnables: runs concurrently
- App lifecycle → Closer contract: closes tracked shells
- HTTP server shell → Closer contract: implements
- gRPC shells → Closer contract: implements
- PostgreSQL shell → Closer contract: implements
- MongoDB shell → Closer contract: implements
- etcd shell → Closer contract: implements
- RabbitMQ shell → Closer contract: implements
- Zap logger shell → Closer contract: implements
- HTTP server shell → HTTP clients: serves
- gRPC shells → gRPC clients: serves
- gRPC shells → Prometheus metrics: instrumented by
- PostgreSQL shell → PostgreSQL service: connects to
- MongoDB shell → MongoDB service: connects to
- etcd shell → etcd service: connects to
- RabbitMQ shell → RabbitMQ service: connects to
