# saurabh-sde/otp-authentication-go architecture

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

- Interactive diagram: https://gitdiagram.com/saurabh-sde/otp-authentication-go
- Repository: https://github.com/saurabh-sde/otp-authentication-go

## Overview

##### Project type and purpose
- This is a Go-based backend microservices system combining two Connect RPC services—an Auth Service and an OTP Service—plus messaging and persistence layers.
- Purpose: Let clients sign up/login with phone numbers, generate and verify OTPs via Twilio, persist user data and events in PostgreSQL, and coordinate between services over RabbitMQ.

##### File structure
- Top-level files:
- main.go: entry point running both services (or one per configuration)
- go.mod/sum, buf.*.yaml: Go modules and Connect RPC code generation
- README.md: project overview and instructions
- Directories:
- auth, client: client stubs and helpers for calling services
- internal/proto + internal/gen: .proto definitions and generated Connect RPC code for auth_service and otp_service
- service: business-logic layers (auth.go, otp.go, twilio.go)
- messagingQueue: RabbitMQ publisher (“publish”) and consumer (“receive”) implementations
- model: ORM models (User, LogEvent)
- utility: helper functions
- query.sql: initial DB schema

##### Readme insights
- Two Connect RPC services: Auth Service (signup, verify, login, get profile) and OTP Service (generate OTP).
- Uses Beego ORM for PostgreSQL persistence.
- Uses RabbitMQ topics (“verification”) to publish “SendOTP” events.
- OTP Service listens on that topic and invokes Twilio’s Verify API.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Clients"
        direction TB
        ClientTools["Client (Postman / Go client)"]:::client
    end

    %% Auth Service Layer
    subgraph "Auth Service"
        direction TB
        AuthService["Auth Service<br/>(Connect gRPC Server)"]:::service
        AuthProto["auth.proto"]:::proto
        AuthGen["auth.pb.go<br/>& auth.connect.go"]:::generated
        AuthLogic["service/auth.go"]:::service
        AuthHandler["auth/auth.go"]:::service
    end

    %% OTP Service Layer
    subgraph "OTP Service"
        direction TB
        OTPService["OTP Service<br/>(gRPC Server & RabbitMQ Consumer)"]:::service
        OTPProto["otp.proto"]:::proto
        OTPGen["otp.pb.go<br/>& otp.connect.go"]:::generated
        OTPlogic["service/otp.go"]:::service
        TwilioLogic["service/twilio.go"]:::service
        Recv["messagingQueue/recieve/recieve.go"]:::messaging
    end

    %% Messaging Broker
    RabbitMQ["RabbitMQ<br/>Topic: verification"]:::broker

    %% Persistence Layer
    subgraph "Persistence (PostgreSQL)"
        direction TB
        DB["PostgreSQL"]:::database
        UserModel["model/user.go"]:::model
        LogModel["model/log_event.go"]:::model
        SQL["query.sql"]:::model
    end

    %% Utility & Entry
    Utility["utility/utility.go"]:::utility
    Entry["main.go<br/>& config files"]:::entry

    %% External API
    ExternalTwilio["Twilio Verify API"]:::external

    %% Connections
    ClientTools -->|"Connect RPC: SignupWithPhoneNumber, VerifyPhoneNumber,\nLoginWithPhoneNumber, GetProfile"| AuthService
    AuthService -->|"ORM CRUD"| DB
    AuthService -->|"Publish SendOTP event"| RabbitMQ
    RabbitMQ -->|"Consume verification topic"| OTPService
    OTPService -->|"HTTP Request"| ExternalTwilio
    ClientTools -->|"Connect RPC: GenerateOTP"| OTPService
    OTPService -->|"Optional ORM"| DB
    Entry --> AuthService
    Entry --> OTPService
    Utility --> AuthService
    Utility --> OTPService
    AuthProto --> AuthGen
    OTPProto --> OTPGen

    %% Click Events
    click AuthProto "https://github.com/saurabh-sde/otp-authentication-go/blob/main/internal/proto/auth_service/v1/auth.proto"
    click AuthGen "https://github.com/saurabh-sde/otp-authentication-go/blob/main/internal/gen/auth_service/v1/auth.pb.go"
    click AuthGen "https://github.com/saurabh-sde/otp-authentication-go/blob/main/internal/gen/auth_service/v1/auth_servicev1connect/auth.connect.go"
    click AuthLogic "https://github.com/saurabh-sde/otp-authentication-go/blob/main/service/auth.go"
    click AuthHandler "https://github.com/saurabh-sde/otp-authentication-go/blob/main/auth/auth.go"
    click OTPProto "https://github.com/saurabh-sde/otp-authentication-go/blob/main/internal/proto/otp_service/v1/otp.proto"
    click OTPGen "https://github.com/saurabh-sde/otp-authentication-go/blob/main/internal/gen/otp_service/v1/otp.pb.go"
    click OTPGen "https://github.com/saurabh-sde/otp-authentication-go/blob/main/internal/gen/otp_service/v1/otp_servicev1connect/otp.connect.go"
    click OTPlogic "https://github.com/saurabh-sde/otp-authentication-go/blob/main/service/otp.go"
    click TwilioLogic "https://github.com/saurabh-sde/otp-authentication-go/blob/main/service/twilio.go"
    click Recv "https://github.com/saurabh-sde/otp-authentication-go/blob/main/messagingQueue/recieve/recieve.go"
    click Utility "https://github.com/saurabh-sde/otp-authentication-go/blob/main/utility/utility.go"
    click Entry "https://github.com/saurabh-sde/otp-authentication-go/blob/main/main.go"
    click Entry "https://github.com/saurabh-sde/otp-authentication-go/blob/main/buf.gen.yaml"
    click Entry "https://github.com/saurabh-sde/otp-authentication-go/blob/main/buf.work.yaml"
    click Entry "https://github.com/saurabh-sde/otp-authentication-go/blob/main/go.mod"
    click Entry "https://github.com/saurabh-sde/otp-authentication-go/blob/main/go.sum"
    click Entry "https://github.com/saurabh-sde/otp-authentication-go/blob/main/README.md"
    click UserModel "https://github.com/saurabh-sde/otp-authentication-go/blob/main/model/user.go"
    click LogModel "https://github.com/saurabh-sde/otp-authentication-go/blob/main/model/log_event.go"
    click SQL "https://github.com/saurabh-sde/otp-authentication-go/blob/main/query.sql"
    click MessagingPublish "https://github.com/saurabh-sde/otp-authentication-go/blob/main/messagingQueue/publish/publish.go"

    %% Styles
    classDef client fill:#B3E5FC,stroke:#0288D1,color:#000
    classDef service fill:#BBDEFB,stroke:#1976D2,color:#000
    classDef proto fill:#E1BEE7,stroke:#8E24AA,color:#000
    classDef generated fill:#EDE7F6,stroke:#5E35B1,color:#000
    classDef messaging fill:#FFECB3,stroke:#FFB300,color:#000
    classDef broker fill:#FFE0B2,stroke:#FB8C00,color:#000
    classDef database fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef model fill:#DCEDC8,stroke:#558B2F,color:#000
    classDef utility fill:#F0F4C3,stroke:#9E9D24,color:#000
    classDef entry fill:#CFD8DC,stroke:#455A64,color:#000
    classDef external fill:#D1C4E9,stroke:#6A1B9A,color:#000
```
