# u0nkis/assignhub architecture

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

- Interactive diagram: https://gitdiagram.com/u0nkis/assignhub
- Repository: https://github.com/u0nkis/assignhub

## Overview

##### Project Type and Purpose
- This is a full-stack web application built as a student assignment and code-judge platform (“Курсовая работа”).
- The frontend is a React/Vite single-page app; the backend is a Go monolith exposing REST APIs, handling user auth, assignments, submissions, and code judging; data is persisted in a relational database; metrics are collected via Prometheus.

##### File Structure Analysis
- Top-level:
- backend/: Go source organized by config, db access, handlers (assignment, auth, code, judge, submission, user), middleware (CORS, auth, rate–limit, security, metrics), models, utils, logger, main.go, Dockerfile.
- frontend/: React app with Vite build (src/, public/, dist/, Dockerfile).
- docker-compose.yaml: orchestrates backend, frontend, DB, Prometheus.
- init.sql: initial schema.
- prometheus/: config for scraping metrics.

- Architectural patterns:
- Layered backend (router → middleware → handlers → models → DB).
- RESTful API.
- Decoupled judge component invoked via handlers.
- Externalized metrics (Prometheus).

##### README Insights
- Minimal (“Курсовая работа”), so we infer architecture solely from code organization and build/deploy configs.

a. Main Components
1. Client (Web Browser)
2. Frontend SPA (React/Vite, TailwindCSS)
3. API Gateway / Backend (Go monolith)
4. Database (PostgreSQL)
5. Code Judge Engine (sandboxed process invoked by backend)
6. File Storage (local or mounted volume for submission files)
7. Monitoring (Prometheus)
8. Docker / Docker-Compose Orchestration

b. Relationships & Data Flows
- Browser ↔ Frontend (HTTP/HTTPS)
- Frontend → Backend REST API (JSON over HTTP)
- Backend ↔ DB (SQL)
- Backend → Code Judge Engine (spawned subprocess, pipes I/O, reads/writes to file storage)
- Backend → File Storage (upload/download submission files)
- Backend → Prometheus (expose /metrics endpoint)
- Prometheus → Backend (scrape metrics)

c. Architectural Patterns & Principles
- Layered separation: presentation (frontend), API layer, business logic (handlers), data access (models).
- Middleware pipeline for cross-cutting concerns (auth, CORS, rate limiting, logging, security, metrics).
- Single responsibility: each handler (assignment, submission, judge) encapsulates its domain.
- Containerization: each major component in its own Docker service.

d. Key Technologies
- Frontend: React, Vite, TailwindCSS, Axios
- Backend: Go, Gin or net/http, Docker
- Database: PostgreSQL (init.sql)
- Observability: Prometheus
- CI/CD: Docker-Compose

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Web Browser"]:::client

    %% Docker Compose Orchestration
    subgraph "Docker-Compose Orchestration"
        direction TB
        ComposeSvc["docker-compose.yaml"]:::orchestration

        %% Frontend Service
        subgraph "Frontend Service" 
            direction TB
            ReactSPA["React SPA (Vite, TailwindCSS)"]:::frontend
            Entry["Index (src/index.jsx)"]:::frontend
            APIFE["API Module (src/api/api.js)"]:::frontend
            AssignComp["Assignments Components"]:::frontend
            AuthComp["Auth Components"]:::frontend
            CodeEditor["Code Editor Component"]:::frontend
            Layout["Main Layout & Routing"]:::frontend
            Pages["Pages Directory"]:::frontend
            UtilsFE["Utility Functions"]:::frontend
            TailwindCfg["Tailwind Config"]:::frontend
        end

        %% Backend Service
        subgraph "Backend Service" 
            direction TB
            GoAPI["Go API Monolith (:8080)"]:::backend
            ConfigLoader["Config Loader"]:::backend
            DBAccess["DB Connection & Queries"]:::backend
            ModelsBE["Models (ORM structs)"]:::backend
            Handlers["HTTP Handlers (assignment, auth, code, file, judge, submission, user)"]:::backend
            Middleware["Middleware (CORS, Auth, Rate-Limit, Security, Metrics, Logging)"]:::backend
            UtilsBE["Utilities"]:::backend
            LoggerUtil["Logging Utility"]:::backend
            JudgeEngine["Code Judge Engine"]:::backend
            FileStorage["File Storage Volume"]:::datastore
            DockerfileBE["Dockerfile"]:::backend
        end

        %% Database
        DB["PostgreSQL"]:::datastore
        InitSQL["init.sql"]:::datastore

        %% Monitoring
        Prometheus["Prometheus (:9090)"]:::monitoring
        PromConfig["prometheus.yml"]:::monitoring
    end

    %% Flows
    Browser -->|"HTTP/HTTPS"| ReactSPA
    ReactSPA -->|"REST API (JSON over HTTP)"| GoAPI
    GoAPI -->|"SQL Queries"| DB
    GoAPI -->|"spawn subprocess / pipes I/O"| JudgeEngine
    JudgeEngine -->|"reads/writes"| FileStorage
    GoAPI -->|"upload/download files"| FileStorage
    GoAPI -->|"/metrics"| Prometheus
    Prometheus -->|"scrape /metrics"| GoAPI

    %% Click Events
    click ComposeSvc "https://github.com/u0nkis/assignhub/blob/main/docker-compose.yaml"
    click ReactSPA "https://github.com/u0nkis/assignhub/tree/main/frontend/"
    click Entry "https://github.com/u0nkis/assignhub/blob/main/frontend/src/index.jsx"
    click APIFE "https://github.com/u0nkis/assignhub/blob/main/frontend/src/api/api.js"
    click AssignComp "https://github.com/u0nkis/assignhub/tree/main/frontend/src/components/Assignments/"
    click AuthComp "https://github.com/u0nkis/assignhub/tree/main/frontend/src/components/Auth/"
    click CodeEditor "https://github.com/u0nkis/assignhub/blob/main/frontend/src/components/Code/CodeEditor.jsx"
    click Layout "https://github.com/u0nkis/assignhub/blob/main/frontend/src/components/Layout/MainLayout.jsx"
    click Pages "https://github.com/u0nkis/assignhub/tree/main/frontend/src/pages/"
    click UtilsFE "https://github.com/u0nkis/assignhub/tree/main/frontend/src/utils/"
    click TailwindCfg "https://github.com/u0nkis/assignhub/blob/main/frontend/tailwind.config.js"
    click GoAPI "https://github.com/u0nkis/assignhub/tree/main/backend/"
    click Main "https://github.com/u0nkis/assignhub/blob/main/backend/main.go"
    click ConfigLoader "https://github.com/u0nkis/assignhub/blob/main/backend/config/config.go"
    click DBAccess "https://github.com/u0nkis/assignhub/blob/main/backend/db/db.go"
    click ModelsBE "https://github.com/u0nkis/assignhub/tree/main/backend/models/"
    click AssignmentHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/assignment.go"
    click AuthHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/auth.go"
    click CodeHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/code.go"
    click FileHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/file.go"
    click JudgeHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/judge.go"
    click SubmissionHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/submission.go"
    click UserHandler "https://github.com/u0nkis/assignhub/blob/main/backend/handlers/user.go"
    click Cors "https://github.com/u0nkis/assignhub/blob/main/backend/middleware/cors.go"
    click AuthMid "https://github.com/u0nkis/assignhub/blob/main/backend/middleware/auth.go"
    click Rate "https://github.com/u0nkis/assignhub/blob/main/backend/middleware/rate_limit.go"
    click Security "https://github.com/u0nkis/assignhub/blob/main/backend/middleware/security.go"
    click MetricsMid "https://github.com/u0nkis/assignhub/blob/main/backend/middleware/metrics.go"
    click LoggerMid "https://github.com/u0nkis/assignhub/blob/main/backend/middleware/logger.go"
    click LoggerUtil "https://github.com/u0nkis/assignhub/blob/main/backend/logger/logger.go"
    click UtilsBE "https://github.com/u0nkis/assignhub/blob/main/backend/utils/utils.go"
    click DockerfileBE "https://github.com/u0nkis/assignhub/tree/main/backend/Dockerfile"
    click DB "https://github.com/u0nkis/assignhub/blob/main/init.sql"
    click InitSQL "https://github.com/u0nkis/assignhub/blob/main/init.sql"
    click Prometheus "https://github.com/u0nkis/assignhub/blob/main/prometheus/prometheus.yml"
    click PromConfig "https://github.com/u0nkis/assignhub/blob/main/prometheus/prometheus.yml"

    %% Styles
    classDef client fill:#B3E5FC,stroke:#0277BD,color:#000
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,color:#000
    classDef backend fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef datastore fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef monitoring fill:#E1BEE7,stroke:#6A1B9A,color:#000
    classDef orchestration fill:#CFD8DC,stroke:#455A64,color:#000
```
