π Framework
A minimal yet powerful web framework with builtin support for ssr html pages and SPA microfrontend splits
Features:
- Simple routing & templating (HTML/Go templates)
- Automatic microfrontend support for multiple SPAs
- 1 Go dependency: esbuild
- Use anything esbuild supports, like TypeScript, JavaScript, JSX, TSX, and CSS
- NO NodeJS process required - no Webpack, Babel, Vite, Rollup, etc.
- Clean
/templates + /frontend folder structure
- Autoreload when in development mode
- Optional Accompanying JavaScript library for frontend development
- Server Sent Events handler, Router, state management, and elements
π¦ Quickstart
1. Project Structure
your-project/
βββ templates/ # HTML templates & components
β βββ base.html # Required: Base layout
β βββ entry.html # Required: html snippet with js and css imports - autogenerated by esbuild on changes
β βββ index.html # Required: Default html page
β βββ other.html # "/other" route auto-registered
β βββ app.subroute.html # "/app/" subroute auto-registered for the app - an easy way to add a new SPA
βββ static # bundled js files place here, you can .gitignore this
βββ frontend/
β βββ src/
β βββ index.ts # Your frontend entrypoint, customize and codesplit as needed
βββ main.go # Your server
- Get started with all the defaults:
package main
import (
"net/http"
"github.com/bencbradshaw/framework"
)
func main() {
http.ListenAndServe(":2025", framework.Run(nil))
}
- Override the defaults:
package main
import (
"net/http"
"os"
"github.com/bencbradshaw/framework"
"github.com/evanw/esbuild/pkg/api"
)
func main() {
mux := framework.Run(framework.InitParams{
IsDevMode: false,
AutoRegisterTemplateRoutes: false,
EsbuildOpts: api.BuildOptions{
EntryPoints: []string{"./app/src/my-app.tsx"},
},
})
// add your own routes, the same as you would with the default mux
mux.Handle("/api/hello-world", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, World!"))
}))
http.ListenAndServe(":2025", mux)
}
π§ In Progress Features
-
Support for Multiple Base Templates
- Allow customization of JavaScript or CSS for different templates.
- Your home page and about page might need different CSS or JS loaded.
-
Image Hosting
- Provide built-in support for serving and managing images.
- This will be simply a folder served with static files
-
Authentication Guard
- Offer a middleware mechanism to enable developers to implement custom authentication logic for route handlers.
- Rather than providing an authentication system, this will allow developers to use their own authentication systems that can tie into the framework.
-
Customizable Templates Directory
- Ensure the
/templates directory path can be configured as needed.
-
Template Naming Conventions
- Clearly define and enforce a consistent naming pattern for templates to improve maintainability.
.html and subroute.html, base and entry. What do they mean and how do they work