# ringecosystem/degov architecture

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

- Interactive diagram: https://gitdiagram.com/ringecosystem/degov
- Repository: https://github.com/ringecosystem/degov

## Overview

##### Main Components
- Smart Contracts Module:
- Located in the “contracts” directory.
- Contains Solidity smart contracts built on the OpenZeppelin Governor framework.
- Includes supporting files like foundry.toml, contracts/src, remappings.txt, and Makefile for building and deploying contracts.
- Indexer Service:
- Found under “packages/indexer.”
- Handles blockchain event listening, data extraction, and populates the off-chain database.
- Contains source code (src directory) for ABI handling, event processing (e.g., src/handler, src/processor.ts), database migrations (db/migrations), and GraphQL schema (schema.graphql).
- Includes various Dockerfiles and deployment scripts to run the indexer.
- Web Frontend:
- Located in “packages/web.”
- A Next.js application that provides the user interface for interacting with the DAO.
- Contains API routes, components, pages, and configurations (next.config.ts, tailwind.config.ts).
- Uses GraphQL services (in src/services/graphql) to query data processed by the indexer and stored in the database.
- Ancillary Elements:
- Docker & Deployment: Dockerfiles and docker-compose files (e.g., docker-compose.yml, files under the “docker/” directory) indicate containerized services which include the indexer and web app.
- Configuration and Initialization: Several init-scripts (init-scripts/postgres/init.sql) and configuration files (pnpm-workspace.yaml, package.json) are supplied for bootstrapping the system.
- CI/CD Pipeline: GitHub workflow files under “.github/workflows/” for testing, deploying in different environments (dev, staging, production), and releasing the code.

##### Relationships and Interactions
- The Smart Contracts on the Ethereum blockchain serve as the core governance engine executing proposals, votes, and state changes.
- The Indexer Service monitors on-chain events from these contracts, parses event data via ABI definitions (both in “contracts” and “packages/indexer/abi”), processes and stores this information in a database (migrations present in indexer’s db directory), and exposes a GraphQL API.
- The Web Frontend communicates with the Indexer’s GraphQL API to display real-time on-chain data, allows users to interact with proposals, vote, and handles authentication (evidenced by auth API endpoints in packages/web/src/app/api).
- Docker orchestration ensures that these services (contracts, indexer, web app) run reliably across different environments.

##### Architectural Patterns & Design Principles
- Microservices / Modular Structure: Separation into distinct services (contracts, indexer, web).
- API-Driven Communication: The Web Frontend interacts with the Indexer through a GraphQL API.
- Containerization & Orchestration: Use of Dockerfiles in “docker/” and docker-compose for service deployment.
- Event-Driven Processing: The Indexer subscribes to blockchain events and executes the necessary processing routines.

##### Elements
- Major component (Contracts, Indexer, Web Frontend, Database, CI/CD Pipeline, Docker Containers).
▪ From blockchain events to the indexer.
▪ From the indexer to the database.
▪ From the frontend to the backend (GraphQL API).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Blockchain Layer
    subgraph "Blockchain Layer"
        SC["DeGov Smart Contracts (OpenZeppelin Governor)"]:::blockchain
    end

    %% Data Processing Layer
    subgraph "Data Processing Layer"
        Indexer["Indexer Service (Event Processor/GraphQL API)"]:::backend
        DB["Database"]:::database
    end

    %% User Interface Layer
    subgraph "User Interface Layer"
        Web["Web Frontend (Next.js UI)"]:::frontend
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        Docker["Docker Orchestration"]:::infra
        Config["Configuration & Initialization"]:::infra
        CI_CD["CI/CD Pipeline"]:::infra
    end

    %% Data Flow Connections
    SC -->|"event_flow"| Indexer
    Indexer -->|"persist"| DB
    Web -->|"GraphQL_API"| Indexer

    %% Infrastructure Connections
    Docker -->|"deploys"| SC
    Docker -->|"deploys"| Indexer
    Docker -->|"deploys"| Web
    CI_CD -->|"triggers_deploy"| Docker
    Config -->|"bootstraps"| SC
    Config -->|"bootstraps"| Indexer
    Config -->|"bootstraps"| Web

    %% Click Events
    click SC "https://github.com/ringecosystem/degov/tree/main/contracts/"
    click Indexer "https://github.com/ringecosystem/degov/tree/main/packages/indexer/"
    click Web "https://github.com/ringecosystem/degov/tree/main/packages/web/"
    click Docker "https://github.com/ringecosystem/degov/tree/main/docker/"
    click Config "https://github.com/ringecosystem/degov/blob/main/init-scripts/postgres/init.sql"
    click CI_CD "https://github.com/ringecosystem/degov/tree/main/.github/workflows/"

    %% Classes / Styling
    classDef blockchain fill:#fdd835,stroke:#333,stroke-width:2px;
    classDef backend fill:#64b5f6,stroke:#333,stroke-width:2px;
    classDef frontend fill:#81c784,stroke:#333,stroke-width:2px;
    classDef database fill:#e57373,stroke:#333,stroke-width:2px;
    classDef infra fill:#ba68c8,stroke:#333,stroke-width:2px;
```
