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/LARAVEL_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
LARAVEL_IN_CONFIG.yaml · 8.5 KB · 378 lines
1# Laravel in Config
2# Everything Laravel does in ~180 lines of YAML
3# 75,000 lines → 180 lines
4
5name: "Laravel Application"
6framework_replaced: "Laravel + Livewire + Inertia + Sanctum + Horizon"
7
8# ==========================================
9# ELOQUENT MODELS → CONFIG
10# ==========================================
11model:
12 # app/Models/
13 User:
14 extends: "Authenticatable"
15 fillable: ["name", "email", "password"]
16 hidden: ["password", "remember_token"]
17 casts:
18 email_verified_at: "datetime"
19 is_admin: "boolean"
20
21 relationships:
22 posts: "hasMany"
23 profile: "hasOne"
24 roles: "belongsToMany"
25
26 Post:
27 fillable: ["title", "slug", "content", "published_at"]
28 casts:
29 published_at: "datetime"
30 meta_data: "json"
31
32 scopes:
33 published: "WHERE published_at <= NOW()"
34 draft: "WHERE published_at IS NULL"
35
36# ==========================================
37# LARAVEL ROUTES → CONFIG
38# ==========================================
39routes:
40 # routes/web.php
41 web:
42 "/": "HomeController@index"
43 "/posts/{post:slug}": "PostController@show"
44 "/dashboard":
45 middleware: ["auth"]
46 controller: "DashboardController@index"
47
48 # routes/api.php
49 api:
50 prefix: "/api"
51 middleware: ["api", "throttle:60,1"]
52 routes:
53 "/posts": "ApiPostController"
54 "/users": "ApiUserController"
55
56 # Resource routes
57 resources:
58 posts: ["index", "show", "create", "store", "edit", "update", "destroy"]
59 middleware: ["auth"]
60
61# ==========================================
62# CONTROLLERS → CONFIG
63# ==========================================
64controllers:
65 # app/Http/Controllers/
66 PostController:
67 index:
68 view: "posts.index"
69 data:
70 posts: "Post::published()->paginate(10)"
71
72 show:
73 view: "posts.show"
74 data:
75 post: "Post::findOrFail($slug)"
76 related: "Post::related($post)->limit(3)"
77
78 store:
79 validate:
80 title: "required|string|max:255"
81 content: "required|string"
82 action: |
83 Post::create($validated)
84 redirect('/posts')->with('success', 'Post created!')
85
86# ==========================================
87# BLADE TEMPLATES → CONFIG
88# ==========================================
89templates:
90 # resources/views/
91 layout:
92 app: |
93 <!DOCTYPE html>
94 <html>
95 <head>
96 @yield('title')
97 @vite(['resources/css/app.css', 'resources/js/app.js'])
98 </head>
99 <body>
100 @include('partials.navigation')
101 @yield('content')
102 @include('partials.footer')
103 </body>
104 </html>
105
106 components:
107 # Blade components
108 alert:
109 props: ["type", "message"]
110 template: |
111 <div class="alert alert-{{ $type }}">
112 {{ $message }}
113 </div>
114
115# ==========================================
116# LIVEWIRE COMPONENTS → CONFIG
117# ==========================================
118livewire:
119 # app/Http/Livewire/
120 SearchPosts:
121 properties:
122 search: ""
123 posts: []
124
125 mount: |
126 $this->posts = Post::all()
127
128 updated:
129 search: |
130 $this->posts = Post::where('title', 'like', "%{$this->search}%")->get()
131
132 render:
133 view: "livewire.search-posts"
134
135# ==========================================
136# MIDDLEWARE → CONFIG
137# ==========================================
138middleware:
139 # app/Http/Middleware/
140 authenticate:
141 handle: |
142 if (!auth()->check()) {
143 return redirect('/login')
144 }
145
146 admin:
147 handle: |
148 if (!auth()->user()->is_admin) {
149 abort(403)
150 }
151
152 throttle:
153 limit: 60
154 per_minutes: 1
155
156# ==========================================
157# VALIDATION → CONFIG
158# ==========================================
159validation:
160 # app/Http/Requests/
161 StorePostRequest:
162 rules:
163 title: "required|string|max:255|unique:posts"
164 slug: "required|alpha_dash|unique:posts"
165 content: "required|string|min:100"
166 tags: "array"
167 "tags.*": "exists:tags,id"
168
169 messages:
170 "title.required": "A title is required"
171 "content.min": "Post must be at least 100 characters"
172
173# ==========================================
174# MIGRATIONS → CONFIG
175# ==========================================
176migrations:
177 # database/migrations/
178 create_posts_table:
179 up:
180 create: "posts"
181 columns:
182 id: "bigIncrements"
183 title: "string"
184 slug: "string.unique"
185 content: "text"
186 published_at: "timestamp.nullable"
187 timestamps: true
188
189 indexes:
190 - ["slug"]
191 - ["published_at", "created_at"]
192
193# ==========================================
194# QUEUES & JOBS → CONFIG
195# ==========================================
196queues:
197 # app/Jobs/
198 connection: "redis"
199
200 jobs:
201 SendNewsletter:
202 handle: |
203 User::subscribed()->each(function ($user) {
204 Mail::to($user)->send(new NewsletterMail())
205 })
206
207 queue: "emails"
208 tries: 3
209 timeout: 300
210
211 ProcessVideo:
212 handle: "ai://process_uploaded_video"
213 queue: "media"
214
215# ==========================================
216# LARAVEL HORIZON → CONFIG
217# ==========================================
218horizon:
219 # config/horizon.php
220 environments:
221 production:
222 supervisor-1:
223 maxProcesses: 10
224 balanceMaxShift: 1
225 balanceCooldown: 3
226
227 queue_worker_config:
228 memory: 128
229 timeout: 300
230 tries: 3
231
232# ==========================================
233# AUTHENTICATION → CONFIG
234# ==========================================
235auth:
236 # config/auth.php
237 guards:
238 web:
239 driver: "session"
240 provider: "users"
241
242 api:
243 driver: "sanctum"
244 provider: "users"
245
246 providers:
247 users:
248 driver: "eloquent"
249 model: "User"
250
251 passwords:
252 users:
253 provider: "users"
254 expire: 60
255
256# ==========================================
257# EVENTS & LISTENERS → CONFIG
258# ==========================================
259events:
260 # app/Events/ & app/Listeners/
261 PostPublished:
262 listeners:
263 - SendPostNotification
264 - UpdateSearchIndex
265 - InvalidateCache
266
267 UserRegistered:
268 listeners:
269 - SendWelcomeEmail
270 - CreateUserProfile
271 - LogRegistration
272
273# ==========================================
274# SERVICE PROVIDERS → CONFIG
275# ==========================================
276providers:
277 # app/Providers/
278 AppServiceProvider:
279 boot: |
280 View::share('site_name', config('app.name'))
281 Model::preventLazyLoading(!app()->isProduction())
282
283 EventServiceProvider:
284 listen:
285 PostPublished: [SendNotification, UpdateIndex]
286
287# ==========================================
288# ARTISAN COMMANDS → CONFIG
289# ==========================================
290commands:
291 # app/Console/Commands/
292 import:posts:
293 signature: "import:posts {file : CSV file path}"
294 description: "Import posts from CSV"
295 handle: |
296 $csv = Reader::createFromPath($file)
297 foreach ($csv as $row) {
298 Post::create($row)
299 }
300
301# ==========================================
302# BROADCASTING → CONFIG
303# ==========================================
304broadcasting:
305 # config/broadcasting.php
306 driver: "pusher"
307
308 channels:
309 post.{postId}:
310 authorize: "return $user->can('view', Post::find($postId))"
311
312 events:
313 PostUpdated:
314 channel: "post.{$this->post->id}"
315 data: ["title", "content"]
316
317# ==========================================
318# CACHE → CONFIG
319# ==========================================
320cache:
321 # config/cache.php
322 default: "redis"
323
324 stores:
325 redis:
326 driver: "redis"
327 connection: "cache"
328
329 tags:
330 posts: ["posts", "content"]
331
332 remember:
333 popular_posts:
334 key: "popular_posts"
335 ttl: 3600
336 query: "Post::popular()->limit(10)->get()"
337
338# ==========================================
339# THE COMPARISON
340# ==========================================
341# Laravel Project Structure:
342# my-laravel-app/
343# composer.json (40+ packages)
344# app/
345# Console/
346# Commands/ (10+ files)
347# Events/ (10+ files)
348# Exceptions/
349# Http/
350# Controllers/ (20+ files)
351# Middleware/ (10+ files)
352# Requests/ (15+ files)
353# Livewire/ (10+ files)
354# Jobs/ (10+ files)
355# Listeners/ (10+ files)
356# Models/ (15+ files)
357# Providers/ (5+ files)
358# bootstrap/
359# config/ (20+ config files)
360# database/
361# migrations/ (20+ files)
362# seeders/
363# factories/
364# resources/
365# views/ (50+ blade files)
366# css/
367# js/
368# routes/
369# web.php
370# api.php
371# channels.php
372# console.php
373# vendor/ (thousands of files)
374#
375# Total: 500+ files, 75,000+ lines
376#
377# DBBasic: This 1 file, ~180 lines
378# ==========================================