# togettoyou/fabric-realty architecture

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

- Interactive diagram: https://gitdiagram.com/togettoyou/fabric-realty
- Repository: https://github.com/togettoyou/fabric-realty

## Overview

##### Project Overview
- This is a blockchain-based full-stack application designed for real estate registration and trading. It leverages Hyperledger Fabric to provide a distributed ledger system where three organizations (the Realty Agency, the Trading Platform, and the Bank) operate in a consortium network.
- The application has distinct layers: a blockchain network (with chaincode for business logic), a backend RESTful API server written in Go (using Gin) that interfaces with the blockchain, and a Vue-based frontend for user interaction.

##### Main Components
a. Blockchain / Network Layer:
- Hyperledger Fabric Network:
- Three organizations (identified as Org1: Realty Agency, Org2: Bank, and Org3: Trading Platform) each with their own set of peer nodes (e.g., peer0, peer1).
- Configuration files (from the network folder) which include crypto materials, configtx.yaml, docker-compose files, etc.
- Smart Contract (Chaincode) Layer:
- The chaincode component found in the “chaincode” directory. It encapsulates core functions for managing property and transaction data (e.g., property creation, transaction completion, queries).

b. Application Server (Backend) Layer:
- REST API server implemented in Go using Gin.
- API routing structure includes endpoints for:
- Realty Agency: create and query realty information.
- Trading Platform: initiate and query transactions.
- Bank: complete transactions and lookup details.
- This layer also integrates with Hyperledger Fabric via the fabric-gateway from the “pkg/fabric” code.
- The configuration management files (in “config”) support environment-specific settings (including Docker-based configurations).
- Docker-related files indicate container-based deployment.

c. Frontend (Web) Layer:
- Built using Vue.js with supporting TypeScript configuration.
- Provides independent user interfaces for each organization.
- Interacts with the backend API for operations such as realty creation, transaction initiation, and transaction completion.
- Files in “application/web” include configuration (Dockerfile, package.json, vite config) and the source code for views such as Bank.vue, RealtyAgency.vue, and TradingPlatform.vue.

d. Supporting Deployment & Configuration:
- Docker Compose files in both “application” and “network” directories serve to orchestrate multi-container deployments.
- Shell scripts (install.sh and uninstall.sh) for one-click deployment and teardown.

##### Relationships and Data Flow
- Backend’s internal call stack:
- API endpoint → internal service (e.g., bank_service, realty_agency_service, trading_platform_service) → fabric gateway calls → smart contract (chaincode) invocations.
- Demonstrate the blockchain network’s multi-organization structure and how each organization (with its peer nodes) interacts with the smart contract.

##### Architectural Patterns & Design Principles
- Clearly separate concerns: presentation (Vue frontend), application logic (Go REST API), and blockchain ledger (Hyperledger Fabric and chaincode).
- Use of microservice-style decomposition in the backend API (different service packages for the distinct business functions).
- Dependency injection and modular integration (with the fabric-gateway abstracting blockchain communication).
- Utilize Docker containers to encapsulate runtime environments, indicated by Dockerfiles and Docker Compose files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE["Frontend - Vue Application"]:::frontend
    end

    subgraph "Backend API Layer"
        APISRV["API Server (Go Gin)"]:::backend
        API_BANK["Bank API Endpoint"]:::backend
        API_REALTY["Realty Agency API Endpoint"]:::backend
        API_TP["Trading Platform API Endpoint"]:::backend
        FG["Fabric Gateway Integration"]:::backend
        BS_BANK["Bank Service"]:::backend
        BS_REALTY["Realty Agency Service"]:::backend
        BS_TP["Trading Platform Service"]:::backend
        BCFG["Backend Configuration Management"]:::backend
        DEPL["Deployment & Containerization"]:::deployment
        SDOCK["Server Dockerfile"]:::deployment
        WDOCK["Web Dockerfile"]:::deployment
    end

    subgraph "Blockchain Network Layer"
        BC_CONF["Blockchain Network Configuration"]:::blockchain
        CC["Smart Contract (Chaincode)"]:::blockchain
        ORG1["Org1: Realty Agency (peer0, peer1)"]:::blockchain
        ORG2["Org2: Bank (peer0, peer1)"]:::blockchain
        ORG3["Org3: Trading Platform (peer0, peer1)"]:::blockchain
    end

    FE -->|"calls"| APISRV
    APISRV -->|"routes"| API_BANK
    APISRV -->|"routes"| API_REALTY
    APISRV -->|"routes"| API_TP
    API_BANK -->|"calls"| BS_BANK
    API_REALTY -->|"calls"| BS_REALTY
    API_TP -->|"calls"| BS_TP
    BS_BANK -->|"invokes"| FG
    BS_REALTY -->|"invokes"| FG
    BS_TP -->|"invokes"| FG
    FG -->|"invokes"| CC
    CC -->|"operates on"| ORG1
    CC -->|"operates on"| ORG2
    CC -->|"operates on"| ORG3
    APISRV -->|"loads"| BCFG
    APISRV -->|"deployed with"| DEPL
    DEPL -->|"includes"| SDOCK
    DEPL -->|"includes"| WDOCK
    APISRV -.->|"uses"| BC_CONF
    CC -.->|"configured by"| BC_CONF

    click FE "https://github.com/togettoyou/fabric-realty/tree/main/application/web"
    click APISRV "https://github.com/togettoyou/fabric-realty/blob/main/application/server/main.go"
    click API_BANK "https://github.com/togettoyou/fabric-realty/blob/main/application/server/api/bank.go"
    click API_REALTY "https://github.com/togettoyou/fabric-realty/blob/main/application/server/api/realty_agency.go"
    click API_TP "https://github.com/togettoyou/fabric-realty/blob/main/application/server/api/trading_platform.go"
    click FG "https://github.com/togettoyou/fabric-realty/blob/main/application/server/pkg/fabric/fabric.go"
    click BS_BANK "https://github.com/togettoyou/fabric-realty/blob/main/application/server/service/bank_service.go"
    click BS_REALTY "https://github.com/togettoyou/fabric-realty/blob/main/application/server/service/realty_agency_service.go"
    click BS_TP "https://github.com/togettoyou/fabric-realty/blob/main/application/server/service/trading_platform_service.go"
    click BCFG "https://github.com/togettoyou/fabric-realty/blob/main/application/server/config/config.go"
    click SDOCK "https://github.com/togettoyou/fabric-realty/tree/main/application/server/Dockerfile"
    click WDOCK "https://github.com/togettoyou/fabric-realty/tree/main/application/web/Dockerfile"
    click DEPL "https://github.com/togettoyou/fabric-realty/blob/main/application/docker-compose.yml"
    click CC "https://github.com/togettoyou/fabric-realty/blob/main/chaincode/chaincode.go"
    click BC_CONF "https://github.com/togettoyou/fabric-realty/blob/main/network/configtx.yaml"

    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef deployment fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef blockchain fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
