# uniswap/v3-core architecture

> Architecture diagram of the GitHub repository uniswap/v3-core, 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/uniswap/v3-core
- Repository: https://github.com/uniswap/v3-core

## Overview

##### Project Type and Purpose
- This repository implements the smart contracts that power Uniswap V3, which is a decentralized trading protocol. The primary purpose is to provide on-chain liquidity and automated market making functionalities.
- The README emphasizes deployment instructions, importing interfaces, and integration with local testnets using the provided bytecode. Thus, the focus is on blockchain smart contract functionality rather than a typical full-stack application.

##### File Structure
- Notice the separation between various directories:
- contracts/ – contains the Solidity source files. Within this, subdirectories like interfaces/ (for standardized smart contract interfaces), libraries/ (for reusable code), and test (for testing smart contract logic) indicate a modular design.
- audits/ – contains multiple audit reports and configuration files for critical security verifications (e.g., cryptic configuration files under the “crytic” folder).
- test/ – TypeScript files that use Hardhat (as indicated by hardhat.config.ts), indicating robust testing of contract behavior including gas consumption, edge cases, and expected operations.
- Configuration and build scripts are present at the top-level (prettier config, .yarnrc, tsconfig.json), while GitHub Actions workflows support linting, tests, fuzz testing, and MythX analysis. This reflects an emphasis on continuous integration, automated testing, and security.

##### Architectural Components
a. Main Components:
- Smart Contracts Layer:
- Factory Contract (UniswapV3Factory) – Responsible for creating new liquidity pools.
- Pool Contracts (e.g., UniswapV3Pool) – The core components that implement market making, swaps, and liquidity management.
- Interfaces – Used by other contracts including external ones, ensuring interoperability.
- Libraries – Reusable algorithms for calculations (BitMath, LiquidityMath, etc.).
- Testing Framework:
- Hardhat configuration and tests written in TypeScript for simulating and verifying smart contract behavior.
- Deployment & CI/CD Infrastructure:
- GitHub workflows for linting, testing, fuzzing, and myth analysis.
- Audit reports (found under audits/) that add a layer of security verification.

b. Relationships and Interactions:
- The Factory contract is deployed first and is used to instantiate new Pool contracts.
- The Pool contracts interact with the associated Interfaces and Libraries to perform operations like swapping and liquidity management.
- Test components simulate the interactions and validate the logic – representing the code’s robustness.
- External tools and CI pipelines run continuous integration and security checks, ensuring the deployed code meets standards.

c. Architectural Patterns and Design Principles:
- Modular design: Separating interfaces, core contracts, and libraries for reusability and clarity.
- Security-oriented approach: With multiple audit directories and CI configurations for fuzz testing, MythX integration, etc.
- Decentralized architecture: Emphasizing smart contracts that operate within a trustless blockchain environment.

d. Relevant Technologies, Frameworks, or Libraries:
- Solidity for smart contracts.
- Hardhat (indicated by hardhat.config.ts) for contract development and testing.
- TypeScript for tests.
- GitHub Actions for CI/CD.
- Dependency management via npm and Yarn using package.json and .yarnrc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Smart Contracts Layer
    subgraph "Smart Contracts Layer"
        FC["Factory Contract"]:::contract
        PC["Pool Contracts"]:::contract
        INT["Interfaces"]:::contract
        LIB["Libraries"]:::contract
    end

    %% Testing & Deployment Infrastructure
    subgraph "Testing & Deployment"
        HC["Hardhat Config"]:::testing
        TS["Test Suite"]:::testing
        CI["CI/CD & Security Testing"]:::ci
    end

    %% Audit and Security Reports
    subgraph "Auditing"
        AR["Audit Reports"]:::audit
    end

    %% Relationships
    FC -->|"creates"| PC
    PC -->|"uses"| INT
    PC -->|"uses"| LIB
    HC -->|"configures"| TS
    TS -->|"tests"| FC
    TS -->|"tests"| PC
    CI -->|"triggers"| HC
    CI -->|"triggers"| TS
    AR -->|"audits"| FC
    AR -->|"audits"| PC

    %% Click Events
    click FC "https://github.com/uniswap/v3-core/blob/main/test/UniswapV3Factory.spec.ts"
    click PC "https://github.com/uniswap/v3-core/blob/main/test/UniswapV3Pool.spec.ts"
    click INT "https://github.com/uniswap/v3-core/tree/main/contracts/interfaces"
    click LIB "https://github.com/uniswap/v3-core/tree/main/contracts/libraries"
    click HC "https://github.com/uniswap/v3-core/blob/main/hardhat.config.ts"
    click TS "https://github.com/uniswap/v3-core/tree/main/test"
    click CI "https://github.com/uniswap/v3-core/tree/main/.github/workflows"
    click AR "https://github.com/uniswap/v3-core/tree/main/audits"

    %% Styles
    classDef contract fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef testing fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef ci fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef audit fill:#FFA07A,stroke:#000,stroke-width:2px;
```
