superkit/README.md

239 lines
6.6 KiB
Markdown
Raw Permalink Normal View History

2024-06-16 11:57:08 +02:00
# SUPERKIT
Build high-performance apps swiftly with minimal team resources in Go programming language. **SUPERKIT** is a full-stack web framework that provides a set of tools and libraries to help you build web applications quickly and efficiently. **SUPERKIT** is built on top of the Go programming language and is designed to be simple and easy to use.
2024-06-06 11:51:22 +02:00
2024-06-11 21:00:48 +02:00
> The project (for now) is in the **experimental** phase.
2024-06-09 11:16:23 +02:00
## Table of content
2024-06-16 11:57:08 +02:00
- [SUPERKIT](#superkit)
- [Table of content](#table-of-content)
2024-06-09 11:16:23 +02:00
- [Installation](#installation)
- [Getting started](#getting-started)
- [Application structure](#application-structure)
- [assets](#assets)
- [conf](#conf)
- [db](#db)
- [events](#events)
- [handlers](#handlers)
- [types](#types)
- [views](#views)
- [Development server](#development-server)
- [Hot reloading the browser](#hot-reloading-the-browser)
2024-06-09 11:16:23 +02:00
- [Migrations](#migrations)
- [Create a new migration](#create-a-new-migration)
- [Migrate the database](#migrate-the-database)
- [Reset the database](#reset-the-database)
- [Seeds](#seeds)
2024-06-11 21:12:12 +02:00
- [Creating views with Templ](#creating-views-with-templ)
2024-06-09 20:49:31 +02:00
- [Validations](#validations)
2024-06-09 11:16:23 +02:00
- [Testing](#testing)
- [Testing handlers](#testing-handlers)
2024-06-09 11:31:59 +02:00
- [Create a production release](#create-a-production-release)
2024-06-06 16:53:16 +02:00
## Installation
To create a new **SUPERKIT** project, you can run the following command:
```bash
# Create your SUPERKIT project in a single command:
2024-06-16 17:59:28 +02:00
go run github.com/anthdm/superkit@master [yourprojectname]
2024-06-06 11:51:22 +02:00
# You can now navigate to your project:
2024-06-15 17:34:19 +02:00
cd [myprojectname]
2024-06-07 09:24:46 +02:00
# Run npm install to install both tailwindcss and esbuild locally.
2024-06-15 17:34:19 +02:00
npm install
2024-06-07 11:26:58 +02:00
# If you run into dependency issues you can run:
go clean -modcache && go get -u ./...
2024-06-16 11:50:54 +02:00
# If you have the authentication plugin enabled you need to migrate your database.
make db-up
2024-06-16 11:50:54 +02:00
```
## Getting started
2024-06-09 11:31:59 +02:00
## Application structure
The **SUPERKIT** project structure is designed to be simple and easy to understand. The project structure is as follows:
```bash
├── bootstrap
│ ├── app
│ ├── assets
│ ├── conf
│ ├── db
│ ├── migrations
│ ├── events
│ ├── handlers
│ ├── types
│ ├── views
│ ├── components
│ ├── errors
│ ├── landing
│ ├── layouts
│ ├── cmd
│ ├── app
│ ├── scripts
│ ├── seed
│ ├── plugins
│ ├── auth
│ ├── public
│ ├── assets
│ ├── env.local
│ ├── go.mod
│ ├── go.sum
│ ├── Makefile
│ ├── package-lock.json
│ ├── package.json
│ ├── tailwind.config.js
├── db
├── event
├── kit
│ ├── middleware
├── validate
├── view
├── go.mod
├── install.go
├── README.md
```
2024-06-09 11:31:59 +02:00
### assets
Assets are stored in the `assets` directory. This directory contains all your CSS and JavaScript files. The `assets` directory is structured as follows:
```bash
assets
├── css
│ ├── app.css
├── js
│ ├── app.js
```
2024-06-09 11:31:59 +02:00
### conf
Configuration. First, config.yml is read, then environment variables overwrite the yaml config if they match. The config structure is in the config.go. The env-required: true tag obliges you to specify a value (either in yaml, or in environment variables).
Reading the config from yaml contradicts the ideology of 12 factors, but in practice, it is more convenient than reading the entire config from ENV. It is assumed that default values are in yaml, and security-sensitive variables are defined in ENV.
2024-06-09 11:31:59 +02:00
### db
The `db` directory contains all your database related files. The `db` directory is structured as follows:
```bash
db
├── migrations
│ ├── 20210919123456_create_users_table.sql
├── seeds
│ ├── seed.go
```
2024-06-09 11:31:59 +02:00
### events
The `events` directory contains all your event related files. These files are used to define custom events and event handlers for the project. The `events` directory is structured as follows:
```bash
events
├── event.go
```
2024-06-09 11:31:59 +02:00
### handlers
The `handlers` directory contains the main handlers or controllers for the project. These handlers handle incoming requests, perform necessary actions, and return appropriate responses. They encapsulate the business logic and interact with other components of the project, such as services and data repositories.
It is important to note that the project structure described here may not include all the directories and files present in the actual project. The provided overview focuses on the key directories relevant to understanding the structure and organization of the project.
2024-06-09 11:31:59 +02:00
### types
The `types` directory contains all your type related files. For example, you can define your models, structs, and interfaces in this directory. The `types` directory is structured as follows:
```bash
types
├── user.go
├── auth.go
```
2024-06-09 11:31:59 +02:00
### views
The `views` directory contains all your view related files. These files are used to render HTML templates for the project. The `views` directory is structured as follows:
```bash
views
├── home.go
├── about.go
```
2024-06-09 11:16:23 +02:00
## Development server
2024-06-11 21:12:12 +02:00
You can run the development server with the following command:
```bash
2024-06-09 11:16:23 +02:00
make dev
2024-06-08 11:02:51 +02:00
```
2024-06-09 11:16:23 +02:00
## Hot reloading the browser
2024-06-09 11:16:23 +02:00
Hot reloading is configured by default when running your application in development.
> NOTE: on windows or on in my case (WSL2) you might need to run `make watch-assets` in another terminal to watch for CSS and JS file changes.
2024-06-09 11:16:23 +02:00
## Migrations
### Create a new migration
```bash
2024-06-11 21:12:12 +02:00
make db-mig-create add_users_table
2024-06-07 09:24:46 +02:00
```
2024-06-11 21:12:12 +02:00
The command will create a new migration SQL file located at `app/db/migrations/add_users_table.sql`
2024-06-09 11:16:23 +02:00
### Migrate the database
```bash
2024-06-07 09:24:46 +02:00
make db-up
```
### Reset the database
```bash
2024-06-07 09:24:46 +02:00
make db-reset
```
2024-06-09 11:16:23 +02:00
## Seeds
```bash
2024-06-07 09:24:46 +02:00
make db-seed
```
2024-06-11 21:12:12 +02:00
This command will run the seed file located at `cmd/scripts/seed/main.go`
## Creating views with Templ
2024-06-16 17:59:28 +02:00
superkit uses Templ as its templating engine. Templ allows you to create type safe view components that renders fragments of HTML. In-depth information about Templ can be found here:
2024-06-11 21:12:12 +02:00
[Templ documentation](https://templ.guide)
2024-06-07 09:24:46 +02:00
## Validations
2024-06-11 21:12:12 +02:00
todo
2024-06-07 09:24:46 +02:00
## Testing
### Testing handlers
## Create a production release
2024-06-07 09:24:46 +02:00
2024-06-16 17:59:28 +02:00
superkit will compile your whole application including its assets into a single binary. To build your application for production you can run the following command:
```bash
2024-06-09 11:31:59 +02:00
make build
```
2024-06-11 21:12:12 +02:00
This will create a binary file located at `/bin/app_prod`.
2024-06-09 11:31:59 +02:00
Make sure you also set the correct application environment variable in your `.env` file.
```bash
2024-06-15 17:34:19 +02:00
SUPERKIT_ENV = production
2024-06-09 11:31:59 +02:00
```