JomMula

Gallery Blog · Lesson 01

The big picture: what we're building

First we get clear on what we're making, how people will use it, and which tech stack we're using. Code comes later — understand first.

5 min readExplanationno codeUpdated October 2026

Okay, today we’re going to learn how to build a gallery blog (no idea what to name it yet). We’ll pick a name together later.

basically you want to build a website where people can look at the photos you post, and comment or maybe like. But you want to build it in your own design, right. Sooo it’s very simple actually — but let’s think about it as a flow, how a user will use it.

Pick a name first

This is actually the hardest part. Not the code — the name (said with a joking tone). Tap whichever one feels right:

Tap any one. It's just a demo — the name doesn't affect anything.

What this project needs

For this project’s prerequisites, I’ve listed a few things you need to download and prepare:

Requirements checklist

0/6 done

If you don’t want to do that yet, no problem — let’s focus on how the system works first.

Flow: how people use this website

First we need to understand: when you land on the website, obviously what people see is the photos etc. And then maybe they can open a photo and comment or like, and so on.

But remember — there isn’t just one flow, there are two. There’s a visitor flow, and an admin flow (you). Tap the tabs and look at each one:

Click each step to focus

Summary: open → browse → click → like/comment. All without logging in.

And that’s really it. Simple, right?

Wait — where do the photos come from?

This is the part people always miss. Visitors only see the photos — but how did they get there?

So now you have two clear big parts:

Public side

for visitors

  • Anyone can walk in, no login
  • Browse photos by folder
  • Open a photo large (lightbox)
  • Like and drop a comment

Admin side

just for you

  • Log in before you can enter
  • Upload new photos any time
  • Create folders and arrange photos
  • Customise the page however you like

That’s about how it works. Simple right?

Tech stack: what we use to build this

Now we go into tech stack. Haa this is pretty wide — because you can use anything. Laravel works, PHP works, WordPress works. But for simplicity, let’s just use expressjs + ejs + neon + r2 cloudflare — one app that renders its own pages and talks to its own database and storage.

Why this stack? Because it’s one language, one app — JavaScript from back to front, and no separate front-end project to keep in sync. You don’t have to switch your brain between two codebases.

Ex

Express 5

The server

One app that does everything: routes, forms, JSON endpoints, pages. It's the only program in this project.

Why this?

Boring on purpose. You can read the whole app top to bottom and understand every line.

EJ

EJS

The pages

Templates that turn data into finished HTML on the server. No framework, no build step, no browser-side rendering.

Why this?

Escaping is automatic — <%= %> keeps whatever users type from becoming something that runs.

Ne

Neon

Database (Postgres)

Stores the structured data: photos, folders, comments, likes. Never the photo files themselves.

Why this?

Serverless Postgres with a free tier — and a second branch just for tests.

R2

Cloudflare R2

Photo storage

Stores the photo files themselves. The database only keeps the object key.

Why this?

Cheap, fast, S3-compatible — and the browser uploads straight to it with a short-lived signed URL.

How it all connects

This is the most important part of this lesson — how all these things talk to each other. Tap the flows:

One app, four jobs — follow the dots

GET / + cookie1query2rows3photos straight from R24Browserthe only clientpages + a little JSExpress approutes · forms · pagesone process, one originNeonphotos · foldersthe structured dataCloudflare R2photo filesuploaded browser → R2
  1. 1The browser asks Express for the page — GET / — with the session cookie attached.
  2. 2Express verifies the cookie, then queries Neon for the photos.
  3. 3Neon returns rows; Express renders them into HTML with EJS and sends the page back.
  4. 4The photos themselves load from R2 — the server never relays image bytes, so it stays fast.

Project structure: one app, one repo

Last one — the project structure. One app, one repo. No separate frontend folder, no API contract to keep in sync:

Repo structure


            
              gallery-blog/
            
            
          
            
              ├─ src/
            
             the server — one app
          
            
              │  ├─ app.ts
            
             middleware order + routers
          
            
              │  ├─ index.ts
            
             boot: settings, db, listen
          
            
              │  ├─ config.ts
            
             zod-parsed env → Settings
          
            
              │  ├─ db/
            
             schema + client
          
            
              │  ├─ services/
            
             the business logic
          
            
              │  ├─ middleware/
            
             auth, same-origin, headers
          
            
              │  └─ routes/
            
             URLs in, responses out
          
            
              ├─ views/
            
             EJS templates
          
            
              │  ├─ partials/
            
             head + foot on every page
          
            
              │  └─ photos.ejs
            
             list + create form
          
            
              ├─ public/
            
             served as-is
          
            
              │  ├─ css/app.css
            
             hand-written, small
          
            
              │  └─ js/
            
             app.js + upload.js
          
            
              ├─ drizzle/
            
             generated SQL migrations
          
            
              ├─ test/
            
             vitest on a test branch
          
            
              ├─ master-plan.md
            
             the document we follow
          
            
              └─ package.json
            
             scripts: dev, test, db:migrate
          
src/ = the serverviews/ = the pagespublic/ = browser filesdrizzle/ = migrations

Why one app? Because there’s nothing to sync. The pages, the routes, the database schema — they all live in one codebase, get read in one sitting, and ship as one container. The Photo shape lives in exactly one place:

// src/db/schema/photos.ts — the one place the shape lives
export const photos = appSchema.table("photos", {
  id: uuid().primaryKey().defaultRandom(),
  title: text().notNull(),
  imageKey: text(), // R2 object key, never a URL
  createdAt: timestamp({ withTimezone: true }).notNull().defaultNow(),
});

The page that lists photos and the route that creates them both go through this schema. One definition, zero drift.

Try it: a demo you can click

Okay, now the best part. This is the gallery blog demo we’re going to build — not a screenshot, actually clickable:

This is what visitors see. Want to upload?

Try doing this:

  1. Go to Admin, upload a new photo.
  2. Create a folder yourself, arrange photos however you like.
  3. Back to Visitor, click that photo, like it and leave a comment.

Everything you just did — that’s our project. The difference later is the data will live in Neon and the photos in R2, not just in the browser.

Recap: what we know today

A gallery blog has two sides: public for visitors, admin for you.

Visitor flow: open → pick a folder → click a photo → like & comment.

Admin flow: log in → upload a photo → instantly live on the public page.

Our stack: Express + EJS (pages) + Neon (data) + R2 (photo files) — one app, not a pile of services.

One app, one repo — fewer moving parts, fewer things to break.

That’s it for the first lesson. If you read it to the end — congrats, you understand the shape of our project before writing a single line of code.

02

Up next

Mockup with opencode

Before we build the real app, let's vibe code first. With opencode, we'll make a mockup using plain HTML — easy to see everything right away.

Read now