Skip to content

yeungon/gossr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GOSSR - A Golang Template Applying Clean Architecture with DDD and Server-Side Rendering

ALERT: WIP

I wanted to create a ready-to-use, scalable Golang template for building web applications with HTMX and server-side rendering (SSR). While there are a few templates out there, I still feel there isn’t an ideal candidate that truly embraces SSR—especially when it comes to structuring HTML and static files using Go’s embed feature.

This template, GoSSR, is built from my personal experience developing several Golang projects. It implements Clean Architecture (modular approach) and Domain-Driven Design (DDD) Lite principles, with full support for server-side rendering.

Please check out the references and my notes on discussions and lessons learned while creating the GoSSR template. I’ve kept the Standard Go Project Layout in mind but also made some modifications where I found improvements necessary.

In GoSSR, you’ll notice I use a “consumer interface” approach (which you might find unconventional in other languages), along with SQLC for database interactions—which is one of my personal favorites and a core reason why the template is structured this way. It’s not perfect, but I think it works for me.

Features

  • Clean Architecture with Domain-Driven Design
  • Server-side rendering
  • PostgreSQL with SQLC for type-safe queries
  • Modular design with independent business domains
  • Chi router for HTTP routing
  • Database migrations support

Prerequisites

  • Go 1.24+
  • PostgreSQL
  • golang-migrate
  • sqlc
  • go-chi

Configuration

Configuration is managed through config.go with environment variables. Please see .env_example for more details:

  • HTTP_ADDR: Server address (default: :8080)
  • DB_URL: PostgreSQL connection string

Getting Started

  1. Clone the repository
  2. Copy .env_example.env and configure
  3. Initialize the database:
    make up
  4. Start the development server:
    make dev

Database Migrations

Manage your database using the commands in the Makefile:

make up     # Apply migrations
make down   # Rollback migrations

Domain Modules

The root of the app is located at internal/app where everything is wired up. The module folder where you are spending most of your time is internal/module. Here are some examples:

Article Module

  • Located at internal/module/articles
  • domain/article.go: articles domain model
  • business/service.go: Business logic
  • storage/postgres.go: Data persistence

Category Module

  • Located at internal/module/categories
  • domain/category.go: category domain model
  • business/service.go: Business processing
  • storage/postgres.go: Data persistence

HTTP Endpoints

Articles

  • GET /article/{id} → Get article by ID

Category

  • GET /category/{id} → Get category by ID

Development

The application uses:

  • app.NewServer → HTTP server setup
  • app.NewRouter → Routing configuration
  • Chi middleware for logging and recovery

Directory Structure

  • cmd → Application entrypoints
  • internal → Private application code
  • config → Configuration management
  • pkg → Shared utilities
  • html → Template files for server-side rendering

Project Layout

The project follows Clean Architecture principles with clear separation of layers:

  • Domain Layer → Domain models and interfaces
  • Business Layer → Use cases and business rules
  • Infrastructure Layer → External interfaces
  • Transport Layer → HTTP handlers

Each module is self-contained with its own layers following DDD principles.

 ├── business/    (Service and Repository)
 ├── transport/   (Controller)
 ├── domain/      (entity and validation)
 ├── mapper/      (Mapping between model sqlc <-> domain)
 ├── queries/     (We write raw queries here which will be then used by sqlc to generate type safe code which is then put in /sqlc folder.)
 ├── storage/
 └── sqlc/        (Generated by sqlc)
infras/           (shared infrastructure)

Alternative name

  • domain -> entity (quite common option)
  • transport -> controllers (simplier)
  • business --> service (in which repository is simply a file given its succint content - mainly interface)

References

License

This project is licensed under the MIT License.

About

Go Server Side Rendering Template using DDD Lite and Clean Code

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors