How kodejuice/leve works
Project type and purpose
• This is a full-stack, monolithic CMS built with Next.js.
• It serves both the website UI (React pages/components under “pages/” and “components/”) and a REST-style API (Next.js API routes under “pages/api/”) from the same codebase.
• It uses MongoDB as its primary data store and provides an admin interface for creating, editing, importing/exporting posts and quotes.
File structure
• Frontend/UI
– pages/ (Next.js pages: dynamic routes “[...id].js”, _app.js, _document.js, admin pages under pages/admin/)
– components/ (shared UI: home, pages, sections, admin subfolder)
– assets/ (SASS styles, fonts)
• Backend/API
– pages/api/ (auth/login.js, post endpoints, RSS and sitemap endpoints)
– utils/ (auth.js, db_requests.js, mdParser.js, swr.js, etc.)
– database/ (connection.js, functions.js, model.js)
• Data‐import tooling
– data/quotes/indexer (scripts to build quotes index at build-time)
– data/quotes/quotes.js (static quotes data)
• Configuration
– next.config.js, site_config.js, .env.example
README for architecture clues
• Confirms Next.js SSR/CSR model
• Requires MongoDB (external DB service)
• Mentions environment variables and build/run steps
Main components and interactions
a. Client (Browser)
– Sends HTTP requests for pages (SSR or CSR)
– Fetches JSON from Next.js API (via fetch/SWR in utils/swr.js)
– Loads static assets from public/ and compiled assets from assets/
b. Next.js Server
– SSR/SSG: pages/* use getServerSideProps/getStaticProps to call database functions
– API layer: pages/api/* handlers invoke database.functions via database/connection.js
– Admin UI pages call API endpoints for CRUD operations
– Data‐import scripts (data/quotes/indexer) run at build time or on-demand
c. Database (MongoDB)
– Hosts collections for posts, quotes, users (models defined in database/model.js)
– Connected via database/connection.js, used by database/functions.js
d. External services
– Google Analytics (component GoogleAnalytics.js)
– RSS feed generator (API endpoints pages/api/rss*.js)
– Sitemap (pages/api/sitemap.xml.js)
Architectural patterns & design principles
• Monolith with clear separation:
– “Views” = pages/ + components/
– “Controllers” = API route handlers (pages/api/)
– “Models” = database/model.js + database/functions.js
• SSR/SSG hybrid: some pages rendered server-side, others fetched client-side with SWR
• Build-time data injection: quotes indexed via local scripts in data/quotes/indexer
• Single codebase for both UI and API (Next.js strength)