# bintangstilllerning/belajar-golang-restful-api architecture

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

- Interactive diagram: https://gitdiagram.com/bintangstilllerning/belajar-golang-restful-api
- Repository: https://github.com/bintangstilllerning/belajar-golang-restful-api

## Overview

This is a Go HTTP REST API for category CRUD. A client request passes through API-key middleware and the routes configured in main.go to category handlers; handlers delegate validation, transaction handling, and category operations to the service, which calls the repository for SQL access. Responses are serialized as JSON, with panics handled by the registered error handler. The source excerpts show category endpoints and MySQL setup; the README is empty, so other product capabilities are not documented.

Main entry points: [`main.go`](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/main.go) (Server and routes), [`controller/category_controller_impl.go`](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/controller/category_controller_impl.go) (Category handlers), [`service/category_service_impl.go`](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/service/category_service_impl.go) (Category service), [`repository/category_repository_impl.go`](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/repository/category_repository_impl.go) (Category repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_entry["Server and routes<br/>[main.go]"]
  node_auth["API-key middleware<br/>[auth_middleware.go]"]
  node_controller["Category handlers"]
  node_errors["Error responses<br/>[error_handler.go]"]
end

subgraph group_domain["Category Operations"]
  node_service["Category service"]
  node_domain_model["Category entity<br/>[category.go]"]
  node_web_models["API models"]
  node_response_model["Response models<br/>[web_response.go]"]
  node_helpers["JSON and mapping helpers<br/>[json.go]"]
end

subgraph group_data["Persistence"]
  node_repository["Category repository"]
  node_db_setup["Database setup<br/>[database.go]"]
  node_sql_pool[("SQL connection pool")]
end

node_client(("API client"))
node_mysql[("MySQL")]

node_client -->|"sends HTTP"| node_auth
node_auth -->|"forwards request"| node_entry
node_entry -->|"routes request"| node_controller
node_entry -->|"dispatches panic"| node_errors
node_controller -->|"calls operations"| node_service
node_controller -->|"reads and writes JSON"| node_helpers
node_service -->|"calls queries"| node_repository
node_service -->|"begins transactions"| node_sql_pool
node_service -->|"maps responses"| node_helpers
node_repository -->|"executes SQL"| node_sql_pool
node_repository -->|"loads and saves"| node_domain_model
node_db_setup -->|"opens connection"| node_sql_pool
node_sql_pool -->|"connects to"| node_mysql
node_entry -->|"initializes database"| node_db_setup
node_entry -->|"wires dependencies"| node_service
node_entry -->|"wires dependencies"| node_controller
node_controller -->|"decodes requests"| node_web_models
node_controller -->|"encodes responses"| node_response_model

click node_entry "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/main.go"
click node_auth "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/middleware/auth_middleware.go"
click node_controller "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/controller/category_controller_impl.go"
click node_errors "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/exception/error_handler.go"
click node_service "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/service/category_service_impl.go"
click node_domain_model "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/model/domain/category.go"
click node_web_models "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/model/web/category_create_request.go"
click node_response_model "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/model/web/web_response.go"
click node_helpers "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/helper/json.go"
click node_repository "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/repository/category_repository_impl.go"
click node_db_setup "https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/app/database.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_entry,node_auth,node_controller,node_errors,node_client toneBlue
class node_service,node_domain_model,node_web_models,node_response_model,node_helpers,node_mysql toneAmber
class node_repository,node_db_setup,node_sql_pool toneMint
```

## Components

### HTTP API

- [Server and routes](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/main.go): `main.go`
- [API-key middleware](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/middleware/auth_middleware.go): `middleware/auth_middleware.go`
- [Category handlers](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/controller/category_controller_impl.go): `controller/category_controller_impl.go`
- [Error responses](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/exception/error_handler.go): `exception/error_handler.go`

### Category Operations

- [Category service](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/service/category_service_impl.go): `service/category_service_impl.go`
- [Category entity](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/model/domain/category.go): `model/domain/category.go`
- [API models](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/model/web/category_create_request.go): `model/web/category_create_request.go`
- [Response models](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/model/web/web_response.go): `model/web/web_response.go`
- [JSON and mapping helpers](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/helper/json.go): `helper/json.go`

### Persistence

- [Category repository](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/repository/category_repository_impl.go): `repository/category_repository_impl.go`
- [Database setup](https://github.com/bintangstilllerning/belajar-golang-restful-api/blob/main/app/database.go): `app/database.go`
- **SQL connection pool**

### Other components

- **API client**
- **MySQL**

## Connections

- API client → API-key middleware: sends HTTP
- API-key middleware → Server and routes: forwards request
- Server and routes → Category handlers: routes request
- Server and routes → Error responses: dispatches panic
- Category handlers → Category service: calls operations
- Category handlers → JSON and mapping helpers: reads and writes JSON
- Category service → Category repository: calls queries
- Category service → SQL connection pool: begins transactions
- Category service → JSON and mapping helpers: maps responses
- Category repository → SQL connection pool: executes SQL
- Category repository → Category entity: loads and saves
- Database setup → SQL connection pool: opens connection
- SQL connection pool → MySQL: connects to
- Server and routes → Database setup: initializes database
- Server and routes → Category service: wires dependencies
- Server and routes → Category handlers: wires dependencies
- Category handlers → API models: decodes requests
- Category handlers → Response models: encodes responses
