# 整体结构

Hyperledger Fabric 从 1.0.0 开始，架构已经解耦为三个主要部分：

* fabric-peer：主要起到 peer 作用，包括 endorser、committer 两种角色；
* fabric-ca：即原先的 membersrvc，独立成一个新的项目。
* fabric-order：起到 order 作用。

其中，fabric-peer 和 fabric-order 代码暂时都在 fabric 项目中，未来可能进一步拆分。

## 核心代码

fabric 项目中主要包括代码、工具、脚本等部分，核心源代码目前（v2.5.2）为 797 个文件，157K 行。

```sh
$ cd fabric
$ find bccsp ccaas_builder cmd common core discovery gossip internal msp orderer pkg protoutil tools \
    -not -path "*/vendor/*" \
    -not -path "*mock*" \
    -name "*.go"  \
    -not -name "*_test.go" \
    -not -name "test_*.go" \
    | wc -l

     797
$ find bccsp ccaas_builder cmd common core discovery gossip internal msp orderer pkg protoutil tools \
    -not -path "*/vendor/*" \
    -not -path "*mock*" \
    -name "*.go"  \
    -not -name "*_test.go" \
    -not -name "test_*.go" \
    | xargs cat | wc -l

156982
```

### 源代码

实现 fabric 功能的核心代码，包括：

* [bccsp](/hyperledger_code_fabric/bccsp.md) 包：实现对加解密算法和机制的支持。
* [common](/hyperledger_code_fabric/common.md) 包：一些通用的模块；
* [core](/hyperledger_code_fabric/core.md) 包：大部分核心实现代码都在本包下。其它包的代码封装上层接口，最终调用本包内代码；
* [events](https://github.com/yeasy/hyperledger_code_fabric/blob/master/events/README.md) 包：支持 event 框架；
* [examples](/hyperledger_code_fabric/examples.md) 包：包括一些示例的 chaincode 代码；
* [gossip](/hyperledger_code_fabric/gossip.md) 包：实现 gossip 协议；
* [msp](/hyperledger_code_fabric/msp.md) 包：Member Service Provider 包；
* [order](https://github.com/yeasy/hyperledger_code_fabric/blob/master/order/README.md) 包：order 服务相关的入口和框架代码；
* [peer](/hyperledger_code_fabric/peer.md) 包：peer 的入口和框架代码；
* [protos](/hyperledger_code_fabric/protos.md) 包：包括各种协议和消息的 protobuf 定义文件和生成的 go 文件。

### 源码相关工具

一些辅助代码包，包括：

* [bddtests](https://github.com/yeasy/hyperledger_code_fabric/blob/master/bddtests/README.md)：测试包，含有大量 bdd 测试用例；
* [gotools](/hyperledger_code_fabric/gotools.md)：golang 开发相关工具安装；
* [vendor](https://github.com/yeasy/hyperledger_code_fabric/blob/master/vendor/README.md) 包：管理依赖；

### 安装部署

包括：

* [busybox](https://github.com/yeasy/hyperledger_code_fabric/blob/master/busybox/README.md)：busybox 环境，精简的 linux；
* [devenv](https://github.com/yeasy/hyperledger_code_fabric/blob/master/devenv/README.md)：配置开发环境；
* [images](/hyperledger_code_fabric/images.md)：镜像生成模板等。
* [scripts](/hyperledger_code_fabric/scripts.md)：各种安装配置脚本；

### 其它工具

其他工具，包括：

* [docs](/hyperledger_code_fabric/docs.md)：文档，大部分文档都可以 [在线查阅](http://hyperledger-fabric.readthedocs.io)；

## 配置、脚本和文档

除了些目录外，还包括一些说明文档、安装需求说明、License 信息文件等。

### Docker 相关文件

* .baseimage-release：生成 baseimage 时候的版本号。
* .dockerignore：生成 Docker 镜像时忽略一些目录，包括 .git 目录。

### git 相关文件

* .gitattributes：git 代码管理时候的属性文件，带有不同类型文件中换行符的规则，默认都为 linux 格式，即 。
* .gitignore：git 代码管理时候忽略的文件和目录，包括 build 和 bin 等中间生成路径。
* .gitreview：使用 git review 时候的配置，带有项目的仓库地址信息。
* README.md：项目的说明文件，包括一些有用的链接等。

### travis 相关文件

* .travis.yml：travis 配置文件，目前是使用 golang 1.6 编辑，运行了三种测试：unit-test、behave、node-sdk-unit-tests。

### 其它

* LICENSE：Apache 2 许可文件。
* docker-env.mk：被 Makefile 引用，生成 Docker 镜像时的环节变量。
* Makefile：执行测试、格式检查、安装依赖、生成镜像等操作。
* mkdocs.yml：生成 <http://hyperledger-fabric.readthedocs.io> 在线文档的配置文件。
* TravisCI\_Readme.md


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/hyperledger_code_fabric/overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
