Aifei positions itself as the first framework designed specifically for AI coding. Hosted on GitHub at jfinal/aifei, it has garnered 51 stars and is written in Java. Traditional server frameworks emerged in an era of human-written code, carrying layers like Controller, Service, Dao, Repository, and Mapper that suit human organization but burden AI models with extra token consumption, context noise, and scattered attention. Aifei addresses this by pioneering the Just Service paradigm, which strips away those layers to focus solely on business logic in a single Service class. This reduces context length, boosts generation stability, and improves code quality when using large language models for development.
The framework's kernel spans just 3333 lines of code with no third-party dependencies, a result of 15 years of minimalism refined from the JFinal project. It targets AI-driven workflows where models generate code more efficiently without mapping across multiple architectural layers.
Core features
Aifei revolves around a few key elements drawn from its HIO structure—Handler, Input, and Output—which simplifies request processing into a predictable flow independent of Servlets. Users define these components themselves and can swap IO implementations as needed.
- Just Service paradigm: Developers write a single
@Path-annotated Service class per domain, handling queries, inserts, updates, and deletes directly. For example, a VipService might include anindexmethod for paginated queries usingVip.sql(sql, filter).paginate(pageNum, pageSize). - Centralized configuration: All settings live in a class implementing
AifeiConfig<In, Out>, covering logs, servers (like Undertow), dispatchers, handlers, routes, and plugins. This avoids scattered configs that confuse AI models. - Minimal cognitive load: No Render, Repository, or Mapper classes; business logic stands alone, leaving more context budget for actual functionality.
- Database integration: Inherits JFinal's API but shifts queries to chainable
sql(...)calls with parameters, plus options likeprintSql(true)for debugging. - Universal applicability: Not limited to web; works for any server-side needs, with web access via paths like
/vipmapping directly to methods.
These features aim to make AI code generation consistent and direct.
Getting it running
Aifei requires no complex build steps beyond standard Java setup, as it avoids external dependencies. Start by creating the core components shown in the README.
First, define a Service class. For a VIP management example:
@Path("/vip")
public class VipService {
// 查询、排序、分页
public Page<Vip> index(Map<?, ?> filter, int pageNum, int pageSize) {
String sql = "select * from vip #where(...) #and(...) ...";
return Vip.sql(sql, filter).paginate(pageNum, pageSize);
}
// 插入
public Out insert(Vip vip) {
vip.insert();
return Out.ok("插入成功");
}
// 修改
public Vip edit(int id) {
return Vip.findById(id);
}
// 更新
public Out update(Vip vip) {
vip.update();
return Out.ok("更新成功");
}
// 删除
public Out delete(int id) {
Vip.deleteById(id);
return Out.ok("删除成功");
}
}
Next, implement AifeiConfig. Load properties from app-config.txt (for JDBC URL, user, password), set up logging (e.g., Log4j2), server (UndertowServer with IoDispatcher), handlers, argument injection (like Account via LoginAccountArgument), routes (scan package with AuthInterceptor), and plugins (DruidSupplier for DB, AifeiDbPlugin with ModelSet):
public class AppConfig implements AifeiConfig<In, Out> {
Prop p;
public void config(Settings<In, Out> settings) {
p = PropKit.use("app-config.txt");
settings.setLogFactory(new Log4j2LogFactory());
settings.setServer(new UndertowServer(), new IoDispatcher());
settings.addHandler(new IoHandler());
settings.configArgument(kit -> {
kit.register(Account.class, LoginAccountArgument.class);
});
}
public void config(Routes routes) {
routes.scan("cn.aifei.vip", new AuthInterceptor());
}
public void config(Plugins plugins) {
DruidSupplier druidSupplier = new DruidSupplier(p.get("jdbcUrl"), p.get("user"), p.get("password"));
AifeiDbPlugin dbPlugin = new AifeiDbPlugin("main", druidSupplier);
dbPlugin.addModelSet(new ModelSet());
dbPlugin.config(c -> c.setPrintSql(true));
plugins.add(dbPlugin);
}
}
Launch via a main method:
public class AifeiVip {
public static void main(String[] args) {
Aifei.start(new AppConfig(), args);
}
}
Compile and run this Java project. Access endpoints like /vip with query params (e.g., ?id=1) to invoke methods directly.
Real-world use cases
Aifei fits scenarios where AI tools generate most server code, such as prototyping subscription services (VIP example), user management (/user path for getById), or any CRUD-heavy backend. Once the config and base models are set, an LLM can output a complete Service class without boilerplate. Its database layer supports familiar operations like findById, insert, update, and deleteById on model classes (e.g., Vip, User), with SQL templating for filters and pagination.
Teams transitioning from JFinal will recognize the API familiarity but appreciate the AI optimizations. If you're feeding project prompts to models repeatedly, the single-layer structure cuts noise—models avoid inventing missing Controllers or Mappers.
How it compares
Aifei diverges sharply from frameworks like Spring Boot or JFinal's full stack, which retain human-centric layers that inflate prompts. Spring, for instance, demands @RestController, @Service, @Repository, and response handling, diluting AI focus on business rules. Aifei claims to halve token use by converging everything to Service methods.
At 3333 lines, it's lighter than JFinal (its predecessor) and far slimmer than dependency-heavy alternatives. No Maven/Gradle artifacts are specified yet—it's a raw Java library—so integration means direct inclusion. For non-Java stacks, Node.js frameworks like Express or Fastify offer similar minimalism but lack Aifei's AI-specific tuning.
Who this is not for
Early adopters of AI coding experiments will find Aifei direct for Java backends, especially CRUD apps. Larger enterprises needing battle-tested ecosystems or non-Java languages may prefer established options. Source code and full docs live at https://github.com/jfinal/aifei.
Comments