# k3k13a1/rm_auth architecture

> Architecture diagram of the GitHub repository k3k13a1/rm_auth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/k3k13a1/rm_auth
- Repository: https://github.com/k3k13a1/rm_auth

## Overview

##### Main Components Identification
The project is clearly a backend service with both REST and gRPC capabilities. The key components to represent are:

a. External Interfaces Layer:
- REST API Server
- gRPC Server

b. Application Core:
- Authentication Service
- JWT Management
- Configuration Management
- Logging System

c. Data Layer:
- PostgreSQL Database
- Storage Interface

##### Architectural Pattern

Outer Layer (Entry Points):
- REST Handlers (/internal/handlers/rest)
- gRPC Handlers (/internal/handlers/grpc)

Middle Layer (Business Logic):
- Services (/internal/services)
- Core Components (/internal/core)

Inner Layer (Data):
- Storage Interface
- PostgreSQL Implementation

##### Component Relationships

a. Request Flow:
- External clients → REST/gRPC Handlers
- Handlers → Auth Service
- Auth Service → Storage Interface
- Storage Interface → PostgreSQL

b. Cross-cutting Concerns:
- Configuration (affects all layers)
- Logging (affects all layers)
- JWT (used by multiple components)

##### Additional Details

Infrastructure Components:
- Docker containers (show containerization boundary)
- Database migrations
- Environment configuration

##### Important Notes

- Dual-protocol nature (REST/gRPC) of the service
- Clear boundaries between layers
- Configuration injection points
- Database migration flow
- Environment configuration management

##### Technical Stack Callouts

Technology badges or labels for:
- Go
- gRPC
- PostgreSQL
- Docker
- JWT

Remember to maintain a balance between showing enough detail to understand the system's architecture while not overwhelming the viewer with implementation-specific details. The focus should be on the component interaction and data flow rather than internal implementation details.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "External Layer"
        Client1[Client HTTP]
        Client2[Client gRPC]
    end

    subgraph "API Layer"
        REST["REST API Server"]:::api
        GRPC["gRPC Server"]:::api
        
        subgraph "Handlers"
            RestHandler["REST Handler"]:::handler
            GrpcHandler["gRPC Handler"]:::handler
        end
    end

    subgraph "Service Layer"
        AuthService["Authentication Service"]:::service
        JWT["JWT Management"]:::core
        UserModel["User Models"]:::core
    end

    subgraph "Data Layer"
        StorageInterface["Storage Interface"]:::storage
        PostgreSQL[(PostgreSQL DB)]:::db
        Migrations["DB Migrations"]:::db
    end

    subgraph "Infrastructure"
        Config["Configuration Management"]:::infra
        Logger["Logging System"]:::infra
    end

    %% Connections
    Client1 --> REST
    Client2 --> GRPC
    REST --> RestHandler
    GRPC --> GrpcHandler
    RestHandler --> AuthService
    GrpcHandler --> AuthService
    AuthService <--> JWT
    AuthService --> UserModel
    AuthService --> StorageInterface
    StorageInterface --> PostgreSQL
    Migrations -.- PostgreSQL
    Config -.-> REST
    Config -.-> GRPC
    Config -.-> AuthService
    Config -.-> PostgreSQL
    Logger -.-> REST
    Logger -.-> GRPC
    Logger -.-> AuthService
    Logger -.-> PostgreSQL

    %% Click Events
    click REST "https://github.com/k3k13a1/rm_auth/blob/main/internal/app/rest/app.go"
    click GRPC "https://github.com/k3k13a1/rm_auth/blob/main/internal/app/grpc/app.go"
    click RestHandler "https://github.com/k3k13a1/rm_auth/blob/main/internal/handlers/rest/auth/auth.go"
    click GrpcHandler "https://github.com/k3k13a1/rm_auth/blob/main/internal/handlers/grpc/auth/server.go"
    click AuthService "https://github.com/k3k13a1/rm_auth/blob/main/internal/services/auth/auth.go"
    click JWT "https://github.com/k3k13a1/rm_auth/blob/main/internal/core/jwt/jwt.go"
    click UserModel "https://github.com/k3k13a1/rm_auth/blob/main/internal/core/models/user.go"
    click StorageInterface "https://github.com/k3k13a1/rm_auth/blob/main/internal/storage/storage.go"
    click PostgreSQL "https://github.com/k3k13a1/rm_auth/blob/main/internal/storage/postgres/postgres.go"
    click Config "https://github.com/k3k13a1/rm_auth/blob/main/internal/config/config.go"
    click Logger "https://github.com/k3k13a1/rm_auth/blob/main/internal/logger/setup.go"
    click Migrations "https://github.com/k3k13a1/rm_auth/blob/main/migrations/01_init.sql"

    %% Styles
    classDef api fill:#2374ab
    classDef handler fill:#48a9a6
    classDef service fill:#e4572e
    classDef core fill:#ffc914
    classDef storage fill:#a786df
    classDef db fill:#583d72
    classDef infra fill:#95a5a6

    %% Legend
    subgraph Legend
        L1["API Components"]:::api
        L2["Handlers"]:::handler
        L3["Services"]:::service
        L4["Core Components"]:::core
        L5["Storage"]:::storage
        L6["Database"]:::db
        L7["Infrastructure"]:::infra
    end
```
