# akbaralishaikh/denti architecture

> Architecture diagram of the GitHub repository akbaralishaikh/denti, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akbaralishaikh/denti
- Repository: https://github.com/akbaralishaikh/denti

## Overview

##### Project type and purpose
- This is a Go-based REST API application for a dental clinic, built with the Clean Architecture / DDD / Hexagonal style.
- It exposes HTTP endpoints (health check, user management, login, patient management) backed by GORM ORM and uses Docker for local orchestration.

##### File structure
- Top level:
- cmd/server
└ router.go, server.go (entry point and HTTP router bootstrap)
- denti.go (optional root entry)
- docker/ (docker-compose.yml), dockerfile
- go.mod, go.sum
- pkg/
– config (config loader, config.yml)
– di (dependency injection container with Uber Dig)
– logger (Zap logger)
– http/rest (Gin handlers: health, login, user)
– login, user, patient (domain entities, repository interfaces, service/use-case implementations)
– storage (driver interface; orm folder with GORM repository implementations)
- No “frontend” – it’s purely a backend service.

##### README for additional insights
- Emphasizes Clean Architecture, DDD, Hexagonal layering
- Core dependencies: gin (HTTP), gorm (ORM), zap (logging), dig (DI), configor (config)
- Typical run/test commands

a. Main components
- Delivery Layer: Gin HTTP Server (cmd/server + pkg/http/rest)
- Application Layer: Use-cases / services (pkg/user/service, pkg/login/service, pkg/patient/service)
- Domain Layer: Entities and interfaces (pkg/user/user.go, pkg/login/login.go, pkg/patient/patient.go + repository interfaces)
- Infrastructure Layer: Persistence (pkg/storage/orm/*.go implementing repository interfaces using GORM), Logger (pkg/logger), Config (pkg/config), DI Container (pkg/di)
- External Dependencies: SQL database (e.g., PostgreSQL/MySQL), Docker environment
b. Relationships and interactions
- HTTP handlers receive requests → invoke DI container to resolve service instances
- Services execute business logic → call repository interfaces
- ORM implementations persist/fetch data from the database
- Config loader initializes config values early in the bootstrap
- Logger is injected across layers for structured logging
c. Architectural patterns
- Hexagonal / Ports-and-Adapters:
– Ports: repository interfaces in domain packages
– Adapters: GORM-based implementations in pkg/storage/orm
- Dependency Injection with Uber Dig for wiring concrete adapters to domain ports
- Separation of Concerns: Delivery, Application, Domain, Infrastructure layers
d. Key technologies
- Go / Gin for HTTP API
- GORM for ORM/persistence
- Zap for logging
- Dig for DI
- Configor or viper-style config loader
- Docker / Docker-Compose for environment

##### Summary of essential elements
- Clearly separate Delivery / Application / Domain / Infrastructure
- Ports (interfaces) vs. Adapters (concrete implementations)
- DI container wiring connections
- Data flows from HTTP → business logic → persistence
- External dependencies (database, Docker environment)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Delivery Layer
    subgraph "Delivery Layer"
        direction TB
        Router["Router\n(cmd/server/router.go)"]:::delivery
        Server["Server\n(cmd/server/server.go)"]:::delivery
        HealthHandler["HealthHandler\n(pkg/http/rest/health_handler.go)"]:::delivery
        LoginHandler["LoginHandler\n(pkg/http/rest/login_handler.go)"]:::delivery
        UserHandler["UserHandler\n(pkg/http/rest/user_handler.go)"]:::delivery
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        UserService["UserService\n(pkg/user/service.go)"]:::application
        LoginService["LoginService\n(pkg/login/service.go)"]:::application
        PatientService["PatientService\n(pkg/patient/service.go)"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        UserEntity["User Entity\n(pkg/user/user.go)"]:::domain
        LoginEntity["Login Entity\n(pkg/login/login.go)"]:::domain
        PatientEntity["Patient Entity\n(pkg/patient/patient.go)"]:::domain
        UserRepoInterface["UserRepository (interface)\n(pkg/user/repository.go)"]:::domain
        LoginRepoInterface["LoginRepository (interface)\n(pkg/login/repository.go)"]:::domain
        PatientRepoInterface["PatientRepository (interface)\n(pkg/patient/repository.go)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        StorageDriver["Storage Driver Interface\n(pkg/storage/driver.go)"]:::infrastructure
        UserRepoAdapter["GORM UserRepo Adapter\n(pkg/storage/orm/user_repo.go)"]:::infrastructure
        LoginRepoAdapter["GORM LoginRepo Adapter\n(pkg/storage/orm/login_repo.go)"]:::infrastructure
        PatientRepoAdapter["GORM PatientRepo Adapter\n(pkg/storage/orm/patient_repo.go)"]:::infrastructure
        ConfigLoader["Config Loader\n(pkg/config/config.go)"]:::infrastructure
        ConfigFile["Config File\n(pkg/config/config.yml)"]:::infrastructure
        LoggerComp["Logger\n(pkg/logger/logger.go)"]:::infrastructure
        ZapLogger["Zap Logger\n(pkg/logger/zaplog.go)"]:::infrastructure
        DIContainer["DI Container\n(pkg/di/di.go)"]:::infrastructure
    end

    %% External
    subgraph "External Dependencies"
        direction TB
        Database[(PostgreSQL/MySQL)]:::external
        DockerCompose["docker-compose.yml\n(docker/docker-compose.yml)"]:::external
        Dockerfile["Dockerfile\n(dockerfile)"]:::external
        RootEntry["denti.go"]:::external
    end

    %% Connections
    Server -->|uses| Router
    Router -->|routes to| HealthHandler
    Router -->|routes to| LoginHandler
    Router -->|routes to| UserHandler

    HealthHandler -->|calls| DIContainer
    LoginHandler -->|calls| DIContainer
    UserHandler -->|calls| DIContainer

    DIContainer --> UserService
    DIContainer --> LoginService
    DIContainer --> PatientService
    DIContainer --> ConfigLoader
    DIContainer --> LoggerComp

    UserService -->|uses| UserRepoInterface
    LoginService -->|uses| LoginRepoInterface
    PatientService -->|uses| PatientRepoInterface

    UserRepoInterface -->|implemented by| UserRepoAdapter
    LoginRepoInterface -->|implemented by| LoginRepoAdapter
    PatientRepoInterface -->|implemented by| PatientRepoAdapter

    StorageDriver -->|defines port for| UserRepoAdapter
    StorageDriver -->|defines port for| LoginRepoAdapter
    StorageDriver -->|defines port for| PatientRepoAdapter

    UserRepoAdapter -->|persists to| Database
    LoginRepoAdapter -->|persists to| Database
    PatientRepoAdapter -->|persists to| Database

    ConfigLoader -->|loads| ConfigFile
    LoggerComp -->|initializes| ZapLogger

    DockerCompose -->|orchestrates| Database
    DockerCompose -->|builds image from| Dockerfile

    RootEntry -->|optional entry| Server

    %% Click Events
    click Router "https://github.com/akbaralishaikh/denti/blob/master/cmd/server/router.go"
    click Server "https://github.com/akbaralishaikh/denti/blob/master/cmd/server/server.go"
    click HealthHandler "https://github.com/akbaralishaikh/denti/blob/master/pkg/http/rest/health_handler.go"
    click LoginHandler "https://github.com/akbaralishaikh/denti/blob/master/pkg/http/rest/login_handler.go"
    click UserHandler "https://github.com/akbaralishaikh/denti/blob/master/pkg/http/rest/user_handler.go"
    click UserService "https://github.com/akbaralishaikh/denti/blob/master/pkg/user/service.go"
    click LoginService "https://github.com/akbaralishaikh/denti/blob/master/pkg/login/service.go"
    click PatientService "https://github.com/akbaralishaikh/denti/blob/master/pkg/patient/service.go"
    click UserEntity "https://github.com/akbaralishaikh/denti/blob/master/pkg/user/user.go"
    click LoginEntity "https://github.com/akbaralishaikh/denti/blob/master/pkg/login/login.go"
    click PatientEntity "https://github.com/akbaralishaikh/denti/blob/master/pkg/patient/patient.go"
    click UserRepoInterface "https://github.com/akbaralishaikh/denti/blob/master/pkg/user/repository.go"
    click LoginRepoInterface "https://github.com/akbaralishaikh/denti/blob/master/pkg/login/repository.go"
    click PatientRepoInterface "https://github.com/akbaralishaikh/denti/blob/master/pkg/patient/repository.go"
    click StorageDriver "https://github.com/akbaralishaikh/denti/blob/master/pkg/storage/driver.go"
    click UserRepoAdapter "https://github.com/akbaralishaikh/denti/blob/master/pkg/storage/orm/user_repo.go"
    click LoginRepoAdapter "https://github.com/akbaralishaikh/denti/blob/master/pkg/storage/orm/login_repo.go"
    click PatientRepoAdapter "https://github.com/akbaralishaikh/denti/blob/master/pkg/storage/orm/patient_repo.go"
    click ConfigLoader "https://github.com/akbaralishaikh/denti/blob/master/pkg/config/config.go"
    click ConfigFile "https://github.com/akbaralishaikh/denti/blob/master/pkg/config/config.yml"
    click LoggerComp "https://github.com/akbaralishaikh/denti/blob/master/pkg/logger/logger.go"
    click ZapLogger "https://github.com/akbaralishaikh/denti/blob/master/pkg/logger/zaplog.go"
    click DIContainer "https://github.com/akbaralishaikh/denti/blob/master/pkg/di/di.go"
    click DockerCompose "https://github.com/akbaralishaikh/denti/blob/master/docker/docker-compose.yml"
    click Dockerfile "https://github.com/akbaralishaikh/denti/tree/master/dockerfile"
    click RootEntry "https://github.com/akbaralishaikh/denti/blob/master/denti.go"

    %% Styles
    classDef delivery fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef application fill:#DFFFE0,stroke:#228B22,color:#228B22;
    classDef domain fill:#FFF5BA,stroke:#DAA520,color:#DAA520;
    classDef infrastructure fill:#FFE4C4,stroke:#FF8C00,color:#FF8C00;
    classDef external fill:#F0F0F0,stroke:#999999,color:#333333;
```
