# makhlouf1102/lets-go architecture

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

- Interactive diagram: https://gitdiagram.com/makhlouf1102/lets-go
- Repository: https://github.com/makhlouf1102/lets-go

## Overview

##### Project Type & Purpose
- The project is a full-stack web application built in Go that appears to be aimed at providing an online problem-solving or coding challenge service (inspired by LeetCode).
- Its purpose is indicated by the README (“I am trash at leetcode so I made leetcode ...”), combined with the presence of code samples in multiple languages, problem and authentication handlers, and the integration with Docker for language-specific containers.

##### Analyzing the File Structure
- Top-level files like main.go show the Go application’s entry point.
- Directories such as “handlers” (with subdirectories for auth and problem) indicate the routing/controllers (or MVC controllers) that process HTTP requests.
- The “models” directory contains definitions for entities such as user, problem, role, and language; this forms the data layer.
- “libs” contains various supporting libraries including bcrypt for authentication, token handling, error handling, Docker client utilities, etc.
- “middlewares” (auth, logger, roleGuard) point to the cross-cutting concerns which intercept and manage requests.
- The “views” directory (with HTML templates) and “static” directory (with JavaScript files) establish a presentation layer.
- The “database” folder contains SQL scripts and a database file indicating the data persistence setup.
- “docker” directories include Dockerfiles for various language environments and shared resources, which suggest support for containerized execution or testing.
- Additional scripts (run.sh, test.sh, test-with-docker.sh) and CI/CD configurations (.github/workflows) provide operational context on running tests, building, and deploying.

##### Elements
a. Main Components:
– Client / Presentation Layer:
- Views (HTML templates in “views/templates”)
- Static assets (JavaScript files in “static”)
– Application Server:
- Entry point (main.go)
- HTTP routing and controllers (handlers for auth and problem)
- Middlewares (auth, logger, role guard)
– Business Logic & Services:
- Models (user, problem, role, language, user_role)
- Supporting libraries for common functions, error handling, token processing, and environment configuration
– Container Management:
- Docker-related libraries (libs/dockerClient, libs/dockerController) for container orchestration—likely to run code in isolated environments.
- Data Persistence:
– Database layer (SQLite file “database-test.db”, build and production SQL scripts)
- Code Samples / Language Support:
– Code sample directories to hold example problem implementations for languages like Go, JavaScript, and Python.
– DevOps & CI/CD:
– Docker files (in “docker”) and GitHub workflows (CI configuration) for automated builds and testing.

b. Relationships & Interactions:
- The client layer sends HTTP requests to endpoints managed by the handlers.
- Handlers invoke business logic by interacting with models and libraries.
- Middleware intercepts requests to perform authentication, logging, and role-based access.
- The application interacts with the database via models (possibly using SQL scripts for initialization and testing).
- For code execution/sandboxing, parts of the system use Docker libraries to manage containerized language runtimes.
- Code samples show integration/testing examples across different languages.

c. Architectural Patterns & Design Principles:
- Layered Architecture: Separation of presentation, application, and data layers is evident.
- MVC / Handler-based Pattern: Clear division between routes/controllers (handlers) and models.
- Modular Design: Libraries (libs) and middlewares are split into functional areas (authentication, token processing, logging, Docker operations, etc.).

d. Relevant Technologies and Frameworks:
- Go (Golang) as the primary language.
- Docker for containerized execution (managed through custom DockerClient and DockerController libraries).
- Likely an SQLite database (given the test.db file) or similar SQL-based persistence.
- Authentication and password encryption via bcrypt.
- HTML templates and JavaScript for view rendering.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client / Presentation Layer
    subgraph "Client / Presentation Layer"
        CT["HTML Templates"]:::client
        SA["Static Assets"]:::client
    end

    %% Application Server
    subgraph "Application Server"
        MG["main.go (Entry Point)"]:::server
        subgraph "Middlewares"
            AMW["Auth Middleware"]:::middleware
            LMW["Logging Middleware"]:::middleware
            RGB["Role Guard Middleware"]:::middleware
        end
        subgraph "Controllers"
            AH["Auth Handler"]:::controller
            PH["Problem Handler"]:::controller
        end
    end

    %% Business Logic & Models
    subgraph "Business Logic & Models"
        DM["Data Models"]:::models
    end

    %% Supporting Libraries
    subgraph "Supporting Libraries"
        BC["Bcrypt Library"]:::lib
        EH["Error Handling Library"]:::lib
        TPL["Token Processing Library"]:::lib
        CF["Common Functions Library"]:::lib
    end

    %% Docker Container Management
    subgraph "Docker Container Management"
        DC["Docker Controller"]:::docker
        DCL["Docker Client"]:::docker
    end

    %% Data Persistence
    subgraph "Data Persistence"
        DB["Database (SQLite)"]:::db
        SQLS["SQL Build Scripts"]:::db
    end

    %% Code Samples
    subgraph "Code Samples"
        CS["Code Samples"]:::code
    end

    %% DevOps & CI/CD
    subgraph "DevOps & CI/CD"
        DCFG["Docker Configurations"]:::devops
        GHW["GitHub Workflows"]:::devops
    end

    %% Connections between layers
    CT --> MG
    SA --> MG

    MG --> AMW
    MG --> LMW
    MG --> RGB

    AMW --> AH
    LMW --> AH
    RGB --> AH

    AMW --> PH
    LMW --> PH
    RGB --> PH

    AH --> DM
    PH --> DM

    AH --> TPL
    AH --> BC
    PH --> EH
    PH --> CF
    AH --> EH
    AH --> CF

    DM --> DB
    DM --> SQLS

    AH --> DC
    PH --> DC
    DC --> DCL

    AH --> CS
    PH --> CS

    DCFG --- MG
    GHW --- MG

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef server fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef controller fill:#87CEEB,stroke:#000,stroke-width:2px;
    classDef middleware fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef models fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef lib fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef docker fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef db fill:#F08080,stroke:#000,stroke-width:2px;
    classDef devops fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef code fill:#E6E6FA,stroke:#000,stroke-width:2px;

    %% Click Events
    click CT "https://github.com/makhlouf1102/lets-go/tree/main/views/templates"
    click SA "https://github.com/makhlouf1102/lets-go/tree/main/static"
    click MG "https://github.com/makhlouf1102/lets-go/blob/main/main.go"
    click AH "https://github.com/makhlouf1102/lets-go/blob/main/handlers/auth/authHandler.go"
    click PH "https://github.com/makhlouf1102/lets-go/blob/main/handlers/problem/problem.go"
    click AMW "https://github.com/makhlouf1102/lets-go/blob/main/middlewares/auth/auth.go"
    click LMW "https://github.com/makhlouf1102/lets-go/blob/main/middlewares/logger/logger.go"
    click RGB "https://github.com/makhlouf1102/lets-go/blob/main/middlewares/roleGuard/adminGuard.go"
    click DM "https://github.com/makhlouf1102/lets-go/tree/main/models"
    click BC "https://github.com/makhlouf1102/lets-go/blob/main/libs/bcrypt/bcrypt.go"
    click EH "https://github.com/makhlouf1102/lets-go/blob/main/libs/commonErrors/commonErrors.go"
    click TPL "https://github.com/makhlouf1102/lets-go/blob/main/libs/token/token.go"
    click CF "https://github.com/makhlouf1102/lets-go/blob/main/libs/commonFunctions/commonFunctions.go"
    click DCL "https://github.com/makhlouf1102/lets-go/tree/main/libs/dockerClient/"
    click DC "https://github.com/makhlouf1102/lets-go/blob/main/libs/dockerController/dockerController.go"
    click DB "https://github.com/makhlouf1102/lets-go/blob/main/database/database-test.db"
    click SQLS "https://github.com/makhlouf1102/lets-go/blob/main/database/scripts/db_build.sql"
    click CS "https://github.com/makhlouf1102/lets-go/tree/main/code-samples"
    click DCFG "https://github.com/makhlouf1102/lets-go/tree/main/docker/"
    click GHW "https://github.com/makhlouf1102/lets-go/tree/main/.github/workflows"
```
