Code Monkey home page Code Monkey logo

once's Introduction

Once是关注项目过程、轻量易用、模块化、模块拿来即用的后端架构。一人一天能产出20多个接口。

编写接口就像画流程图一样

Once架构是一套后端应用的顶层架构,架构本身只约束了工程结构和开发过程,对后端应用的基础技术无任何改造和深度封装。

Once架构关注的是开发效率和维护成本,保证业务开发人员以近似千人一面的方式完成业务功能的开发。

Once架构是具备成长性的,A项目积累下来的模块代码,可以直接使用在B项目中,实现项目复利。

虽然Once架构提倡代码生成,但是,在排查错误时,仍然建议从代码本身找出出错原因,再重新生成正确的代码。

基础技术

此架构是一种顶层架构,架构本身只约束了工程结构和开发过程,对基础技术无任何改造和深度封装。

架构中采用的基础技术如下:

  • 开发语言:Java(JDK8或以上)
  • 基础框架:SpringBoot 2.2.0.M5
  • 项目自动构建工具:Gradle 5.6
  • Tomcat版本:8.5以上

其中,由于Once架构只是一种规则,基础技术甚至是开发语言都是可以替换的,可联系官方打造个性化架构

前提知识

在使用Once架构前,请学习SpringBoot、Java程序、Http请求等相关知识。

Once架构只是一种规则,实际上还是一个SpringBoot工程,要想真正使用起来、或者排查一些错误,还是需要先学习这些知识。

设计**

Once架构的设计**可以直白地理解为:所有代码只写一次,如果不能,则用代码生成器生成它。另外,对于同样使用Once架构的两个项目,A项目积累下来的模块代码,可以直接使用在B项目中。

工作原理

从宏观上讲,后端应用程序是多个请求的集合。而对单个请求来讲,是多个步骤的集合。

以一个审核博客的接口为例,可以对其理解为:第一步“用户鉴权”、第二步“检查必要参数”、第三步“填充默认参数”、第四步“数据库操作”。

如果从“单个请求就是多个步骤的集合”出发的话,代码可以分成两层:

  • 业务代码:指定该业务请求的步骤,且指定每一步调用的模块,例如:第一步“调用xx模块”、第二步“调用yy模块”;
  • 模块代码:实现某种具体功能的代码块,例如用户鉴权模块、检查必要参数模块等。模块代码与业务功能无关,只关心被使用的场景。

这样的话,模块代码是可以只写一次的(所有接口都可以使用)。但是,业务代码部分仍然需要编写大量的代码,而这些代码其实是高度重复的。那么,如果加入“数据池”的话,则可以进一步简化业务代码。

业务代码每次调用模块时,都把“数据池”和模块参数传入模块中,模块代码根据模块参数实现逻辑,模块代码可直接对“数据池”进行处理(可以从“数据池”中获取或更新数据),当模块发生错误时,错误码会被存放到数据池中。模块处理完后,把数据池返回业务代码,业务代码判断是否需要截断下一步逻辑(数据池中是否有错误码)。工作原理如图所示。

经过以上规范化后,业务代码可以简化为json的表达形式,如代码所示。简化业务代码后,即可通过代码生成器把业务代码还原成Java代码。这样,即可减少重复代码的编写,又让业务代码更加清晰明了。

"接口列表"{
	"接口一": {
         "接口路径": "/xx/xx" ,
         "请求方式": "POST" ,
         "调用模块": [
				{
					"模块名":"检查必要参数",
					"模块参数":{            //模块代码会自动识别数据池中是否有以下字段
						"abc":"abs",   //abc字段为必填
						"bcd":"opt"    //bcd字段为选填
					}
				},
				{
					"模块名":"数据库操作",
					"模块参数":{
					     "control":"update",				        //更新操作
				             "query":"UPDATE t_blog SET state='pass' WHERE id='@id@'"	//sql语句,其中@id@会替换成数据池中的id的值
				}
		 ],
	},
	"接口二":{
		...
	}
}

once's People

Contributors

yiigaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.