# uniswap/v2-core architecture

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

- Interactive diagram: https://gitdiagram.com/uniswap/v2-core
- Repository: https://github.com/uniswap/v2-core

## Overview

##### Main Components
- Smart Contracts – Represented by the “contracts” directory, which is subdivided into:
- Core Contracts (likely representing key components such as the Uniswap V2 Factory, Pair, and ERC20 token logic).
- Interfaces – Defining the contracts’ external APIs and expected behaviors.
- Libraries – Utility code or shared logic used by the core contracts.
- Test-specific contracts in “contracts/test” if applicable.
- Testing Infrastructure – Seen in the “test” folder that contains TypeScript test files (e.g., “UniswapV2ERC20.spec.ts”, “UniswapV2Factory.spec.ts”, “UniswapV2Pair.spec.ts”) and shared test utilities.
- Development and Build Tools – Illustrated by configuration files such as package.json, tsconfig.json, and other artifacts (e.g., .github workflows for CI, .prettierrc, .gitignore) that govern the build and deployment environment.

##### Relationships and Interactions
- Core Smart Contracts interact with each other: for example, the Factory contract is responsible for creating and managing Pair contracts. The Pair contracts, in turn, handle liquidity pools and token swaps.
- The Interfaces define how external components or other smart contracts communicate with these core contracts.
- Libraries provide supporting functionality to the smart contracts, ensuring code reuse, consistency, and reliability.
- Test files simulate interactions with the smart contracts and validate their behavior. There’s an interaction flow from the test layer (written in TypeScript) to the compiled Solidity contracts.
- The CI/CD pipelines (see .github/workflows) orchestrate tests and builds to ensure the integrity of the codebase.

##### Architectural Patterns and Design Principles
- Modularity – The smart contracts are divided into separate directories for contracts, interfaces, and libraries, indicating clean separation of concerns.
- Test-Driven Development – The dedicated “test” directory implies a design where unit and integration testing of smart contracts is a primary concern.
- Configuration as Code – With YAML files for workflows, the project uses automated CI practices.

##### Relevant Technologies, Frameworks, and Tools
- Solidity – The primary language for writing smart contracts.
- Node.js and Yarn – For managing dependencies, compiling contracts, and running tests.
- TypeScript and Mocha (as indicated by .mocharc.json) – For writing and executing tests.
- GitHub Actions – For continuous integration.
- Uniswap V2 Protocol-specific design – For aspects like the Factory, Pair contracts, and token standards.

##### Summary
- Smart Contract Layer: Contracts, Interfaces, Libraries.
- Testing & Development Layer: Test scripts, CI configurations.
- Next, detail the internal interactions among smart contracts (Factory, Pair, etc.) and indicate how tests validate these interactions.
- Finally, include peripheral components like GitHub Actions and build tools which automate the testing and deployment workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Smart Contract Layer
    subgraph "Smart Contract Layer"
        CCS["Core Smart Contracts"]:::contract
        UFactory["UniswapV2Factory"]:::contract
        UPair["UniswapV2Pair"]:::contract
        ERC20["ERC20 Logic"]:::contract
        Interfaces["Interfaces"]:::interface
        Libraries["Libraries"]:::library
        TestSC["Test-Specific Contracts"]:::testsc
    end

    %% Testing & Development Layer
    subgraph "Testing & Development Layer"
        BuildTools["Build & Config Tools"]:::build
        CI["CI/CD Pipeline"]:::ci
        TestSuite["Test Suite (TypeScript)"]:::tests
    end

    %% Relationships within Smart Contract Layer
    CCS -->|"contains"| UFactory
    CCS -->|"contains"| UPair
    CCS -->|"contains"| ERC20
    UFactory -->|"creates"| UPair
    UPair -->|"interactsWith"| ERC20
    CCS -->|"defines"| Interfaces
    CCS -->|"utilizes"| Libraries
    CCS -->|"includes"| TestSC

    %% Relationships between Layers
    BuildTools -->|"compiles"| CCS
    CI -->|"triggers"| BuildTools
    CI -->|"runs"| TestSuite
    TestSuite -->|"validates"| UFactory
    TestSuite -->|"validates"| UPair
    TestSuite -->|"validates"| ERC20

    %% Click Events
    click CCS "https://github.com/uniswap/v2-core/tree/master/contracts/"
    click Interfaces "https://github.com/uniswap/v2-core/tree/master/contracts/interfaces"
    click Libraries "https://github.com/uniswap/v2-core/tree/master/contracts/libraries"
    click TestSC "https://github.com/uniswap/v2-core/tree/master/contracts/test"
    click TestSuite "https://github.com/uniswap/v2-core/tree/master/test/"
    click CI "https://github.com/uniswap/v2-core/tree/master/.github/workflows"
    click BuildTools "https://github.com/uniswap/v2-core/tree/master/.github/workflows"

    %% Styles
    classDef contract fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef interface fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef library fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef testsc fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef tests fill:#DCEDC8,stroke:#333,stroke-width:2px;
    classDef ci fill:#FFF9C4,stroke:#333,stroke-width:2px;
    classDef build fill:#D1C4E9,stroke:#333,stroke-width:2px;
```
