askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/docs/paradigms/EXPRESS_IN_CONFIG.yaml
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
EXPRESS_IN_CONFIG.yaml · 6.7 KB · 291 lines
1# Express.js in Config
2# Everything Express does in ~100 lines of YAML
3# 10,000 lines + node_modules → 100 lines
4
5name: "Express Application"
6framework_replaced: "Express + MongoDB + Passport + Socket.io + Bull"
7
8# ==========================================
9# EXPRESS ROUTES → CONFIG
10# ==========================================
11routes:
12 # app.js routes
13 middleware:
14 - cors
15 - helmet
16 - morgan: "dev"
17 - express.json
18 - express.urlencoded: {extended: true}
19
20 GET:
21 "/":
22 handler: "res.render('home', {title: 'Welcome'})"
23
24 "/api/users":
25 middleware: ["authenticate"]
26 handler: "userController.getAll"
27
28 "/api/users/:id":
29 handler: "userController.getById"
30 cache: 300
31
32 POST:
33 "/api/users":
34 middleware: ["authenticate", "admin"]
35 validate:
36 body:
37 email: "email"
38 password: "min:8"
39 handler: "userController.create"
40
41 "/api/login":
42 handler: "authController.login"
43 rate_limit: "5 per minute"
44
45 PUT:
46 "/api/users/:id":
47 middleware: ["authenticate", "ownerOrAdmin"]
48 handler: "userController.update"
49
50 DELETE:
51 "/api/users/:id":
52 middleware: ["authenticate", "admin"]
53 handler: "userController.delete"
54
55# ==========================================
56# MONGODB MODELS → CONFIG
57# ==========================================
58models:
59 # Mongoose schemas
60 User:
61 schema:
62 email: {type: "String", required: true, unique: true}
63 password: {type: "String", required: true}
64 name: "String"
65 role: {type: "String", enum: ["user", "admin"], default: "user"}
66 createdAt: {type: "Date", default: "Date.now"}
67
68 methods:
69 comparePassword: "bcrypt.compare"
70
71 virtuals:
72 fullName: "return `${this.firstName} ${this.lastName}`"
73
74 hooks:
75 pre_save: "hash password if modified"
76
77 Post:
78 schema:
79 title: {type: "String", required: true}
80 content: "String"
81 author: {type: "ObjectId", ref: "User"}
82 tags: ["String"]
83 published: {type: "Boolean", default: false}
84
85 indexes:
86 - {title: "text", content: "text"}
87 - {author: 1, createdAt: -1}
88
89# ==========================================
90# MIDDLEWARE → CONFIG
91# ==========================================
92middleware:
93 authenticate:
94 type: "jwt"
95 secret: "${JWT_SECRET}"
96 handler: |
97 Verify JWT token
98 Set req.user
99 Next() or 401
100
101 admin:
102 handler: |
103 if (req.user.role !== 'admin') {
104 return res.status(403).json({error: 'Forbidden'})
105 }
106 next()
107
108 error_handler:
109 handler: |
110 Log error
111 Send appropriate response
112 Don't leak sensitive info
113
114# ==========================================
115# PASSPORT AUTHENTICATION → CONFIG
116# ==========================================
117auth:
118 strategies:
119 local:
120 username_field: "email"
121 password_field: "password"
122 verify: "User.findOne + bcrypt.compare"
123
124 jwt:
125 secret: "${JWT_SECRET}"
126 extract_from: "header.authorization"
127
128 google:
129 client_id: "${GOOGLE_CLIENT_ID}"
130 client_secret: "${GOOGLE_CLIENT_SECRET}"
131 callback_url: "/auth/google/callback"
132
133# ==========================================
134# SOCKET.IO REALTIME → CONFIG
135# ==========================================
136websocket:
137 # socket.io setup
138 cors:
139 origin: "http://localhost:3000"
140 credentials: true
141
142 namespaces:
143 "/chat":
144 middleware: ["authenticate"]
145
146 events:
147 connection:
148 - "socket.join(user.room)"
149 - "socket.emit('welcome')"
150
151 message:
152 - "validate message"
153 - "broadcast to room"
154 - "save to database"
155
156 disconnect:
157 - "notify room"
158 - "cleanup"
159
160# ==========================================
161# BACKGROUND JOBS (BULL) → CONFIG
162# ==========================================
163queues:
164 # Bull queue configuration
165 email:
166 redis: "redis://localhost:6379"
167
168 jobs:
169 sendWelcomeEmail:
170 process: "sendEmail(user.email, 'welcome')"
171 attempts: 3
172 backoff: "exponential"
173
174 sendNewsletter:
175 process: "batchSendEmails"
176 cron: "0 9 * * MON"
177
178 image_processing:
179 jobs:
180 generateThumbnail:
181 process: "sharp.resize(200, 200)"
182 concurrency: 5
183
184# ==========================================
185# DATABASE & SESSIONS → CONFIG
186# ==========================================
187database:
188 mongodb:
189 uri: "mongodb://localhost:27017/myapp"
190 options:
191 useNewUrlParser: true
192 useUnifiedTopology: true
193
194 redis:
195 host: "localhost"
196 port: 6379
197
198 sessions:
199 store: "redis"
200 secret: "${SESSION_SECRET}"
201 ttl: 86400
202
203# ==========================================
204# FILE UPLOADS → CONFIG
205# ==========================================
206uploads:
207 # Multer configuration
208 storage: "disk" # or "s3"
209
210 limits:
211 file_size: "10MB"
212 files: 5
213
214 allowed_types: ["image/jpeg", "image/png", "application/pdf"]
215
216 destinations:
217 avatars: "/uploads/avatars"
218 documents: "/uploads/docs"
219
220# ==========================================
221# VALIDATION → CONFIG
222# ==========================================
223validation:
224 # express-validator
225 schemas:
226 createUser:
227 email: "isEmail"
228 password: "isLength({min: 8})"
229 age: "isInt({min: 18, max: 120})"
230
231 createPost:
232 title: "notEmpty"
233 content: "isLength({min: 10})"
234 tags: "isArray"
235
236# ==========================================
237# ERROR HANDLING → CONFIG
238# ==========================================
239errors:
240 handlers:
241 ValidationError:
242 status: 400
243 message: "Validation failed"
244
245 UnauthorizedError:
246 status: 401
247 message: "Authentication required"
248
249 NotFoundError:
250 status: 404
251 message: "Resource not found"
252
253 logging:
254 service: "winston"
255 level: "info"
256 transport: ["console", "file"]
257
258# ==========================================
259# THE COMPARISON
260# ==========================================
261# Express Project Structure:
262# my-express-app/
263# package.json (50+ dependencies)
264# app.js (200+ lines)
265# routes/
266# users.js (300+ lines)
267# posts.js (250+ lines)
268# auth.js (200+ lines)
269# controllers/ (10+ files, 1500+ lines)
270# models/ (10+ files, 800+ lines)
271# middleware/ (8+ files, 400+ lines)
272# validators/ (5+ files, 300+ lines)
273# services/ (10+ files, 1000+ lines)
274# utils/ (5+ files, 500+ lines)
275# config/
276# database.js
277# passport.js
278# redis.js
279# node_modules/ (50,000+ files, 200MB+)
280#
281# Total: 100+ files, 10,000+ lines (plus node_modules chaos)
282#
283# DBBasic: This 1 file, ~100 lines
284# ==========================================
285
286# BONUS: No more:
287# - "Cannot find module"
288# - "npm audit: 47 vulnerabilities"
289# - "node_modules is 800MB"
290# - Callback hell or Promise chains
291# - Figuring out which of 20 middleware order matters