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/NEXTJS_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
NEXTJS_IN_CONFIG.yaml · 7.1 KB · 296 lines
1# Next.js in Config
2# Everything Next.js does in ~150 lines of YAML
3# 100,000 lines (with node_modules) → 150 lines
4
5name: "Next.js Application"
6framework_replaced: "Next.js + React + Tailwind + Prisma + tRPC"
7
8# ==========================================
9# NEXT.JS PAGES/APP ROUTER → CONFIG
10# ==========================================
11routes:
12 # pages/ or app/ directory
13 "/":
14 component: "HomePage"
15 getStaticProps: "fetch_home_data"
16
17 "/blog/[slug]":
18 component: "BlogPost"
19 getStaticPaths: "get_all_posts"
20 getStaticProps: "fetch_post_by_slug"
21
22 "/dashboard":
23 component: "Dashboard"
24 getServerSideProps: "fetch_user_data"
25 middleware: ["auth"]
26
27 "/api/posts":
28 method: ["GET", "POST"]
29 handler: "handle_posts_api"
30
31# ==========================================
32# REACT COMPONENTS → CONFIG
33# ==========================================
34components:
35 # components/ directory
36 HomePage:
37 props: ["posts", "featured"]
38 render: |
39 <Layout>
40 <Hero />
41 <FeaturedPosts posts={featured} />
42 <PostGrid posts={posts} />
43 </Layout>
44
45 PostCard:
46 props: ["title", "excerpt", "date", "slug"]
47 render: |
48 <Link href={`/blog/${slug}`}>
49 <Card>
50 <h2>{title}</h2>
51 <p>{excerpt}</p>
52 <time>{date}</time>
53 </Card>
54 </Link>
55
56# ==========================================
57# NEXT.JS API ROUTES → CONFIG
58# ==========================================
59api:
60 # pages/api/ or app/api/
61 "/api/auth/[...nextauth]":
62 provider: "NextAuth"
63 providers: ["Google", "GitHub", "Email"]
64
65 "/api/trpc/[trpc]":
66 handler: "tRPC"
67 procedures:
68 posts.list: "SELECT * FROM posts"
69 posts.create: "INSERT INTO posts"
70 user.profile: "SELECT * FROM users WHERE id = ?"
71
72# ==========================================
73# NEXT.JS DATA FETCHING → CONFIG
74# ==========================================
75data_fetching:
76 # getStaticProps, getServerSideProps, etc.
77 fetch_home_data:
78 revalidate: 60 # ISR
79 query: |
80 posts: "SELECT * FROM posts ORDER BY date DESC LIMIT 10"
81 featured: "SELECT * FROM posts WHERE featured = true"
82
83 fetch_post_by_slug:
84 query: "SELECT * FROM posts WHERE slug = ?"
85 notFound: "IF NOT EXISTS"
86
87# ==========================================
88# REACT STATE MANAGEMENT → CONFIG
89# ==========================================
90state:
91 # Redux, Zustand, Jotai - or just config
92 global:
93 user: "null | User"
94 theme: "'light' | 'dark'"
95 cart: "CartItem[]"
96
97 providers:
98 ThemeProvider:
99 value: "theme"
100 toggle: "setTheme(theme === 'light' ? 'dark' : 'light')"
101
102# ==========================================
103# TAILWIND CSS → CONFIG
104# ==========================================
105styles:
106 # tailwind.config.js → config
107 theme:
108 colors:
109 primary: "#0066ff"
110 secondary: "#00ffcc"
111
112 spacing:
113 unit: "0.25rem"
114
115 components:
116 ".btn": "px-4 py-2 bg-primary text-white rounded hover:bg-primary-dark"
117 ".card": "p-6 bg-white shadow rounded-lg"
118
119# ==========================================
120# PRISMA SCHEMA → CONFIG
121# ==========================================
122database:
123 # schema.prisma
124 models:
125 User:
126 fields:
127 id: {type: "String", id: true, default: "cuid()"}
128 email: {type: "String", unique: true}
129 posts: {type: "Post[]", relation: true}
130
131 Post:
132 fields:
133 id: {type: "String", id: true}
134 title: "String"
135 content: "String"
136 published: {type: "Boolean", default: false}
137 author: {type: "User", relation: true}
138
139# ==========================================
140# NEXT.JS MIDDLEWARE → CONFIG
141# ==========================================
142middleware:
143 # middleware.ts
144 matchers:
145 "/dashboard/*": ["requireAuth"]
146 "/admin/*": ["requireAdmin", "logAccess"]
147
148 functions:
149 requireAuth: "redirect('/login') if !user"
150 requireAdmin: "return 403 if user.role !== 'admin'"
151
152# ==========================================
153# NEXT.JS IMAGE OPTIMIZATION → CONFIG
154# ==========================================
155images:
156 # next/image config
157 domains: ["images.example.com", "cdn.example.com"]
158
159 optimization:
160 quality: 75
161 formats: ["image/webp"]
162
163 sizes:
164 thumbnail: "100px"
165 card: "300px"
166 hero: "100vw"
167
168# ==========================================
169# ENVIRONMENT & CONFIG → CONFIG
170# ==========================================
171env:
172 # .env.local
173 public:
174 NEXT_PUBLIC_API_URL: "https://api.example.com"
175 NEXT_PUBLIC_GA_ID: "G-XXXXXXXXXX"
176
177 server:
178 DATABASE_URL: "postgresql://..."
179 JWT_SECRET: "{{ secret }}"
180
181# ==========================================
182# BUILD & DEPLOYMENT → CONFIG
183# ==========================================
184build:
185 # next.config.js
186 output: "standalone" # or "static" for SSG
187
188 optimization:
189 bundle_analyzer: false
190 remove_console: true
191
192 redirects:
193 "/old-path": "/new-path"
194
195 headers:
196 "/*":
197 X-Frame-Options: "DENY"
198 X-Content-Type-Options: "nosniff"
199
200deployment:
201 platform: "vercel" # or "netlify", "cloudflare"
202
203 functions:
204 regions: ["iad1"] # Edge functions
205 maxDuration: 10
206
207# ==========================================
208# WEBPACK/TURBOPACK → CONFIG
209# ==========================================
210bundling:
211 # webpack.config.js - who cares, just make it work
212 mode: "auto"
213
214 aliases:
215 "@": "./src"
216 "@components": "./src/components"
217
218 optimizations:
219 tree_shaking: true
220 code_splitting: true
221 minification: true
222
223# ==========================================
224# TESTING → CONFIG
225# ==========================================
226testing:
227 # jest.config.js, cypress.config.js
228 unit:
229 framework: "jest"
230 coverage: 80
231
232 e2e:
233 framework: "playwright"
234 browsers: ["chrome", "firefox"]
235
236 tests:
237 "HomePage renders": "expect(HomePage).toBeInDocument()"
238 "API returns posts": "expect(api.posts).toHaveLength(10)"
239
240# ==========================================
241# THE COMPARISON
242# ==========================================
243# Next.js Project Structure:
244# my-app/
245# package.json (50+ dependencies)
246# next.config.js
247# tailwind.config.js
248# tsconfig.json
249# .env.local
250# prisma/
251# schema.prisma
252# src/
253# app/ (or pages/)
254# layout.tsx
255# page.tsx
256# blog/
257# [slug]/
258# page.tsx
259# api/
260# posts/
261# route.ts
262# components/
263# (50+ component files)
264# lib/
265# (utility files)
266# styles/
267# globals.css
268# node_modules/
269# (100,000+ files, 500MB+)
270#
271# Total: 200+ files, 50,000+ lines (not counting node_modules)
272#
273# DBBasic: This 1 file, ~150 lines
274# ==========================================
275
276# ==========================================
277# THE REAL KICKER
278# ==========================================
279# Next.js requires understanding:
280# - React
281# - JSX/TSX
282# - Webpack/Turbopack
283# - Node.js
284# - npm/yarn/pnpm
285# - CSS-in-JS or Tailwind
286# - REST or GraphQL or tRPC
287# - Prisma or another ORM
288# - Vercel deployment specifics
289# - Edge vs Node runtime
290# - Client vs Server components
291# - Hydration issues
292# - Bundle optimization
293#
294# DBBasic requires understanding:
295# - YAML
296# ==========================================