# keybittech/awayto-v3 architecture

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

- Interactive diagram: https://gitdiagram.com/keybittech/awayto-v3
- Repository: https://github.com/keybittech/awayto-v3

## Overview

##### Main Components Structure

a) Frontend Layer (TypeScript/React)
- 'ts' directory structure with key modules:
- Auth Module
- WebSocket Module
- Groups Module
- Services Module
- Forms Module
- Common Components
- Hooks system for state management

b) Backend Services
- Go API Server
- HTTP/REST endpoints
- WebSocket handlers
- Middleware components
- Authentication integration
- Java Authentication Service (Keycloak)
- Custom event listeners
- User registration
- Theme customization

c) Infrastructure Layer
- Database (PostgreSQL)
- Redis (for session management)
- TURN Server
- Static File Server (for landing page)

##### Connection Flows
- Client-Server communication (both REST and WebSocket)
- Authentication flows through Keycloak
- Database interactions
- WebSocket real-time communications
- File storage operations

##### Key Technical Elements to Highlight

- Blue rectangles: Core services (Go API, Keycloak, Database)
- Green rectangles: Frontend modules
- Yellow diamonds: Communication protocols (REST, WebSocket)
- Purple circles: Infrastructure components (Redis, TURN)
- Orange rectangles: Development/deployment tools

##### Specific Implementation Details

Important architectural features:
- Protocol Buffer definitions (proto directory)
- Database migration scripts structure
- Docker containerization setup
- Authentication flow with Keycloak
- WebSocket real-time communication system
- And role-based access control

##### Deployment Architecture

Containerized structure:
- Docker compose setup
- Service dependencies
- Network isolation
- Volume mounts

**[Frontend Layer (React/TypeScript)]**
- ↕ HTTP/WS
**[API Gateway (Go)]**
- ↕
- [Services Layer]
- [Auth Service (Keycloak)]
- [TURN Server]
- [Static File Server]
- ↕
**[Data Layer]**
- [PostgreSQL]
- [Redis]

Important Considerations:

1. Use clear separation between frontend modules while showing their interconnections through the hooks system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        FE_Auth["Auth Module"]:::frontend
        FE_WS["WebSocket Module"]:::frontend
        FE_Groups["Groups Module"]:::frontend
        FE_Forms["Forms Module"]:::frontend
        FE_Common["Common Components"]:::frontend
        Hooks["Hooks System"]:::frontend
    end

    subgraph Backend
        API["Go API Server"]:::backend
        Handlers["API Handlers"]:::backend
        WSHandler["WebSocket Handler"]:::backend
        Middleware["Middleware"]:::backend
    end

    subgraph AuthService
        Keycloak["Keycloak Service"]:::auth
        EventListener["Custom Event Listeners"]:::auth
        Theme["Custom Theme"]:::auth
    end

    subgraph Infrastructure
        DB[(PostgreSQL)]:::db
        Redis[(Redis)]:::cache
        TURN["TURN Server"]:::infra
        Static["Static File Server"]:::infra
        Proto["Protocol Buffers"]:::proto
    end

    %% Frontend Connections
    FE_Auth --> Hooks
    FE_WS --> Hooks
    FE_Groups --> Hooks
    FE_Forms --> Hooks
    FE_Common --> Hooks

    %% Backend Connections
    Hooks --> API
    API --> Handlers
    API --> WSHandler
    API --> Middleware
    Handlers --> DB
    WSHandler --> DB
    API --> Redis
    
    %% Auth Connections
    API --> Keycloak
    Keycloak --> EventListener
    Keycloak --> Theme
    
    %% Infrastructure Connections
    API --> TURN
    API --> Static
    API --> Proto

    %% Click Events
    click FE_Auth "https://github.com/keybittech/awayto-v3/tree/main/ts/src/modules/auth/"
    click FE_WS "https://github.com/keybittech/awayto-v3/tree/main/ts/src/modules/web_socket/"
    click FE_Groups "https://github.com/keybittech/awayto-v3/tree/main/ts/src/modules/groups/"
    click FE_Forms "https://github.com/keybittech/awayto-v3/tree/main/ts/src/modules/forms/"
    click FE_Common "https://github.com/keybittech/awayto-v3/tree/main/ts/src/modules/common/"
    click Hooks "https://github.com/keybittech/awayto-v3/tree/main/ts/src/hooks/"
    click API "https://github.com/keybittech/awayto-v3/tree/main/go/pkg/api/"
    click Handlers "https://github.com/keybittech/awayto-v3/tree/main/go/pkg/handlers/"
    click WSHandler "https://github.com/keybittech/awayto-v3/blob/main/go/pkg/api/sock.go"
    click EventListener "https://github.com/keybittech/awayto-v3/blob/main/java/src/main/java/kbt/CustomEventListenerProvider.java"
    click Theme "https://github.com/keybittech/awayto-v3/tree/main/java/themes/base/"
    click Static "https://github.com/keybittech/awayto-v3/tree/main/landing/"
    click Proto "https://github.com/keybittech/awayto-v3/tree/main/proto/"
    click Redis "https://github.com/keybittech/awayto-v3/blob/main/go/pkg/clients/redis.go"
    click DB "https://github.com/keybittech/awayto-v3/blob/main/go/pkg/clients/db.go"

    classDef frontend fill:#4CAF50,stroke:#333,stroke-width:2px
    classDef backend fill:#2196F3,stroke:#333,stroke-width:2px
    classDef auth fill:#FF9800,stroke:#333,stroke-width:2px
    classDef db fill:#9C27B0,stroke:#333,stroke-width:2px
    classDef cache fill:#E91E63,stroke:#333,stroke-width:2px
    classDef infra fill:#607D8B,stroke:#333,stroke-width:2px
    classDef proto fill:#795548,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L_FE["Frontend Component"]:::frontend
        L_BE["Backend Component"]:::backend
        L_Auth["Auth Component"]:::auth
        L_DB[(Database)]:::db
        L_Cache[(Cache)]:::cache
        L_Infra["Infrastructure"]:::infra
        L_Proto["Protocol Buffers"]:::proto
    end
```
