🎯 Build Final FastKit Setup — Pluggable API Framework with Direct Routing, Utility Exports, and Zero Lock-In
#20 创建于 2025年6月28日
仓库指标
- 星标
- (1 个星标)
- PR 合并指标
- (PR 指标待抓取)
描述
📖 Description
This issue will establish the confirmed structure and design rules for FastKit — a modular, plug-and-play backend API system using TypeScript and Express.
Rather than registering routes or injecting everything inside a framework, developers will:
- ✅ Use fastKit.get(), post(), put(), delete(), use() directly
- ✅ Write API routes inside any file using FastKit's fluent syntax
- ✅ Import and use middleware, utils, services, and controllers anywhere
- ✅ Keep full control — no magic, no locked structure
- ✅ Use only what they need: one feature, or everything
This system is inspired by developer-first design, real-world needs, and clean code architecture.
🚀 Why It Matters
Benefit Explanation
- ✅ Custom Route Control You create your own files, use fastKit.get() as you want
- ✅ Independent Exports Use any controller, service, or utility without touching FastKit
- ✅ Zero Boilerplate No manual route registration or feature binding
- ✅ npm-Ready Build your own module, publish it, and reuse it
- ✅ Universal Usage Works for Express, Fastify, REST APIs, or monorepos
- ✅ Simple Learning Curve No decorators, no DI — just clean TypeScript and logic
🔧 Tasks
[x] Setup fastKit.ts (class with get/post/put/delete/use)
[x] Create server.ts (Express app with FastKit instance)
[x] Create config/fastkit.config.ts (global config: version, prefix, middlewares)
[x] Create features/ folder (Auth, Todo, Email, etc.)
[x] Create utils/ folder (SendResponse.ts, etc.)
[x] Create middlewares/ folder (verifyToken.ts, validateBody.ts, etc.)
[x] Export each feature independently: no need to bind to FastKit
[x] Allow user to use only what they want
[x] Support for file-based routing if needed (optional)
[x] Export everything via index.ts for plugin-friendly structure
📁 Final Folder Structure
src/
├── server.ts
├── fastkit.ts
├── config/
│ └── fastkit.config.ts
├── utils/
│ ├── SendResponse.ts
│ └── ErrorHandler.ts
├── middlewares/
│ ├── verifyToken.ts
│ ├── validateBody.ts
├── services/
│ └── email/
│ └── v1/
│ ├── Email.service.ts
│ └── Email.utils.ts
├── features/
│ ├── Auth/
│ │ └── v1/
│ │ ├── Auth.controller.ts
│ │ ├── Auth.service.ts
│ │ ├── Auth.validators.ts
│ │ ├── Auth.constants.ts
│ │ └── Auth.ts
│ ├── Todo/
│ │ └── v1/
│ │ └── ...
│ └── Folder/
│ └── v1/
│ └── ...
└── index.ts
💡 Example: How Developers Will Use It
// ✅ In any file (e.g., src/api/auth.routes.ts)
import { fastKit } from '../fastkit';
import { authController } from '../features/Auth/v1/Auth.controller';
import { validateSignup } from '../features/Auth/v1/Auth.validators';
fastKit.post('/auth/signup', validateSignup, authController.signup);
fastKit.post('/auth/login', authController.login);
// ✅ In server.ts
import express from 'express';
import { FastKit } from './fastkit';
import { loadFastKitConfig } from './config/fastkit.config';
const app = express();
const fastKit = new FastKit(app, loadFastKitConfig());
// Run express
app.listen(3000, () => {
console.log('🚀 FastKit server running on http://localhost:3000');
});
🔌 What Developers Can Do
-
Use fastKit.get/post() directly in any file
-
Use SendResponse.success() or .error() anywhere
-
Use EmailService.sendOtp(), Logger.log() globally
-
Import middleware like verifyToken or validateBody where needed
-
Add custom routes in any .ts file
-
Don’t touch any Express internals
-
Extend FastKit with your own methods if required
✨ What This Enables
- ✅ Real API Dev without Express noise
- ✅ Modular features (Auth, Todo, Notes, Folder, File, Calendar...)
- ✅ Reusable in any project
- ✅ Custom middleware stacking
- ✅ Full TS Support
- ✅ Cleanest DX
🔁 Final Outcome
Once this issue is complete:
-
You will have a production-ready FastKit base
-
Developers can create their own APIs using fastKit.*() anywhere
-
All services, middlewares, validators, and utilities are modular and importable
-
You can even turn this into a CLI/boilerplate/npm module
🧠 Optional Next Steps
[ ] Add support for Swagger docs
[ ] Add auto-error wrapping for async handlers
[ ] Add fastKit.group('/path', fn) for grouped routes (optional)
[ ] Create CLI to scaffold features