# sunweb3sec/defihacklabs architecture

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

- Interactive diagram: https://gitdiagram.com/sunweb3sec/defihacklabs
- Repository: https://github.com/sunweb3sec/defihacklabs

## Overview

##### Main Components
- Educational (Academy) Module:
– Directory: “academy”
– Contains lessons and tutorials under multiple sections (e.g., “move”, “onchain_debug”, “solidity”, “user_awareness”)
– Supports multiple languages (en, es, ko, vi, etc.) for each lesson.
– These lessons function as a self-contained Web3 cybersecurity academy.

- Exploit Simulation/Test Module:
– Directory: “src/test” (organized under date-based folders) where Foundry test contracts simulate actual DeFi attack scenarios.
– The “script” directory can also be seen as supporting automation or auxiliary deployment tasks.

- Historical Data Archive:
– Directory: “past” (with subdirectories per year) that compiles previous hacks or cleanup case studies in README files.

- Dependency and Library Management:
– Directory: “lib” (includes forge-std and possibly other libraries)
– Contains configuration artifacts like “foundry.toml”, “remappings.txt”, and formatter config “.prettierrc”

- CI/CD and Project Management:
– .github folder: Contains workflows (e.g., PRAutoTest.yml) and issue templates that integrate with automated testing and development guidelines.
– CONTRIBUTING.md and .gitmodules also contribute to project governance and submodule management.

##### Relationships and Interactions
- Foundry Testing Framework:
– Central to the project, it orchestrates the execution of smart contract tests (located in “src/test”) against vulnerabilities.

- Educational Content Integration:
– The “academy” provides contextual background on hacking techniques and security practices; it is logically separate but related to the test module.
– Indicate how lessons reference specific exploits that are demonstrated in the “src/test” section and sometimes in the “past” archive.

- Historical Archive:
– The “past” directory aggregates background case studies and serves as a knowledge base.
– Show connections from the “Academy” and “Exploit Module” to “Historical Archive” to indicate that the simulated exploits are based on actual incidents.

- Continuous Integration (CI) & Version Control:
– Illustrate the role of the .github workflows in triggering tests and reporting gas usage, ensuring quality and automation.
– Integrate “CONTRIBUTING.md” and other project governance files as external influences on development practices.

##### Architectural Patterns and Technologies
- Modular Design:
– Separate the project into clearly defined modules (educational, test harness, archive), each represented by its own block.

- Multi-language & Multi-format Support:

- Testing and Gas Reporting:
– Illustrate the integration of Foundry’s test command (including gas reports) which is central for simulating exploits.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configurations & Libraries
    subgraph "Libraries & Configurations"
        C("Libraries & Configurations"):::config
        L("Dependency: lib"):::configchild
        F("Config: foundry.toml"):::configchild
        R("Config: remappings.txt"):::configchild
        P("Config: .prettierrc"):::configchild
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI("CI/CD Pipeline"):::cicd
        G("Workflow: .github"):::cicdchild
        CP("Guidelines: CONTRIBUTING.md"):::cicdchild
        GM("Submodules: .gitmodules"):::cicdchild
    end

    %% Exploit Simulation / Test Harness
    subgraph "Exploit Simulation (Foundry Tests)"
        T("Exploit Simulation (Foundry Tests)"):::test
        S("Automation Scripts"):::test2
    end

    %% Academy (Educational Content)
    subgraph "Educational Module"
        A("Academy (Educational Content)"):::academic
    end

    %% Historical Archive
    subgraph "Historical Archive"
        H("Historical Archive"):::archive
    end

    %% Relationships
    C -->|"configures"| T
    CI -->|"triggers"| T
    T --> S
    A -->|"references"| T
    A -->|"cites"| H
    T -->|"based_on"| H

    %% Click Events for Component Mapping
    click A "https://github.com/sunweb3sec/defihacklabs/tree/main/academy"
    click T "https://github.com/sunweb3sec/defihacklabs/tree/main/src/test"
    click S "https://github.com/sunweb3sec/defihacklabs/tree/main/script"
    click L "https://github.com/sunweb3sec/defihacklabs/tree/main/lib"
    click F "https://github.com/sunweb3sec/defihacklabs/blob/main/foundry.toml"
    click R "https://github.com/sunweb3sec/defihacklabs/blob/main/remappings.txt"
    click P "https://github.com/sunweb3sec/defihacklabs/blob/main/.prettierrc"
    click G "https://github.com/sunweb3sec/defihacklabs/blob/main/.github"
    click CP "https://github.com/sunweb3sec/defihacklabs/blob/main/CONTRIBUTING.md"
    click GM "https://github.com/sunweb3sec/defihacklabs/blob/main/.gitmodules"
    
    %% Styles
    classDef academic fill:#B3E5FC,stroke:#01579B,stroke-width:2px;
    classDef test fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef archive fill:#FFE082,stroke:#FF6F00,stroke-width:2px;
    classDef config fill:#C5E1A5,stroke:#558B2F,stroke-width:2px;
    classDef configchild fill:#E6EE9C,stroke:#9E9D24,stroke-width:1px;
    classDef cicd fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef cicdchild fill:#F48FB1,stroke:#AD1457,stroke-width:1px;
    classDef test2 fill:#90CAF9,stroke:#1976D2,stroke-width:1px;
```
