# kophaiphuoc/2fa-php architecture

> Architecture diagram of the GitHub repository kophaiphuoc/2fa-php, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kophaiphuoc/2fa-php
- Repository: https://github.com/kophaiphuoc/2fa-php

## Overview

##### Project Type and Purpose
- This project is a full-stack application that leverages the Wails framework to enable calling Go methods from a React/TS frontend.
- The README confirms that it is structured as a Wails React-TS template. The primary purpose is to provide a development environment with live hot-reloading (via Vite) and a bridge between the Go backend and the React frontend.

##### Analyzing the File Structure
- The root contains key configuration files (go.mod, go.sum, wails.json, main.go) and project metadata (README, LICENSE).
- The Go source files reside in the “app” directory (files like app.go, capture.go, db.go, etc.), representing the business logic and backend functionality.
- A dedicated “frontend” directory holds the React TypeScript application, including components, assets, styling, and build/config files (package.json, vite.config.ts).
- The “wailsjs” folder inside “frontend” suggests auto-generated bindings or runtime code that facilitates communication between the Go backend and the React frontend.
- The “build” folder along with platform-specific files (e.g., darwin/Info.plist) points to deployment scripts and packaging configurations.

##### Extracting Additional Insights from the README
- The README highlights live development using “wails dev” and production builds via “wails build”. This indicates an architecture that supports iterative frontend development using Vite and integration testing against real Go endpoints.

a. Main Components:
- Frontend Application: Contains React components (e.g., Home, Input2FA, CardOtp, QRCodeScanner, etc.) and is served by a Vite development server.
- Wails Bridge/Runtime: The Wails-generated code (found in the “wailsjs” directory) that “glues” the frontend to the Go backend.
- Backend Application: Consists of Go source files (in “app” and main.go) that handle core logic such as database operations, encoding, OTP generation, QR code generation, etc.
- Configuration & Build System: Files like wails.json, build scripts (fix_plist.sh), and other configuration files (go.mod, package.json) indicate how the project is set up and deployed.

b. Determining Relationships and Interactions:
- The Wails runtime acts as an intermediary, exposing backend functions to the frontend.
- Components of the frontend may interact with local assets or external services (if applicable).
- Build and deployment pipelines are triggered through scripts and configuration files (wails build, live dev mode via Vite).

c. Important Architectural Patterns and Design Principles:
- Separation of Concerns: Clear separation between UI (frontend) and application logic (backend).
- Bridging: The Wails framework facilitates communication between Go and React.
- Hot Reload and Development Mode: Use of Vite indicates a modern frontend development setup that supports rapid iteration.
- Modular Structure: The Go backend is modularized (different files for operations, OTP, qrcode, etc.) and the React components are organized under a dedicated folder.

d. Relevant Technologies, Frameworks, Libraries:
- Go for the backend logic.
- React with TypeScript for the frontend.
- Vite for the development and build process.
- Wails, which serves as the framework for connecting the Go backend with the React frontend.
- Additional JS tooling is noted via package.json for dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Frontend (Vite & TS)"]:::frontend
    end

    %% Bridge Layer
    subgraph "Bridge Layer"
        BR["Wails Bridge/Runtime"]:::bridge
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Go Backend Application"]:::backend
    end

    %% Configuration & Build System
    subgraph "Configuration & Build System"
        CF["Build & Deployment Scripts/Configurations"]:::config
    end

    %% Connections
    FE -->|"calls"| BR
    BR -->|"invokes"| BE
    CF -->|"configures"| FE
    CF -->|"configures"| BR
    CF -->|"configures"| BE

    %% Click Events for React Frontend (Vite & TS)
    click FE "https://github.com/kophaiphuoc/2fa-php/tree/main/frontend/src"
    click FE "https://github.com/kophaiphuoc/2fa-php/blob/main/frontend/package.json"
    click FE "https://github.com/kophaiphuoc/2fa-php/blob/main/frontend/vite.config.ts"

    %% Click Events for Wails Bridge/Runtime
    click BR "https://github.com/kophaiphuoc/2fa-php/tree/main/frontend/wailsjs"

    %% Click Events for Go Backend Application
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/main.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/app.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/capture.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/db.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/encode.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/file.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/operations.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/otp.go"
    click BE "https://github.com/kophaiphuoc/2fa-php/blob/main/app/qrcode.go"

    %% Click Events for Build & Deployment Scripts/Configurations
    click CF "https://github.com/kophaiphuoc/2fa-php/tree/main/build"
    click CF "https://github.com/kophaiphuoc/2fa-php/blob/main/fix_plist.sh"
    click CF "https://github.com/kophaiphuoc/2fa-php/blob/main/wails.json"
    click CF "https://github.com/kophaiphuoc/2fa-php/blob/main/go.mod"
    click CF "https://github.com/kophaiphuoc/2fa-php/blob/main/go.sum"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef bridge fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef config fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
