# teguhsugiono/be-presensi architecture

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

- Interactive diagram: https://gitdiagram.com/teguhsugiono/be-presensi
- Repository: https://github.com/teguhsugiono/be-presensi

## Overview

This is a Go backend for a presence/attendance product. Its visible workflow is HTTP requests entering Gin routes, reaching handlers and services, and producing JSON responses; authentication supports login, current-user lookup, and admin setup, while protected routes guard user, role, and work-schedule management. The server wires these modules to a PostgreSQL connection. The tree also contains database backups and a Postman collection, but no README describing attendance-record workflows. Several module implementations were not excerpted, so those internal calls are not inferred.

Main entry points: [`cmd/server/main.go`](https://github.com/teguhsugiono/be-presensi/blob/main/cmd/server/main.go) (Gin server), [`internal/modules/auth/middleware/auth_middleware.go`](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/middleware/auth_middleware.go) (JWT middleware), [`internal/modules/auth/routes/auth_routes.go`](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/routes/auth_routes.go) (Auth routes), [`internal/modules/user/routes/user_routes.go`](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/routes/user_routes.go) (User routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server and storage"]
  node_server["Gin server<br/>[main.go]"]
  node_config["App configuration<br/>[config.go]"]
  node_dbconnect["Postgres connector<br/>[postgres.go]"]
  node_postgres[("PostgreSQL")]
  node_response["JSON responses<br/>[response.go]"]
end

subgraph group_auth["Authentication"]
  node_authroutes["Auth routes<br/>[auth_routes.go]"]
  node_authhandler["Auth handler<br/>[auth_handler.go]"]
  node_authservice["Auth service<br/>[auth_service.go]"]
  node_authmiddleware["JWT middleware<br/>[auth_middleware.go]"]
  node_authdto["Auth DTOs<br/>[auth_dto.go]"]
  node_jwtclaims["JWT claims<br/>[jwt_claims.go]"]
end

subgraph group_people["People and roles"]
  node_userroutes["User routes<br/>[user_routes.go]"]
  node_userhandler["User handler<br/>[user_handler.go]"]
  node_userservice["User service<br/>[user_service.go]"]
  node_userrepo["User repository<br/>[user_repository.go]"]
  node_userentity["User entity<br/>[user.go]"]
  node_userdto["User DTOs<br/>[user_dto.go]"]
  node_roleroutes["Role routes<br/>[role_routes.go]"]
  node_rolehandler["Role handler<br/>[role_handler.go]"]
  node_roleservice["Role service<br/>[role_service.go]"]
  node_rolerepo["Role repository<br/>[role_repository.go]"]
  node_roleentity["Role entity<br/>[role.go]"]
  node_roledto["Role DTOs<br/>[role_dto.go]"]
end

subgraph group_scheduling["Work schedules"]
  node_scheduleroutes["Schedule routes"]
  node_schedulehandler["Schedule handler"]
  node_scheduleservice["Schedule service"]
  node_schedulerepo["Schedule repository"]
  node_scheduleentity["Schedule entity<br/>[work_schedule.go]"]
  node_scheduledto["Schedule DTOs"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"loads settings"| node_config
node_server -->|"opens connection"| node_dbconnect
node_dbconnect -->|"connects"| node_postgres
node_server -->|"registers routes"| node_authroutes
node_server -->|"registers routes"| node_userroutes
node_server -->|"registers routes"| node_roleroutes
node_server -->|"registers routes"| node_scheduleroutes
node_server -->|"constructs"| node_authhandler
node_server -->|"constructs"| node_authservice
node_server -->|"constructs"| node_userhandler
node_server -->|"constructs"| node_userservice
node_server -->|"constructs"| node_rolehandler
node_server -->|"constructs"| node_roleservice
node_server -->|"constructs"| node_schedulehandler
node_server -->|"constructs"| node_scheduleservice
node_authroutes -->|"routes to"| node_authhandler
node_authroutes -->|"protects profile"| node_authmiddleware
node_authhandler -->|"calls"| node_authservice
node_authservice -->|"looks up users"| node_userrepo
node_userroutes -->|"routes to"| node_userhandler
node_userroutes -->|"protects routes"| node_authmiddleware
node_roleroutes -->|"routes to"| node_rolehandler
node_roleroutes -->|"protects routes"| node_authmiddleware
node_scheduleroutes -->|"routes to"| node_schedulehandler
node_scheduleroutes -->|"protects routes"| node_authmiddleware
node_userservice -->|"reads and writes"| node_userrepo
node_response -->|"formats JSON"| node_client

click node_server "https://github.com/teguhsugiono/be-presensi/blob/main/cmd/server/main.go"
click node_config "https://github.com/teguhsugiono/be-presensi/blob/main/internal/config/config.go"
click node_dbconnect "https://github.com/teguhsugiono/be-presensi/blob/main/internal/database/postgres.go"
click node_authroutes "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/routes/auth_routes.go"
click node_authhandler "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/handler/auth_handler.go"
click node_authservice "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/service/auth_service.go"
click node_authmiddleware "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/middleware/auth_middleware.go"
click node_authdto "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/dto/auth_dto.go"
click node_jwtclaims "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/service/jwt_claims.go"
click node_userroutes "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/routes/user_routes.go"
click node_userhandler "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/handler/user_handler.go"
click node_userservice "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/service/user_service.go"
click node_userrepo "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/repository/user_repository.go"
click node_userentity "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/entity/user.go"
click node_userdto "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/dto/user_dto.go"
click node_roleroutes "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/routes/role_routes.go"
click node_rolehandler "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/handler/role_handler.go"
click node_roleservice "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/service/role_service.go"
click node_rolerepo "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/repository/role_repository.go"
click node_roleentity "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/entity/role.go"
click node_roledto "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/dto/role_dto.go"
click node_scheduleroutes "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/routes/work_schedule_routes.go"
click node_schedulehandler "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/handler/work_schedule_handler.go"
click node_scheduleservice "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/service/work_schedule_service.go"
click node_schedulerepo "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/repository/work_schedule_repository.go"
click node_scheduleentity "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/entity/work_schedule.go"
click node_scheduledto "https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/dto/work_schedule_dto.go"
click node_response "https://github.com/teguhsugiono/be-presensi/blob/main/internal/response/response.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_config,node_dbconnect,node_postgres,node_response,node_client toneBlue
class node_authroutes,node_authhandler,node_authservice,node_authmiddleware,node_authdto,node_jwtclaims toneAmber
class node_userroutes,node_userhandler,node_userservice,node_userrepo,node_userentity,node_userdto,node_roleroutes,node_rolehandler,node_roleservice,node_rolerepo,node_roleentity,node_roledto toneMint
class node_scheduleroutes,node_schedulehandler,node_scheduleservice,node_schedulerepo,node_scheduleentity,node_scheduledto toneRose
```

## Components

### Server and storage

- [Gin server](https://github.com/teguhsugiono/be-presensi/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [App configuration](https://github.com/teguhsugiono/be-presensi/blob/main/internal/config/config.go): `internal/config/config.go`
- [Postgres connector](https://github.com/teguhsugiono/be-presensi/blob/main/internal/database/postgres.go): `internal/database/postgres.go`
- **PostgreSQL**
- [JSON responses](https://github.com/teguhsugiono/be-presensi/blob/main/internal/response/response.go): `internal/response/response.go`

### Authentication

- [Auth routes](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/routes/auth_routes.go): `internal/modules/auth/routes/auth_routes.go`
- [Auth handler](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/handler/auth_handler.go): `internal/modules/auth/handler/auth_handler.go`
- [Auth service](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/service/auth_service.go): `internal/modules/auth/service/auth_service.go`
- [JWT middleware](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/middleware/auth_middleware.go): `internal/modules/auth/middleware/auth_middleware.go`
- [Auth DTOs](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/dto/auth_dto.go): `internal/modules/auth/dto/auth_dto.go`
- [JWT claims](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/auth/service/jwt_claims.go): `internal/modules/auth/service/jwt_claims.go`

### People and roles

- [User routes](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/routes/user_routes.go): `internal/modules/user/routes/user_routes.go`
- [User handler](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/handler/user_handler.go): `internal/modules/user/handler/user_handler.go`
- [User service](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/service/user_service.go): `internal/modules/user/service/user_service.go`
- [User repository](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/repository/user_repository.go): `internal/modules/user/repository/user_repository.go`
- [User entity](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/entity/user.go): `internal/modules/user/entity/user.go`
- [User DTOs](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/user/dto/user_dto.go): `internal/modules/user/dto/user_dto.go`
- [Role routes](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/routes/role_routes.go): `internal/modules/role/routes/role_routes.go`
- [Role handler](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/handler/role_handler.go): `internal/modules/role/handler/role_handler.go`
- [Role service](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/service/role_service.go): `internal/modules/role/service/role_service.go`
- [Role repository](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/repository/role_repository.go): `internal/modules/role/repository/role_repository.go`
- [Role entity](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/entity/role.go): `internal/modules/role/entity/role.go`
- [Role DTOs](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/role/dto/role_dto.go): `internal/modules/role/dto/role_dto.go`

### Work schedules

- [Schedule routes](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/routes/work_schedule_routes.go): `internal/modules/work_schedule/routes/work_schedule_routes.go`
- [Schedule handler](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/handler/work_schedule_handler.go): `internal/modules/work_schedule/handler/work_schedule_handler.go`
- [Schedule service](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/service/work_schedule_service.go): `internal/modules/work_schedule/service/work_schedule_service.go`
- [Schedule repository](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/repository/work_schedule_repository.go): `internal/modules/work_schedule/repository/work_schedule_repository.go`
- [Schedule entity](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/entity/work_schedule.go): `internal/modules/work_schedule/entity/work_schedule.go`
- [Schedule DTOs](https://github.com/teguhsugiono/be-presensi/blob/main/internal/modules/work_schedule/dto/work_schedule_dto.go): `internal/modules/work_schedule/dto/work_schedule_dto.go`

### Other components

- **API client**

## Connections

- API client → Gin server: sends requests (evidence: `cmd/server/main.go`)
- Gin server → App configuration: loads settings (evidence: `cmd/server/main.go`)
- Gin server → Postgres connector: opens connection (evidence: `cmd/server/main.go`)
- Postgres connector → PostgreSQL: connects (evidence: `internal/database/postgres.go`)
- Gin server → Auth routes: registers routes (evidence: `cmd/server/main.go`)
- Gin server → User routes: registers routes (evidence: `cmd/server/main.go`)
- Gin server → Role routes: registers routes (evidence: `cmd/server/main.go`)
- Gin server → Schedule routes: registers routes (evidence: `cmd/server/main.go`)
- Gin server → Auth handler: constructs (evidence: `cmd/server/main.go`)
- Gin server → Auth service: constructs (evidence: `cmd/server/main.go`)
- Gin server → User handler: constructs (evidence: `cmd/server/main.go`)
- Gin server → User service: constructs (evidence: `cmd/server/main.go`)
- Gin server → Role handler: constructs (evidence: `cmd/server/main.go`)
- Gin server → Role service: constructs (evidence: `cmd/server/main.go`)
- Gin server → Schedule handler: constructs (evidence: `cmd/server/main.go`)
- Gin server → Schedule service: constructs (evidence: `cmd/server/main.go`)
- Auth routes → Auth handler: routes to (evidence: `internal/modules/auth/routes/auth_routes.go`)
- Auth routes → JWT middleware: protects profile (evidence: `internal/modules/auth/routes/auth_routes.go`)
- Auth handler → Auth service: calls (evidence: `internal/modules/auth/handler/auth_handler.go`)
- Auth service → User repository: looks up users (evidence: `internal/modules/auth/service/auth_service.go`)
- User routes → User handler: routes to (evidence: `internal/modules/user/routes/user_routes.go`)
- User routes → JWT middleware: protects routes (evidence: `internal/modules/user/routes/user_routes.go`)
- Role routes → Role handler: routes to (evidence: `internal/modules/role/routes/role_routes.go`)
- Role routes → JWT middleware: protects routes (evidence: `internal/modules/role/routes/role_routes.go`)
- Schedule routes → Schedule handler: routes to (evidence: `internal/modules/work_schedule/routes/work_schedule_routes.go`)
- Schedule routes → JWT middleware: protects routes (evidence: `internal/modules/work_schedule/routes/work_schedule_routes.go`)
- User service → User repository: reads and writes (evidence: `internal/modules/user/service/user_service.go`)
- JSON responses → API client: formats JSON (evidence: `internal/response/response.go`)
