# revandpratama/reflect-be architecture

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

- Interactive diagram: https://gitdiagram.com/revandpratama/reflect-be
- Repository: https://github.com/revandpratama/reflect-be

## Overview

##### Project type and purpose
- This repo is a Go-based microservices system.
- It consists of three independently deployable services—auth-service, logging-service, and main-app—plus a shared “shared/proto” folder for gRPC contracts and a “deployments” folder for Docker Compose orchestration.
- Purpose: main-app is the primary API gateway and business logic layer (exposes REST/gRPC), auth-service handles user authentication/authorization, logging-service processes log events (via Kafka).

##### File structure
- Top-level directories:
– auth-service: hexagonal (adapter, config, helper, internal/{controller,services,repositories,entities,dto}, generatedProtobuf)
– logging-service: adapter (Kafka), server entrypoint
– main-app: rich layered structure (adapter for gRPC, Kafka, MinIO, PostgreSQL, Redis, REST; cmd; config; errorhandler; helper; internal/{handlers,middleware,repositories,services,routes,dto,entities,generatedProtobuf}; types)
– shared/proto: .proto definitions (auth.proto) shared by services
– deployments: docker-compose setups for local and CI/CD
- Architectural clues:
– Hexagonal/Clean layers in each service
– Event-driven integration via Kafka
– Sync RPC via gRPC (auth proto)
– Polyglot persistence: PostgreSQL, Redis, MinIO object store

##### README (empty here)
- No explicit architecture section—derive from file layout and naming conventions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Clients["Clients (Web/Mobile)"]:::external

    %% Main Application Service
    subgraph "Main App Service" 
        direction TB
        MainAdapter["Adapter"]:::service
        MainCmd["Cmd (Migrations)"]:::service
        MainConfig["Config"]:::service
        MainError["ErrorHandler"]:::service
        MainHelpers["Helpers"]:::service
        MainHandlers["Handlers & Routes"]:::service
        MainServices["Services & Repositories"]:::service
        MainDTOs["DTOs & Entities"]:::service
        MainProto["Protobuf Contracts"]:::service
        MainTypes["Types"]:::service
    end

    %% Auth Service
    subgraph "Auth Service" 
        direction TB
        AuthAdapter["Adapter"]:::service
        AuthConfig["Config"]:::service
        AuthHelpers["Helpers"]:::service
        AuthController["Controller"]:::service
        AuthServiceComp["Service"]:::service
        AuthRepo["Repository"]:::service
        AuthEntities["Entities & DTOs"]:::service
        AuthProto["Protobuf Contracts"]:::service
    end

    %% Logging Service
    subgraph "Logging Service"
        direction TB
        LogAdapter["Adapter"]:::service
        LogServer["Server Entrypoint"]:::service
    end

    %% Shared Proto
    SharedProto["Shared Proto Definitions"]:::infra

    %% Message Broker
    Kafka["Kafka Cluster"]:::broker

    %% Datastores
    PostgresMain["PostgreSQL (Main App)"]:::db
    PostgresAuth["PostgreSQL (Auth Service)"]:::db
    Redis["Redis (Cache)"]:::db
    MinIO["MinIO (Object Storage)"]:::db

    %% Deployment
    DockerCompose["Docker Compose"]:::infra

    %% Connections
    Clients -->|"REST/gRPC"| MainAdapter
    MainProto -.->|uses| SharedProto
    AuthProto -.->|uses| SharedProto

    MainAdapter -->|"gRPC Auth"| AuthAdapter
    MainAdapter -.->|"Publish Events"| Kafka
    Kafka -->|"Consume Logs"| LogAdapter

    MainAdapter -->|"Read/Write"| PostgresMain
    MainAdapter -->|"Cache"| Redis
    MainAdapter -->|"Store Objects"| MinIO

    AuthAdapter -->|"Read/Write"| PostgresAuth

    DockerCompose --> MainAdapter
    DockerCompose --> AuthAdapter
    DockerCompose --> LogAdapter
    DockerCompose --> Kafka
    DockerCompose --> PostgresMain
    DockerCompose --> PostgresAuth
    DockerCompose --> Redis
    DockerCompose --> MinIO

    %% Click Events for Main App
    click MainAdapter "https://github.com/revandpratama/reflect-be/blob/main/main-app/adapter/adapter.go"
    click MainCmd "https://github.com/revandpratama/reflect-be/blob/main/main-app/cmd/auto_migrate.go"
    click MainConfig "https://github.com/revandpratama/reflect-be/blob/main/main-app/config/config.go"
    click MainError "https://github.com/revandpratama/reflect-be/blob/main/main-app/errorhandler/errorhandler.go"
    click MainHelpers "https://github.com/revandpratama/reflect-be/blob/main/main-app/helper/logger.go"
    click MainHandlers "https://github.com/revandpratama/reflect-be/blob/main/main-app/internal/handlers/auth_handler.go"
    click MainServices "https://github.com/revandpratama/reflect-be/blob/main/main-app/internal/services/comment_service.go"
    click MainDTOs "https://github.com/revandpratama/reflect-be/blob/main/main-app/internal/entities/comment.go"
    click MainProto "https://github.com/revandpratama/reflect-be/blob/main/main-app/internal/generatedProtobuf/auth/auth.pb.go"
    click MainTypes "https://github.com/revandpratama/reflect-be/blob/main/main-app/types/error.go"

    %% Click Events for Auth Service
    click AuthAdapter "https://github.com/revandpratama/reflect-be/blob/main/auth-service/adapter/adapter.go"
    click AuthConfig "https://github.com/revandpratama/reflect-be/blob/main/auth-service/config/config.go"
    click AuthHelpers "https://github.com/revandpratama/reflect-be/blob/main/auth-service/helper/logger.go"
    click AuthController "https://github.com/revandpratama/reflect-be/blob/main/auth-service/internal/controller/auth_controller.go"
    click AuthServiceComp "https://github.com/revandpratama/reflect-be/blob/main/auth-service/internal/services/auth_service.go"
    click AuthRepo "https://github.com/revandpratama/reflect-be/blob/main/auth-service/internal/repositories/auth_repository.go"
    click AuthEntities "https://github.com/revandpratama/reflect-be/blob/main/auth-service/internal/entities/user.go"
    click AuthProto "https://github.com/revandpratama/reflect-be/blob/main/auth-service/internal/generatedProtobuf/auth/auth.pb.go"

    %% Click Events for Logging Service
    click LogAdapter "https://github.com/revandpratama/reflect-be/blob/main/logging-service/adapter/kafka-go.go"
    click LogServer "https://github.com/revandpratama/reflect-be/blob/main/logging-service/server/server.go"

    %% Click for Shared Proto and Deployment
    click SharedProto "https://github.com/revandpratama/reflect-be/blob/main/shared/proto/auth.proto"
    click DockerCompose "https://github.com/revandpratama/reflect-be/blob/main/deployments/docker-compose.yml"

    %% Styles
    classDef service fill:#AEDFF7,stroke:#0366d6,color:#000
    classDef db fill:#FFDDA0,stroke:#D99058,color:#000
    classDef broker fill:#E2E2E2,stroke:#999999,color:#000
    classDef external fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef infra fill:#F0F0F0,stroke:#666666,color:#000
```
