FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
lightweight
lightweightglimpse2-runbook-view-glimpse-save-login-react
Remix of lightweight/glimpse2-runbook-view-glimpse-save-login
Public
Like
glimpse2-runbook-view-glimpse-save-login-react
Home
Code
8
_townie
13
backend
7
frontend
9
shared
3
.vtignore
README.md
deno.json
H
main.tsx
Branches
2
Pull requests
Remixes
History
Environment variables
6
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
backend
/
README.md
Code
/
backend
/
README.md
Search
…
Viewing readonly version of main branch: v34
View latest version
README.md

Backend

The backend follows a clean architecture with proper separation of concerns across multiple layers.

Architecture Overview

Separation of Concerns

The backend is organized into distinct layers, each with specific responsibilities:

Architecture Layers

  • Controllers: Business logic, workflow orchestration, HTTP handling
  • Services: External integrations and data persistence operations
  • Routes: HTTP routing, middleware application, parameter extraction
  • Utils: Pure utility functions with no external dependencies

Data Flow Pattern

Request → Routes (middleware + routing) → Controllers (business logic + orchestration) → Services (external operations) + Utils (pure functions) → Response

Key Principles

  • Controllers orchestrate services and use utilities to implement business workflows
  • Services handle external system interactions (APIs, databases, storage)
  • Utils provide pure, reusable functions with no side effects
  • Routes focus purely on HTTP concerns and middleware

Layer Interactions

Controllers Use Both Services and Utils

// Controller orchestrates services and uses utils const pageData = await getPageById(pageId); // SERVICE call const cleanedData = formatAgentProperties(pageData); // UTIL function await setAgentBlob(pageId, cleanedData); // SERVICE call

Clear Distinction: Services vs Utils

  • Services: "I need to talk to Notion API" → notion/page.service.ts
  • Utils: "I need to format this date" → utils/date.helpers.ts
  • Services: "I need to store this in blob storage" → blob.service.ts
  • Utils: "I need to validate this email format" → utils/validation.helpers.ts

Directory Structure

backend/
├── controllers/         # Business logic and workflow orchestration
├── routes/             # HTTP routing and middleware
├── services/           # External integrations (APIs, storage)
├── utils/              # Pure utility functions
├── types/              # TypeScript type definitions
└── crons/              # Scheduled tasks

Response Format Standards

All controller functions return a consistent structure:

{ success: boolean, data: any | null, error: string | null, details?: string // Additional error context }

Routes then format these into appropriate HTTP responses.

Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.