# faustaakbar/golang-restapi architecture

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

- Interactive diagram: https://gitdiagram.com/faustaakbar/golang-restapi
- Repository: https://github.com/faustaakbar/golang-restapi

## Overview

This is a layered Go REST API for listing and creating users. An HTTP client reaches the Gin routes, which dispatch to handlers; handlers call the user service, which coordinates Redis caching and repository operations backed by MySQL. Startup loads configuration, connects to both stores, migrates the user model, and registers routes. The README also documents five-minute list caching and cache invalidation after creation. Relationships are based on the shown source and README; Docker Compose infrastructure is omitted as development setup.

Main entry points: [`cmd/main.go`](https://github.com/faustaakbar/golang-restapi/blob/main/cmd/main.go) (Application Entry), [`internal/service/user_service.go`](https://github.com/faustaakbar/golang-restapi/blob/main/internal/service/user_service.go) (User Service), [`internal/models/user.go`](https://github.com/faustaakbar/golang-restapi/blob/main/internal/models/user.go) (User Model), [`internal/database/mysql.go`](https://github.com/faustaakbar/golang-restapi/blob/main/internal/database/mysql.go) (MySQL Connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Application Startup"]
  node_main["Application Entry<br/>[main.go]"]
  node_config["Environment Config<br/>[config.go]"]
  node_mysql_conn["MySQL Connection<br/>[mysql.go]"]
  node_redis_conn["Redis Connection<br/>[redis.go]"]
end

subgraph group_api["User API"]
  node_routes["API Routes<br/>[routes.go]"]
  node_handler["User Handler<br/>[user_handler.go]"]
  node_service["User Service<br/>[user_service.go]"]
end

subgraph group_data["Data Access"]
  node_model["User Model<br/>[user.go]"]
  node_repository["User Repository<br/>[user_repository.go]"]
end

node_client(("HTTP Client"))
node_mysql[("MySQL Store")]
node_redis[("Redis Cache")]

node_client -->|"sends requests"| node_routes
node_main -->|"loads config"| node_config
node_main -->|"connects"| node_mysql_conn
node_main -->|"connects"| node_redis_conn
node_main -->|"migrates schema"| node_model
node_main -->|"registers routes"| node_routes
node_mysql_conn -->|"reads settings"| node_config
node_redis_conn -->|"reads settings"| node_config
node_mysql_conn -->|"opens connection"| node_mysql
node_redis_conn -->|"opens connection"| node_redis
node_routes -->|"dispatches requests"| node_handler
node_handler -->|"calls service"| node_service
node_service -->|"queries users"| node_repository
node_service -->|"reads and invalidates cache"| node_redis
node_repository -->|"reads and writes"| node_mysql
node_repository -->|"uses user records"| node_model
node_service -->|"processes users"| node_model
node_handler -->|"binds request data"| node_model

click node_main "https://github.com/faustaakbar/golang-restapi/blob/main/cmd/main.go"
click node_config "https://github.com/faustaakbar/golang-restapi/blob/main/internal/config/config.go"
click node_mysql_conn "https://github.com/faustaakbar/golang-restapi/blob/main/internal/database/mysql.go"
click node_redis_conn "https://github.com/faustaakbar/golang-restapi/blob/main/internal/database/redis.go"
click node_routes "https://github.com/faustaakbar/golang-restapi/blob/main/internal/routes/routes.go"
click node_handler "https://github.com/faustaakbar/golang-restapi/blob/main/internal/handler/user_handler.go"
click node_service "https://github.com/faustaakbar/golang-restapi/blob/main/internal/service/user_service.go"
click node_model "https://github.com/faustaakbar/golang-restapi/blob/main/internal/models/user.go"
click node_repository "https://github.com/faustaakbar/golang-restapi/blob/main/internal/repository/user_repository.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_main,node_config,node_mysql_conn,node_redis_conn,node_client toneBlue
class node_routes,node_handler,node_service,node_mysql,node_redis toneAmber
class node_model,node_repository toneMint
```

## Components

### Application Startup

- [Application Entry](https://github.com/faustaakbar/golang-restapi/blob/main/cmd/main.go): `cmd/main.go`
- [Environment Config](https://github.com/faustaakbar/golang-restapi/blob/main/internal/config/config.go): `internal/config/config.go`
- [MySQL Connection](https://github.com/faustaakbar/golang-restapi/blob/main/internal/database/mysql.go): `internal/database/mysql.go`
- [Redis Connection](https://github.com/faustaakbar/golang-restapi/blob/main/internal/database/redis.go): `internal/database/redis.go`

### User API

- [API Routes](https://github.com/faustaakbar/golang-restapi/blob/main/internal/routes/routes.go): `internal/routes/routes.go`
- [User Handler](https://github.com/faustaakbar/golang-restapi/blob/main/internal/handler/user_handler.go): `internal/handler/user_handler.go`
- [User Service](https://github.com/faustaakbar/golang-restapi/blob/main/internal/service/user_service.go): `internal/service/user_service.go`

### Data Access

- [User Model](https://github.com/faustaakbar/golang-restapi/blob/main/internal/models/user.go): `internal/models/user.go`
- [User Repository](https://github.com/faustaakbar/golang-restapi/blob/main/internal/repository/user_repository.go): `internal/repository/user_repository.go`

### Other components

- **HTTP Client**
- **MySQL Store**
- **Redis Cache**

## Connections

- HTTP Client → API Routes: sends requests (evidence: `README.md`)
- Application Entry → Environment Config: loads config (evidence: `cmd/main.go`)
- Application Entry → MySQL Connection: connects (evidence: `cmd/main.go`)
- Application Entry → Redis Connection: connects (evidence: `cmd/main.go`)
- Application Entry → User Model: migrates schema (evidence: `cmd/main.go`)
- Application Entry → API Routes: registers routes (evidence: `cmd/main.go`)
- MySQL Connection → Environment Config: reads settings (evidence: `internal/database/mysql.go`)
- Redis Connection → Environment Config: reads settings (evidence: `internal/database/redis.go`)
- MySQL Connection → MySQL Store: opens connection (evidence: `internal/database/mysql.go`)
- Redis Connection → Redis Cache: opens connection (evidence: `internal/database/redis.go`)
- API Routes → User Handler: dispatches requests (evidence: `internal/routes/routes.go`)
- User Handler → User Service: calls service (evidence: `internal/handler/user_handler.go`)
- User Service → User Repository: queries users (evidence: `internal/service/user_service.go`)
- User Service → Redis Cache: reads and invalidates cache (evidence: `internal/service/user_service.go`)
- User Repository → MySQL Store: reads and writes (evidence: `internal/repository/user_repository.go`)
- User Repository → User Model: uses user records (evidence: `internal/repository/user_repository.go`)
- User Service → User Model: processes users (evidence: `internal/service/user_service.go`)
- User Handler → User Model: binds request data (evidence: `internal/handler/user_handler.go`)
