# shelepuginivan/hakutest architecture

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

- Interactive diagram: https://gitdiagram.com/shelepuginivan/hakutest
- Repository: https://github.com/shelepuginivan/hakutest

## Overview

##### Main Components

a) Server Component:
- Located in `internal/app/server`
- Controllers (student and teacher)
- Template engine integration
- Middleware layer

b) Web Interface:
- Located in `web` directory
- Static assets (CSS, JS, templates)
- Separation between student and teacher views

c) Core Testing Engine:
- Located in `pkg` directory
- Test management (`pkg/test`)
- Result processing (`pkg/result`)
- Statistics handling (`pkg/statistics`)

d) Security Layer:
- Located in `pkg/security` and `internal/pkg/security`
- JWT implementation
- Role-based access control
- Network security components

**[Client Layer]**
- Web Browsers
- hakuctl CLI Tool

**[Presentation Layer]**
- Web Templates (GoHTML)
- Static Assets
- System Tray Interface

**[Application Layer]**
- Server Controllers
- Security Middleware
- Test Engine
- Result Processor
- Statistics Generator

**[Core Services]**
- Configuration Management
- Internationalization (i18n)
- File System Operations
- Network Services

**[Storage Layer]**
- Test Files (JSON)
- Results Storage
- Statistics Export (CSV/XLSX)

##### Key Interactions to Highlight

- Flow of test data from storage through the test engine to presentation
- Security layer's interaction with all components
- Demonstrate how the statistics module interfaces with results storage

##### Additional Elements

- Version information from `pkg/version`
- Configuration flow from `.semver.yaml`
- Supported export formats (CSV, JSON, XLSX)

##### Implementation Notes

- Use standard UML notation where applicable
- Keep component sizes proportional to their importance
- Clear labels for all components and data flows

- Local network operation
- Secure test delivery
- Automated answer checking
- Real-time result processing
- Cross-platform compatibility
- Multi-language support

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browsers"]
        CLI["hakuctl CLI Tool"]:::cli
        SysTray["System Tray Interface"]:::tray
    end

    subgraph Presentation
        Templates["Web Templates"]:::templates
        StaticAssets["Static Assets"]:::static
        subgraph Assets
            CSS["CSS"]:::static
            JS["JavaScript"]:::static
            Partials["Partial Templates"]:::static
        end
    end

    subgraph Application
        Server["Server Component"]:::server
        subgraph Controllers
            TeacherCtrl["Teacher Controller"]:::controller
            StudentCtrl["Student Controller"]:::controller
        end
        Middleware["Security Middleware"]:::middleware
        TestEngine["Test Engine"]:::core
        ResultProc["Result Processor"]:::core
        StatsGen["Statistics Generator"]:::core
    end

    subgraph CoreServices
        Config["Configuration Management"]:::config
        I18n["Internationalization"]:::i18n
        FileOps["File System Operations"]
        Network["Network Services"]:::network
    end

    subgraph Security
        JWT["JWT Authentication"]:::security
        RBAC["Role-Based Access"]:::security
        NetSec["Network Security"]:::security
    end

    subgraph Storage
        TestFiles["Test Files (JSON)"]
        Results["Results Storage"]
        StatsExport["Statistics Export"]
        subgraph ExportFormats
            CSV["CSV Export"]:::export
            XLSX["XLSX Export"]:::export
            JSON["JSON Export"]:::export
        end
    end

    Browser --> Server
    Server --> Browser
    CLI --> Server
    SysTray --> Server

    Server --> Templates
    StaticAssets --> Browser
    Assets --> StaticAssets

    Server --> Controllers
    Controllers --> TestEngine
    TestEngine --> ResultProc
    ResultProc --> StatsGen
    
    Security --> Server
    Security --> Controllers
    
    CoreServices --> Server
    CoreServices --> Security

    TestEngine --> TestFiles
    ResultProc --> Results
    StatsGen --> StatsExport
    StatsExport --> ExportFormats

    %% Click Events
    click CLI "https://github.com/shelepuginivan/hakutest/tree/main/cmd/hakuctl"
    click SysTray "https://github.com/shelepuginivan/hakutest/tree/main/internal/app/tray"
    click Templates "https://github.com/shelepuginivan/hakutest/tree/main/web/templates"
    click CSS "https://github.com/shelepuginivan/hakutest/tree/main/web/css"
    click JS "https://github.com/shelepuginivan/hakutest/tree/main/web/js"
    click Partials "https://github.com/shelepuginivan/hakutest/tree/main/web/partials"
    click Server "https://github.com/shelepuginivan/hakutest/tree/main/internal/app/server"
    click Middleware "https://github.com/shelepuginivan/hakutest/blob/main/internal/app/server/middlewares.go"
    click TestEngine "https://github.com/shelepuginivan/hakutest/tree/main/pkg/test"
    click ResultProc "https://github.com/shelepuginivan/hakutest/tree/main/pkg/result"
    click StatsGen "https://github.com/shelepuginivan/hakutest/tree/main/pkg/statistics"
    click JWT "https://github.com/shelepuginivan/hakutest/blob/main/internal/pkg/security/jwt.go"
    click RBAC "https://github.com/shelepuginivan/hakutest/blob/main/pkg/security/roles.go"
    click Config "https://github.com/shelepuginivan/hakutest/tree/main/internal/pkg/config"
    click I18n "https://github.com/shelepuginivan/hakutest/tree/main/internal/pkg/i18n"
    click Network "https://github.com/shelepuginivan/hakutest/tree/main/internal/pkg/network"
    click CSV "https://github.com/shelepuginivan/hakutest/blob/main/pkg/statistics/csv.go"
    click XLSX "https://github.com/shelepuginivan/hakutest/blob/main/pkg/statistics/xlsx.go"
    click JSON "https://github.com/shelepuginivan/hakutest/blob/main/pkg/statistics/json.go"

    %% Styling
    classDef server fill:#2196F3
    classDef controller fill:#1976D2
    classDef middleware fill:#0D47A1
    classDef core fill:#FF9800
    classDef security fill:#4CAF50
    classDef static fill:#9C27B0
    classDef templates fill:#673AB7
    classDef config fill:#795548
    classDef network fill:#607D8B
    classDef export fill:#FFC107
    classDef cli fill:#E91E63
    classDef tray fill:#9E9E9E
    classDef i18n fill:#3F51B5
```
