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/DJANGO_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
DJANGO_IN_CONFIG.yaml · 7.0 KB · 290 lines
1# Django in Config
2# Everything Django does in ~200 lines of YAML
3# 50,000 lines → 200 lines
4
5name: "Django Application"
6framework_replaced: "Django + DRF + Celery + Channels"
7
8# ==========================================
9# DJANGO MODELS → CONFIG
10# ==========================================
11model:
12 # models.py
13 User:
14 extends: "AbstractUser" # Django's user model
15 fields:
16 email: {type: "email", unique: true}
17 is_premium: {type: "boolean", default: false}
18
19 Post:
20 fields:
21 title: {type: "CharField", max_length: 200}
22 slug: {type: "SlugField", unique: true}
23 content: {type: "TextField"}
24 author: {type: "ForeignKey", to: "User"}
25 created_at: {type: "DateTimeField", auto_now_add: true}
26
27 class_meta:
28 ordering: ["-created_at"]
29 verbose_name_plural: "Posts"
30
31# ==========================================
32# DJANGO ADMIN → CONFIG
33# ==========================================
34admin:
35 # admin.py
36 register: "all"
37
38 customization:
39 Post:
40 list_display: ["title", "author", "created_at"]
41 list_filter: ["created_at", "author"]
42 search_fields: ["title", "content"]
43 prepopulated_fields: {slug: ["title"]}
44
45 site_header: "My Django App Admin"
46 site_title: "Admin Portal"
47
48# ==========================================
49# DJANGO VIEWS → CONFIG
50# ==========================================
51views:
52 # views.py / viewsets.py
53 PostViewSet:
54 type: "ModelViewSet"
55 queryset: "Post.objects.all()"
56 serializer: "PostSerializer"
57 permission_classes: ["IsAuthenticatedOrReadOnly"]
58 filter_backends: ["SearchFilter", "OrderingFilter"]
59 search_fields: ["title", "content"]
60
61 home_view:
62 template: "home.html"
63 context:
64 recent_posts: "Post.objects.all()[:5]"
65 user_count: "User.objects.count()"
66
67# ==========================================
68# DJANGO URLS → CONFIG
69# ==========================================
70urls:
71 # urls.py
72 patterns:
73 "": "home_view"
74 "admin/": "admin.site.urls"
75 "api/": "include('api.urls')"
76 "posts/<slug:slug>/": "PostDetailView"
77
78 api_router:
79 "posts": "PostViewSet"
80 "users": "UserViewSet"
81
82# ==========================================
83# DJANGO REST FRAMEWORK → CONFIG
84# ==========================================
85rest_framework:
86 # serializers.py
87 serializers:
88 PostSerializer:
89 model: "Post"
90 fields: ["id", "title", "slug", "content", "author"]
91
92 UserSerializer:
93 model: "User"
94 fields: ["id", "username", "email"]
95 read_only_fields: ["id"]
96
97 # settings.py DRF config
98 default_authentication: ["TokenAuthentication", "SessionAuthentication"]
99 default_permission: ["IsAuthenticated"]
100 pagination_class: "PageNumberPagination"
101 page_size: 20
102
103# ==========================================
104# DJANGO MIDDLEWARE → CONFIG
105# ==========================================
106middleware:
107 # settings.py MIDDLEWARE
108 - SecurityMiddleware
109 - SessionMiddleware
110 - CommonMiddleware
111 - CsrfViewMiddleware
112 - AuthenticationMiddleware
113 - MessageMiddleware
114
115# ==========================================
116# CELERY TASKS → CONFIG
117# ==========================================
118tasks:
119 # tasks.py
120 send_welcome_email:
121 queue: "email"
122 task: "email.send_welcome"
123 retry: 3
124 retry_delay: 60
125
126 generate_report:
127 schedule: "cron(0 0 * * 1)" # Weekly
128 task: "reports.generate_weekly"
129
130 celery_beat_schedule:
131 cleanup_old_sessions:
132 task: "django.cleanup_sessions"
133 schedule: "interval(hours=24)"
134
135# ==========================================
136# DJANGO CHANNELS → CONFIG
137# ==========================================
138channels:
139 # consumers.py / routing.py
140 websocket_routes:
141 "/ws/chat/": "ChatConsumer"
142 "/ws/notifications/": "NotificationConsumer"
143
144 ChatConsumer:
145 on_connect: "accept_connection"
146 on_receive: "broadcast_message"
147 groups: ["chat_room"]
148
149# ==========================================
150# DJANGO FORMS → CONFIG
151# ==========================================
152forms:
153 # forms.py
154 PostForm:
155 model: "Post"
156 fields: ["title", "content"]
157 widgets:
158 content: "Textarea(attrs={'rows': 10})"
159
160 ContactForm:
161 fields:
162 name: {type: "CharField", max_length: 100}
163 email: {type: "EmailField"}
164 message: {type: "CharField", widget: "Textarea"}
165
166# ==========================================
167# DJANGO TEMPLATES → CONFIG
168# ==========================================
169templates:
170 # templates/
171 extends: "base.html"
172
173 blocks:
174 title: "{{ post.title }} | My Site"
175 content: |
176 <h1>{{ post.title }}</h1>
177 <p>By {{ post.author }} on {{ post.created_at|date }}</p>
178 <div>{{ post.content|safe }}</div>
179
180 filters:
181 date: "F j, Y"
182 truncatewords: 50
183
184# ==========================================
185# DJANGO SETTINGS → CONFIG
186# ==========================================
187settings:
188 # settings.py
189 debug: false
190 allowed_hosts: ["example.com"]
191
192 databases:
193 default:
194 engine: "postgresql"
195 name: "myapp"
196
197 static:
198 url: "/static/"
199 root: "staticfiles"
200
201 media:
202 url: "/media/"
203 root: "media"
204
205 email:
206 backend: "smtp"
207 host: "smtp.gmail.com"
208 port: 587
209
210 cache:
211 backend: "redis"
212 location: "redis://127.0.0.1:6379/1"
213
214# ==========================================
215# DJANGO MIGRATIONS → CONFIG
216# ==========================================
217migrations:
218 # Auto-generated from model changes
219 auto_generate: true
220
221 # Custom migrations
222 custom:
223 add_user_tier:
224 operations:
225 - "AddField('User', 'tier', CharField(max_length=10))"
226
227# ==========================================
228# DJANGO SIGNALS → CONFIG
229# ==========================================
230signals:
231 # signals.py
232 post_save:
233 User:
234 - send_welcome_email
235 - create_user_profile
236
237 pre_delete:
238 Post:
239 - cleanup_related_files
240
241# ==========================================
242# DJANGO AUTH → CONFIG
243# ==========================================
244auth:
245 # Django's auth system
246 authentication_backends:
247 - "ModelBackend" # Username/password
248 - "OAuth2Backend" # Social login
249
250 social_auth:
251 google:
252 client_id: "{{ env.GOOGLE_CLIENT_ID }}"
253 scope: ["email", "profile"]
254
255 password_validators:
256 - MinimumLengthValidator: 8
257 - CommonPasswordValidator
258 - NumericPasswordValidator
259
260# ==========================================
261# THE COMPARISON
262# ==========================================
263# Django Project Structure:
264# myproject/
265# manage.py
266# myproject/
267# __init__.py
268# settings.py (300+ lines)
269# urls.py (50+ lines)
270# wsgi.py
271# asgi.py
272# myapp/
273# __init__.py
274# models.py (200+ lines)
275# views.py (500+ lines)
276# urls.py (50+ lines)
277# admin.py (100+ lines)
278# forms.py (150+ lines)
279# serializers.py (100+ lines)
280# tasks.py (100+ lines)
281# signals.py (50+ lines)
282# migrations/ (20+ files)
283# templates/ (10+ files)
284# static/ (CSS/JS files)
285# requirements.txt (30+ packages)
286#
287# Total: 50+ files, 10,000+ lines
288#
289# DBBasic: This 1 file, ~200 lines
290# ==========================================