Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit c0c941c

Browse files
committed
feat(docs): enhance the documentation
1 parent c0c414c commit c0c941c

File tree

11 files changed

+738
-101
lines changed

11 files changed

+738
-101
lines changed

AGENTS.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,34 @@ This guide provides essential dev context for automated agents working in this r
1212
- **Test Coverage**: `make test-coverage`
1313
- **Linting**: Uses `go fmt` (strict gofmt style); no golangci-lint config by default
1414

15-
## 2. Code Style Guidelines
15+
## 2. Console Command System
16+
GoPlate features a powerful console command system for development tasks:
17+
18+
### Database Operations
19+
- **Run migrations**: `go run main.go console db:up`
20+
- **Check migration status**: `go run main.go console db:status`
21+
- **Rollback migration**: `go run main.go console db:down`
22+
- **Fresh migration**: `go run main.go console db:fresh`
23+
- **Create migration**: `go run main.go console db:create <name>`
24+
- **Run seeders**: `go run main.go console db:seed`
25+
26+
### Code Generation
27+
- **Generate model**: `go run main.go console make:model <ModelName>`
28+
- **Generate DTO**: `go run main.go console make:dto <DtoName>`
29+
- **Generate job**: `go run main.go console make:job <JobName>`
30+
- **Generate seeder**: `go run main.go console make:seeder <SeederName>`
31+
- **Generate cron job**: `go run main.go console make:cron <CronName>`
32+
33+
### Utility Commands
34+
- **List all commands**: `go run main.go console list`
35+
- **Run example**: `go run main.go console example`
36+
- **Interactive demo**: `go run main.go console interactive`
37+
38+
### Alternative Make Commands (Legacy)
39+
- **Database**: `make db-up`, `make db-down`, `make db-status`, `make db-fresh`
40+
- **Development**: `make dev`, `make run`, `make build`, `make clean`
41+
42+
## 3. Code Style Guidelines
1643
- **Imports**: Standard library, then third-party, then local imports (grouped, no blank lines between groups)
1744
- **Formatting**: Always use `gofmt`; tabs not spaces
1845
- **Types**: Prefer explicit struct field types; use `interface{}` or `any` sparingly (replace where modern Go suggests)
@@ -22,8 +49,15 @@ This guide provides essential dev context for automated agents working in this r
2249
- **Tests**: Standard `_test.go` files; assertions via Go testing or testify if added
2350
- **Env/config**: Managed via `env/` package and `.env` file
2451

25-
## 3. Project Structure
52+
## 4. Project Structure
2653
- App code is under `cmd/`, `pkg/`, `domains/`, `router/`
2754
- DB/migrations/seed in `db/`, utility code in `pkg/utils/`
55+
- Console commands in `pkg/console/commands/`
56+
57+
## 5. Custom Command Development
58+
To create new console commands:
59+
1. Create command file in `pkg/console/commands/`
60+
2. Implement `Command` interface with `GetSignature()`, `GetDescription()`, `Execute(args []string) error`
61+
3. Register in `pkg/console/commands.go` via `RegisterCommands()`
2862

2963
No Cursor or Copilot rules present. If new lint, type, or style guidelines are added, update this file accordingly.

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GoPlate
22

3-
A comprehensive Go-based REST API boilerplate with Fiber, GORM, background jobs, and task scheduling.
3+
A comprehensive Go-based REST API boilerplate with Fiber, GORM, powerful console commands, background jobs, and task scheduling.
44

55
## Quick Start
66

@@ -14,19 +14,30 @@ go mod tidy
1414
cp .env.example .env
1515
# Edit .env with your database settings
1616

17-
# Run migrations and start
18-
make db-up
17+
# Run migrations and start (using console commands)
18+
go run main.go console db:up
1919
make dev
20+
21+
# Or use traditional make commands
22+
# make db-up
23+
# make dev
2024
```
2125

2226
## Key Commands
2327

28+
### Console Commands (Recommended)
29+
```bash
30+
go run main.go console list # List all available commands
31+
go run main.go console db:up # Run database migrations
32+
go run main.go console make:model User # Generate new model
33+
go run main.go console make:dto UserDto # Generate new DTO
34+
```
35+
36+
### Make Commands
2437
```bash
2538
make dev # Development server with hot reload
2639
make build # Build application
2740
make test # Run tests
28-
make db-create # Create migration
29-
make model # Generate model
3041
```
3142

3243
## Documentation
@@ -35,6 +46,7 @@ Complete documentation is available in the [docs/](docs/) directory:
3546

3647
- [Installation](docs/installation.md)
3748
- [Quick Start](docs/quick-start.md)
49+
- [Console Commands](docs/console-commands.md) - **New!** Powerful development tools
3850
- [Configuration](docs/configuration.md)
3951
- [Database](docs/database.md)
4052
- [API Reference](docs/api-reference.md)

docs/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ GoPlate is a comprehensive Go boilerplate that provides everything you need to b
2828

2929
### 🛠️ Developer Experience
3030
- Hot reload development server
31-
- Comprehensive CLI tools via Makefile
32-
- Code generation for models, DTOs, and more
31+
- **Powerful Console Command System** for code generation and database operations
32+
- Comprehensive CLI tools via Makefile and console commands
33+
- Code generation for models, DTOs, jobs, and seeders
3334
- Structured logging with file rotation
3435
- Test coverage reporting
3536

@@ -64,6 +65,20 @@ func (c *Controller) GetUsers(ctx *fiber.Ctx) error {
6465
}
6566
```
6667

68+
**Console Commands in Action:**
69+
```bash
70+
# Generate code with ease
71+
go run main.go console make:model User
72+
go run main.go console make:dto UserDto
73+
74+
# Manage database effortlessly
75+
go run main.go console db:up
76+
go run main.go console db:seed
77+
78+
# List all available commands
79+
go run main.go console list
80+
```
81+
6782
## Architecture Highlights
6883

6984
- **MVC Pattern**: Clean separation between Models, Views, and Controllers
@@ -88,8 +103,9 @@ Ready to build something amazing? Let's get you started:
88103

89104
1. **[Quick Start](/quick-start)** - Get up and running in minutes
90105
2. **[Installation](/installation)** - Detailed installation guide
91-
3. **[Configuration](/configuration)** - Configure your environment
92-
4. **[Project Structure](/project-structure)** - Understand the codebase
106+
3. **[Console Commands](/console-commands)** - Powerful development tools
107+
4. **[Configuration](/configuration)** - Configure your environment
108+
5. **[Project Structure](/project-structure)** - Understand the codebase
93109

94110
## Community & Support
95111

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- **Development**
88
- [Project Structure](/project-structure)
9+
- [Console Commands](/console-commands)
910
- [Database](/database)
1011
- [Routing](/routings)
1112
- [DTOs & Validation](/validation-and-dto)

docs/background-tasks.md

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The background task system consists of:
99
- **Job Queue**: Database-backed queue for persistent job storage
1010
- **Worker Pool**: Configurable number of workers processing jobs concurrently
1111
- **Job Registry**: Type-safe job registration and resolution
12+
- **Console Commands**: Easy job generation and management via CLI
1213
- **Retry Logic**: Automatic retry with exponential backoff
1314
- **Job States**: Track job lifecycle from pending to completion
1415

@@ -27,6 +28,60 @@ type Job interface {
2728

2829
## Creating Jobs
2930

31+
### Generating Jobs with Console Commands
32+
33+
Use the console command system to quickly generate new background jobs:
34+
35+
```bash
36+
# Generate a new job
37+
go run main.go console make:job EmailJob
38+
39+
# Generate job with specific name
40+
go run main.go console make:job ProcessPaymentJob
41+
42+
# Generate multiple jobs
43+
go run main.go console make:job ImageProcessorJob
44+
go run main.go console make:job NotificationJob
45+
46+
# List all available make commands
47+
go run main.go console list | grep "make:"
48+
```
49+
50+
**Generated job example:**
51+
```go
52+
// pkg/queue/jobs/email_job.go
53+
package jobs
54+
55+
import (
56+
"encoding/json"
57+
"time"
58+
"github.com/sheenazien8/goplate/pkg/queue"
59+
)
60+
61+
type EmailJob struct{}
62+
63+
func (j EmailJob) Type() string {
64+
return "email_job"
65+
}
66+
67+
func (j EmailJob) Handle(payload json.RawMessage) error {
68+
// Add your job logic here
69+
return nil
70+
}
71+
72+
func (j EmailJob) MaxAttempts() int {
73+
return 3
74+
}
75+
76+
func (j EmailJob) RetryAfter() time.Duration {
77+
return 30 * time.Second
78+
}
79+
80+
func init() {
81+
queue.RegisterJob(EmailJob{})
82+
}
83+
```
84+
3085
### Basic Job Example
3186

3287
```go
@@ -79,6 +134,9 @@ func init() {
79134
}
80135
```
81136

137+
**Note**: When you generate a job using `go run main.go console make:job`, the job is automatically registered via the `init()` function.
138+
```
139+
82140
### Advanced Job Example
83141
84142
```go
@@ -151,6 +209,32 @@ func init() {
151209
}
152210
```
153211

212+
### Custom Job Development Workflow
213+
214+
1. **Generate the job structure**:
215+
```bash
216+
go run main.go console make:job ImageProcessorJob
217+
```
218+
219+
2. **Implement the job logic** in the generated file:
220+
```go
221+
func (j ImageProcessorJob) Handle(payload json.RawMessage) error {
222+
// Your custom business logic here
223+
return nil
224+
}
225+
```
226+
227+
3. **Configure retry behavior**:
228+
```go
229+
func (j ImageProcessorJob) MaxAttempts() int {
230+
return 5 // Customize based on your needs
231+
}
232+
233+
func (j ImageProcessorJob) RetryAfter() time.Duration {
234+
return 1 * time.Minute // Customize retry delay
235+
}
236+
```
237+
154238
## Dispatching Jobs
155239

156240
### From Controllers
@@ -330,6 +414,12 @@ func TestJobDispatchAndProcessing(t *testing.T) {
330414

331415
## Best Practices
332416

417+
### Job Development with Console Commands
418+
419+
1. **Use code generation** - Always start with `go run main.go console make:job` for consistency
420+
2. **Follow naming conventions** - Use descriptive job names like `ProcessPaymentJob`, `SendEmailJob`
421+
3. **One job per file** - Each job should have its own file in `pkg/queue/jobs/`
422+
333423
### Job Design
334424

335425
1. **Keep jobs idempotent** - Jobs should be safe to run multiple times
@@ -353,9 +443,29 @@ func TestJobDispatchAndProcessing(t *testing.T) {
353443

354444
---
355445

446+
## Development Workflow Summary
447+
448+
1. **Generate job**: `go run main.go console make:job YourJobName`
449+
2. **Implement logic**: Add your business logic to the `Handle()` method
450+
3. **Configure retries**: Set appropriate `MaxAttempts()` and `RetryAfter()` values
451+
4. **Test thoroughly**: Write unit tests for your job logic
452+
5. **Deploy and monitor**: Use logging to track job performance
453+
454+
## Console Commands Reference
455+
456+
```bash
457+
# Job Development
458+
go run main.go console make:job <JobName> # Generate new background job
459+
go run main.go console list # List all available commands
460+
461+
# Related Commands
462+
go run main.go console make:cron <CronName> # Generate CRON job
463+
go run main.go console db:seed # Run database seeders
464+
```
465+
356466
## Next Steps
357467

358-
- **[Task Scheduler](/task-scheduler)** - Learn about CRON-based scheduling
359-
- **[Logging](/logging)** - Implement proper job logging
360-
- **[Performance](/performance)** - Optimize job processing
468+
- **[Console Commands](/console-commands)** - Master the command-line tools
469+
- **[Task Scheduler](/task-scheduler)** - Learn about CRON-based scheduling
470+
- **[Database](/database)** - Understand job storage and models
361471
- **[Examples](/examples/jobs)** - See complete job examples

0 commit comments

Comments
 (0)