fastschema

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 31 Imported by: 7

README

FastSchema

Go.Dev reference go report card codecov test status MIT license

FastSchema is a Go web framework and headless CMS for building dynamic web applications. Designed to simplify the creation and management of structured content, FastSchema automates the generation of databases and provides CRUD APIs effortlessly.

Try it out

Launch a headless CMS in seconds or utilize as a web framework.

Run the Docker Container:

docker pull ghcr.io/fastschema/fastschema:latest
docker run \
  -p 8000:8000 \
  -v ./data:/fastschema/data \
  ghcr.io/fastschema/fastschema:latest

Example output:

> APP_KEY is not set. A new key is generated and saved to /fastschema/data/.env
> Using the default sqlite db file path: /fastschema/data/fastschema.db
> Visit the following URL to setup the app: http://localhost:8000/dash/setup/?token=lUDRgoTUUNDsjCcitgGFTqwMZQPmYvlU

Now you can access to the FastSchema setup page by visiting http://localhost:8000/setup?token={token} (The setup token is displayed in the terminal).

Note: FastSchema is currently in beta and under active development. We welcome feedback, contributions, and suggestions from the community to help improve the platform and make it more robust and feature-rich.

Overview

FastSchema core features are built on top of schema, a blueprint that outlines the structure of your content. This schema acts as the foundation upon which FastSchema builds your database tables and API endpoints, streamlining the development process and allowing you to focus on creating rich, dynamic content.

FastSchema Overview

Use Cases

  • A Headless CMS (No-Code Solution)

    FastSchema is an ideal solution for building headless CMS applications that require dynamic content modeling without writing a line of code.

    It is designed to support API-first development, allowing you to define your content models and generate RESTful APIs effortlessly.

    With two line of commands, you can create a new project, define your content models, and start creating content instantly.

  • A Framework for web development

    FastSchema is designed to be used as a framework for building web applications. It provides a set of tools and packages that simplify the development process.

    Resource is a core concept that represents an access point to your data. By defining resources, you can create custom endpoints and customize the behavior of your APIs.

    Hooks are functions that are executed before or after an operation is performed on a resource. A Hook can be a resolver hook, database hook, or application hook. They allow you to add custom logic to your APIs and extend the functionality of FastSchema.

    ORM is a powerful tool that simplifies the interaction with your database. It provides a set of methods for querying, creating, updating, and deleting records in your database.

Web Framework

package main

import (
	"fmt"
	"log"

	"github.com/fastschema/fastschema"
	"github.com/fastschema/fastschema/db"
	"github.com/fastschema/fastschema/fs"
)

func main() {
	app, _ := fastschema.New(&fs.Config{
		SystemSchemas: []any{Tag{}, Blog{}},
	})

	app.API().Add(fs.Post("/blogvote", func(c fs.Context, vote *Payload) (*Response, error) {
		_, err := db.Mutation[Blog](app.DB()).
			Where(db.EQ("id", vote.ID)).
			Update(c.Context(), fs.Map{
				"$expr": fs.Map{"vote": "vote + 1"},
			})

		return &Response{
			Success: err == nil,
			Message: fmt.Sprintf("Vote for %d: %v", vote.ID, err),
		}, nil
	}))

	log.Fatal(app.Start())
}

Features

Fastschema offers a comprehensive suite of features designed to streamline and simplify the process of building and managing dynamic web applications.

  • Automated Database Generation: FastSchema automatically generates the necessary database tables based on your schema definition with flexible relationships model, eliminating the need for manual setup.

  • RESTful API Generation: RESTful APIs are automatically generated based on the schema definition. Whenever you create or update a schema, the corresponding API endpoints are updated accordingly.

  • Dynamic Content Modeling: Easily create and modify content models through the intuitive admin UI, with changes reflected instantly in the schema definition file.

  • Built-in File Management: FastSchema provides a built-in file manager to manage media assets, enabling you to upload, organize, and serve files seamlessly.

  • Built-in Admin Control Panel: FastSchema comes with a built-in admin control panel that allows you to manage content, users, manage permissions, and more.

  • Database Support: MySQL, PostgreSQL, SQLite.

  • Role-Based Access Control: Define roles and permissions to control access to content and features.

  • OpenAPI Specification (OAS) Generation: FastSchema automatically generates OpenAPI Specification (OAS) documentation for your APIs, making it easy to understand and consume your APIs.

  • Extensible and Flexible: Extend and customize FastSchema with Go code, build extensive features by leveraging the power of Resources, Hooks, ORM, and more.

  • Real-time Updates: FastSchema supports real-time updates, allowing you to build dynamic web applications that update in real-time without the need for manual refresh.

Documentation

For more information on how to get started with FastSchema, check out our documentation.

Roadmap

  • Improve documentation and testing.
  • Add auth provider.
  • OpenAPI generator.
  • Real-time updates.
  • Plugin system.
  • GraphQL support.
  • Webhooks.
  • Client SDKs.
    • JavaScript SDK.

Testing

FastSchema comes with a suite of automated tests to ensure the stability and reliability of the platform.

Fastschema come with integration tests that require a database connection. You can use the following command to create DB containers.

cd tests/integration
docker compose up -d

To run the tests, execute the following command:

go test ./...

You can skip the integration tests by running tests for packages only.

./tests/test.sh ./schema

Dependencies

FastSchema is built using the Go programming language and leverages a number of open-source libraries to provide its core functionality. Some of the key dependencies include:

Contributing

We welcome contributions from the community and encourage developers to get involved in the project. Whether you're a seasoned developer or just getting started, there are plenty of ways to contribute to FastSchema.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(config *fs.Config) (_ *App, err error)

func (*App) API added in v0.0.5

func (a *App) API() *fs.Resource

func (*App) AddMiddlewares

func (a *App) AddMiddlewares(middlewares ...fs.Middleware)

func (*App) AddResource

func (a *App) AddResource(resource *fs.Resource)

func (*App) CWD added in v0.1.0

func (a *App) CWD() string

func (*App) Config added in v0.0.5

func (a *App) Config() *fs.Config

func (*App) CreateOpenAPISpec added in v0.1.0

func (a *App) CreateOpenAPISpec(overrides ...bool) ([]byte, error)

CreateOpenAPISpec generates the openapi spec for the app.

func (*App) DB

func (a *App) DB() db.Client

func (*App) Dir added in v0.0.5

func (a *App) Dir() string

func (*App) Disk

func (a *App) Disk(names ...string) fs.Disk

func (*App) Disks added in v0.0.5

func (a *App) Disks() []fs.Disk

func (*App) GetAuthProvider added in v0.2.0

func (a *App) GetAuthProvider(name string) fs.AuthProvider

func (*App) GetSetupToken added in v0.3.0

func (a *App) GetSetupToken(ctx context.Context) (string, error)

func (*App) Hooks

func (a *App) Hooks() *fs.Hooks

func (*App) Key

func (a *App) Key() string

func (*App) Logger

func (a *App) Logger() logger.Logger

func (*App) OnPostDBCreate added in v0.3.0

func (a *App) OnPostDBCreate(hooks ...db.PostDBCreate)

func (*App) OnPostDBDelete added in v0.3.0

func (a *App) OnPostDBDelete(hooks ...db.PostDBDelete)

func (*App) OnPostDBGet added in v0.0.5

func (a *App) OnPostDBGet(hooks ...db.PostDBGet)

func (*App) OnPostDBUpdate added in v0.3.0

func (a *App) OnPostDBUpdate(hooks ...db.PostDBUpdate)

func (*App) OnPostResolve added in v0.0.5

func (a *App) OnPostResolve(middlewares ...fs.Middleware)

func (*App) OnPreResolve added in v0.0.5

func (a *App) OnPreResolve(middlewares ...fs.Middleware)

func (*App) Reload

func (a *App) Reload(ctx context.Context, migration *db.Migration) (err error)

func (*App) Resources

func (a *App) Resources() *fs.ResourcesManager

func (*App) Roles

func (a *App) Roles() []*fs.Role

func (*App) SchemaBuilder

func (a *App) SchemaBuilder() *schema.Builder

func (*App) Shutdown added in v0.1.0

func (a *App) Shutdown() error

func (*App) Start

func (a *App) Start() error

func (*App) UpdateCache

func (a *App) UpdateCache(ctx context.Context) (err error)

UpdateCache updates the application cache. It fetches all roles from the database and stores them in the cache.

Directories

Path Synopsis
examples
database command
hooks command
logging command
relations command
resource command
storage command
pkg
services

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL