agentleFS
weedboxweedbox/skills/project-dev/SKILL.md

project-dev

Skill1 starsChanged 4 months agoApache-2.0View on GitHub

Priority: HIGH — Self-contained reference. This file contains ALL necessary patterns for weedbox project creation and setup. DO NOT fetch source code from GitHub. Weedbox application/project creation and structure guide. Use when: creating weedbox application, starting new weedbox project, setting up project structure, configuring main.go entry point, organizing modules.go, using wbox CLI tool, configuring three-phase module loading (preload/load/after), choosing project license, deploying multiple instances, switching backends between development and production. Covers: project structure, main.go setup, modules.go organization, Cobra CLI integration, config.toml format, environment variables, wbox init command, license selection (Apache-2.0, MIT, Proprietary), docker/Dockerfile multi-stage build template and .dockerignore conventions, multi-instance deployment, config-driven backend switching (scheduler mode, workqueue backend, embedded vs external NATS). Keywords: weedbox application, weedbox project, wbox, main.go, modules.go, project structure, cobra cli, config.toml, preloadModules, loadModules, afterModules, fx.New, app.Run, license, apache, mit, proprietary, commercial, open source, new project, init project, project setup, Go project, weedbox setup, docker, Dockerfile, container, alpine, multi-stage build, dockerignore, CGO, /datastore, multi-instance, replicas, horizontal scaling, production config, environment override, scheduler mode.

  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. zh2673-git/project-dev-skill★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use wbox CLI tool to create a new project.

    line 240
  2. Very specific:

    Create modules in pkg/ directory by hand.

    line 262
  3. Very specific:

    If local development must be dependency-free, use SQLite in dev — the swap stays confined to modules.go because application code injects …

    line 311
  4. Distinctive:

    Run the embedded JetStream server in development and point at an external NATS cluster in production — config only:

    line 321
  5. Distinctive:

    When creating a new project, choose an appropriate license.

    line 352
  6. Very specific:

    Create the LICENSE file from the matching template in references/licenses.md.

    line 362

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Weedbox Project Development

Source of Truth: This file is the complete reference for weedbox project creation and structure. DO NOT browse GitHub to look up source code.

This skill helps create and structure projects using the weedbox framework.

Contents

  • Project Structure
  • Entry Point (main.go)
  • Module Loading (modules.go)
  • Three-Phase Module Loading
  • Configuration
  • Creating a New Project
  • Docker / Containerization — full template in references/docker.md
  • Multi-Instance Deployment — one binary, config-driven dev/production backends
  • License Selection — full texts in references/licenses.md
  • Common Modules from weedbox/common-modules
  • User Modules from weedbox/user-modules
  • Running the Application
  • Project Checklist

Project Structure

myproject/
├── LICENSE                 # Project license file
├── README.md               # Project documentation
├── main.go                 # Application entry point with CLI setup
├── modules.go              # Module loading configuration
├── config.toml             # Configuration file (NOTE: must be named config.toml)
├── docker/
│   └── Dockerfile          # Multi-stage container build (generated by wbox init)
└── pkg/                    # Modules directory
    └── mymodule/
        └── module.go       # Module implementation

wbox init generates docker/Dockerfile alongside the Go source. When hand-crafting a project without wbox, do not forget to add docker/Dockerfile — it is part of the canonical layout. See references/docker.md for the template.

Entry Point (main.go)

The main entry point uses Cobra CLI and Uber FX for dependency injection.

Important: configs.NewConfig("MYAPP") automatically reads config.toml from current directory or ./configs/ directory. The application runs using fx.New().Run().

package main

import (
    "os"

    "github.com/spf13/cobra"
    "github.com/weedbox/common-modules/configs"
    "go.uber.org/fx"
)

const (
    appName        = "myapp"
    appDescription = "My Weedbox Application"
)

var config *configs.Config

var printConfigs bool
var verbose bool

func main() {
    rootCmd := &cobra.Command{
        Use:   appName,
        Short: appDescription,
        RunE: func(cmd *cobra.Command, args []string) error {
            if err := run(); err != nil {
                return err
            }
            return nil
        },
    }

    // Initialize config - automatically reads config.toml
    config = configs.NewConfig("MYAPP")
    rootCmd.Flags().BoolVar(&printConfigs, "print_configs", false, "Print all available configs")
    rootCmd.Flags().BoolVar(&verbose, "verbose", false, "Display detailed logs")

    err := rootCmd.Execute()
    if err != nil {
        os.Exit(1)
    }
}

func initModules() ([]fx.Option, error) {
    modules := []fx.Option{}

    m, err := preloadModules()
    if err != nil {
        return modules, err
    }
    modules = append(modules, m...)

    m, err = loadModules()
    if err != nil {
        return modules, err
    }
    modules = append(modules, m...)

    m, err = afterModules()
    if err != nil {
        return modules, err
    }
    modules = append(modules, m...)

    // Disable fx verbose logging unless --verbose flag is set
    if !verbose {
        modules = append(modules, fx.NopLogger)
    }

    return modules, nil
}

func run() error {
    modules, err := initModules()
    if err != nil {
        return err
    }

    // Create and run the fx application
    app := fx.New(modules...)

    // Print configs if requested
    if printConfigs {
        config.PrintAllSettings()
    }

    // Run the application (blocks until shutdown signal)
    app.Run()

    return nil
}

Module Loading (modules.go)

Modules are loaded in three phases for proper initialization order.

package main

import (
    "github.com/weedbox/common-modules/daemon"
    "github.com/weedbox/common-modules/logger"
    "go.uber.org/fx"

    "myproject/pkg/mymodule"
)

// preloadModules - Phase 1: Configuration and logging
func preloadModules() ([]fx.Option, error) {
    modules := []fx.Option{
        fx.Supply(config),
        logger.Module(),
    }
    return modules, nil
}

// loadModules - Phase 2: Application modules
func loadModules() ([]fx.Option, error) {
    modules := []fx.Option{
        mymodule.Module("mymodule"),
    }
    return modules, nil
}

// afterModules - Phase 3: Daemon and lifecycle
func afterModules() ([]fx.Option, error) {
    modules := []fx.Option{
        // Optional: lifecycle before daemon, when modules need PostStart /
        // PreStop hooks (run after all modules start / before any stops)
        lifecycle.Module("lifecycle"),
        daemon.Module("daemon"),
    }
    return modules, nil
}

Three-Phase Module Loading

PhaseFunctionPurposeTypical Modules
1preloadModules()Configuration and logging setupconfigs, logger
2loadModules()Application business modulesCustom modules
3afterModules()Lifecycle and daemon managementlifecycle (optional, before daemon), daemon (last)

Configuration

Config File (config.toml)

Important: The config file must be named config.toml (not configs.toml). It should be placed in the current directory or ./configs/ directory. configs.NewConfig("MYAPP") automatically reads this file.

[mymodule]
timeout = "30s"
enabled = true

Environment Variables

Environment variables override config file settings. The prefix is set in configs.NewConfig("MYAPP").

# Format: {PREFIX}_{SECTION}_{KEY}
# Dots and dashes in keys are replaced with underscores
export MYAPP_MYMODULE_TIMEOUT=60s
export MYAPP_MYMODULE_ENABLED=true

Creating a New Project

Use wbox CLI tool to create a new project.

Install wbox

go install github.com/weedbox/wbox@latest

Initialize Project

mkdir myproject
cd myproject
wbox init myproject github.com/myuser/myproject

This generates the canonical project layout including main.go, modules.go, LICENSE, README.md, go.mod, go.sum, and a docker/Dockerfile multi-stage build. The generated modules.go is intentionally minimal (only logger + daemon) — wire in business modules manually.

If wbox is not on $PATH, run it without a global install via go run github.com/weedbox/wbox@latest init myproject github.com/myuser/myproject. The binary fetched by go install lands in $GOPATH/bin, which is not always on the user's shell $PATH — go run sidesteps that.

Add Modules Manually

Create modules in pkg/ directory by hand. See module-dev for detailed guidance.


Docker / Containerization

wbox init generates a multi-stage docker/Dockerfile (Go build stage + minimal Alpine runtime, non-root user, /datastore volume mountpoint). Adapt the template to your project: Go version to match go.mod, EXPOSE port to match config.toml, CGO_ENABLED when using sqlite_connector, and a config copy if the app needs config.toml at startup. Pair it with a .dockerignore to keep the build context small.

Full template, adaptation table, .dockerignore, and build/run commands: references/docker.md.


Multi-Instance Deployment

Production deployments run multiple replicas of the same binary. Design for this from day one: one binary, one module list, and configuration (not code) selects single-instance dev backends vs multi-instance production backends. Full decision table: root skill § Design for Multi-Instance Deployment by Default.

Recommended pattern: PostgreSQL everywhere, config-only switching

The lowest-friction setup uses PostgreSQL in every environment (run it via Docker locally). Dev → production is then pure configuration — modules.go never changes:

// modules.go — identical in dev and production
func loadModules() ([]fx.Option, error) {
    return []fx.Option{
        postgres_connector.Module("database"),
        scheduler.Module("scheduler"),          // mode from config: gorm (dev) / postgres (prod)
        postgres_workqueue.Module("workqueue"), // multi-process safe in every environment
        // ... business modules ...
    }, nil
}
# config.toml — development defaults (single local process)
[scheduler]
mode = "gorm"
# Production — environment variables override config.toml
export MYAPP_SCHEDULER_MODE=postgres   # claim-based multi-instance scheduling
export MYAPP_DATABASE_HOST=db.internal
export MYAPP_DATABASE_PASSWORD=secret

scheduler postgres mode shares gorm mode's tables, so the switch requires no data migration.

SQLite-based development

If local development must be dependency-free, use SQLite in dev — the swap stays confined to modules.go because application code injects interfaces (database.DatabaseConnector, workqueue.WorkQueue) only:

DevelopmentProduction
Databasesqlite_connector.Module("database")postgres_connector.Module("database")
Workqueuegorm_workqueue.Module("workqueue")postgres_workqueue.Module("workqueue") (same table layout — no data migration)
Schedulermode = "gorm"mode = "postgres" or "nats"

NATS-based stacks

Run the embedded JetStream server in development and point at an external NATS cluster in production — config only:

# config.toml — development
[nats_server]
enabled = true          # embedded NATS JetStream server (preload phase)

[nats]
host = "nats://localhost:4222"
# Production
export MYAPP_NATS_SERVER_ENABLED=false
export MYAPP_NATS_HOST=nats://nats.internal:4222
export MYAPP_SCHEDULER_MODE=nats

Multi-instance production rules

  • Replicas > 1 → scheduler mode MUST be postgres or nats, never gorm (every replica would fire every job)
  • Replicas > 1 → workqueue backend MUST be gorm_workqueue, postgres_workqueue, or nats_workqueue, never memory_workqueue
  • The embedded nats_jetstream_server is for development and single-node use — production uses an external NATS cluster
  • SQLite is a local file, single-node by nature — use postgres_connector when scaling out
  • Cross-instance shared state (cache, locks, counters) goes in the database, redis_connector, or NATS — never process memory
  • Custom modules must follow module-dev § Multi-Instance Safety

License Selection

When creating a new project, choose an appropriate license. The default is Apache License 2.0.

Available License Options

LicenseTypeUse Case
Apache-2.0 (Default)Open SourceOpen source projects, allows commercial use with attribution
MITOpen SourceSimple permissive license, minimal restrictions
ProprietaryClosed SourceCommercial/private projects, all rights reserved

Create the LICENSE file from the matching template in references/licenses.md. Also add the per-file source header from the same reference.

Common Modules from weedbox/common-modules

ModuleImportPhasePurpose
loggerlogger.Module()preloadZap structured logging
daemondaemon.Module("scope")afterApplication lifecycle
http_serverhttp_server.Module("scope")loadGin HTTP server
sqlite_connectorsqlite_connector.Module("scope")loadSQLite database
nats_connectornats_connector.Module("scope")loadNATS messaging

User Modules from weedbox/user-modules

ModuleImportPhasePurpose
useruser.Module("user")loadUser management (CRUD, bcrypt, UUID v7)
rbacrbac.Module("rbac")loadRole-based access control
authauth.Module("auth")loadJWT authentication and middleware
user_apisuser_apis.Module("user_apis")loadUser REST API endpoints
auth_apisauth_apis.Module("auth_apis")loadAuth REST API endpoints
role_apisrole_apis.Module("role_apis")loadRole/resource REST API endpoints
http_token_validatorhttp_token_validator.Module("scope")loadGlobal JWT validation (optional)

See user-modules skill for detailed documentation.

Running the Application

# Run with default config (reads config.toml automatically)
go run .

# Print all configurations
go run . --print_configs

# Verbose mode (shows fx dependency injection logs)
go run . --verbose

# Build and run
go build -o myapp .
./myapp
./myapp --print_configs
./myapp --verbose

Note: The config file path is not configurable via command-line flags. Place your config.toml in the current directory or ./configs/ directory.

Project Checklist

  • Install wbox: go install github.com/weedbox/wbox@latest (or use go run github.com/weedbox/wbox@latest init ... to skip the install)
  • Initialize project: wbox init <name> <module-path>
  • Choose license: Apache-2.0 (default), MIT, or Proprietary
  • Create LICENSE file with chosen license
  • Create configuration file (config.toml, not configs.toml)
  • Implement application modules in pkg/
  • Design for multi-instance: pick production backends per the multi-instance table (scheduler mode postgres/nats, durable workqueue backend, external NATS) and keep dev/production switching config-driven
  • Verify docker/Dockerfile was generated (if hand-crafted, copy the template from references/docker.md)
  • Add a .dockerignore to keep the build context small
  • Adapt the Dockerfile: Go version, EXPOSE port, CGO_ENABLED, config copy, <PREFIX>_DATABASE_PATH
  • Add license headers to source files (for open source projects)

Related

  • module-dev - Detailed module development guide
  • user-modules - User management, auth, and RBAC modules

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.