Skip to content

[init] add modules#1

Merged
capcom6 merged 1 commit into
masterfrom
init/add-modules
Apr 8, 2026
Merged

[init] add modules#1
capcom6 merged 1 commit into
masterfrom
init/add-modules

Conversation

@capcom6
Copy link
Copy Markdown
Contributor

@capcom6 capcom6 commented Apr 8, 2026

Summary by CodeRabbit

  • New Features
    • Added database support: connection pooling, migrations (embedded), timestamped models, and unique-constraint error helper.
  • Removals
    • Removed Telegram bot support and related configuration.
  • Documentation
    • Added a repository-level dev-docs reference.
  • Chores
    • Disabled benchmark job in CI workflow.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

Repository module renamed to github.com/bit-issues/backend; Telegram/bot subsystem removed; database support added (Goose migrations, Bun ORM, MySQL driver) with Fx wiring; configuration switched from Telegram to Database settings; a CI benchmark job disabled; a repo-root dev-docs file added.

Changes

Cohort / File(s) Summary
Project rename & docs
dev-docs, main.go, internal/server/module.go
Added dev-docs; updated module/import paths to github.com/bit-issues/backend.
Go module & deps
go.mod
Changed module path; removed Telegram/bot deps; added Bun/Goose/MySQL/sqlfx/bunfx/goosefx/validatorfx and bumped various indirect deps.
App & DI wiring
internal/app.go, internal/config/module.go
Rewired Fx graph: enabled bunfx/sqlfx/goosefx/validatorfx and db.Module(); replaced telegofx config provider with sqlfx.Config wired from cfg.Database.
Configuration
internal/config/config.go
Replaced Telegram config with Database config block and updated Default() to include DB defaults and timing fields.
Bot removal
internal/bot/...
internal/bot/handler/handler.go, internal/bot/handlers/start/handler.go, internal/bot/module.go
Removed bot package: handler interface, start handler, and bot Fx module and related registration logic.
Database additions
internal/db/module.go, internal/db/errors.go, internal/db/models.go, internal/db/migrations/embed.go, internal/db/migrations/20260204013005_initial.sql
Added db.Module() Fx submodule, MySQL error helper IsUniqueViolation, TimedModel, embedded migrations FS, initial Goose SQL migration, and registered MySQL driver/dialects.
CI workflow tweak
.github/workflows/go.yml
Disabled benchmark job by adding if: false.

Sequence Diagram(s)

sequenceDiagram
    participant App as App (main)
    participant Fx as Fx container
    participant DBModule as db.Module
    participant Goose as Goose (goosefx)
    participant Bun as Bun ORM / sqlfx

    rect rgba(0,128,0,0.5)
    App->>Fx: Start application (internal.Run)
    Fx->>DBModule: Construct db.Module()
    end

    rect rgba(0,0,255,0.5)
    DBModule->>Goose: Provide migration storage (migrations.FS) & dialect
    DBModule->>Bun: Provide mysqldialect and driver registration
    end

    rect rgba(128,0,128,0.5)
    Fx->>Goose: Run migrations on startup (goosefx)
    Fx->>Bun: Initialize DB connection pool (sqlfx/bunfx)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title '[init] add modules' is vague and generic, failing to clearly describe the primary changes in this comprehensive refactoring that includes module reorganization, dependency updates, bot feature removal, and database infrastructure addition. Use a more descriptive title that captures the main scope, such as 'Refactor: migrate to database backend with SQL migrations and remove Telegram bot' or 'Init: restructure with database modules and remove bot implementation'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
main.go (1)

8-8: Consider updating the contact URL in Swagger annotations.

The contact URL still references https://github.com/capcom6 while the module has been renamed to github.com/bit-issues/backend. Update this if the project contact has changed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@main.go` at line 8, Update the Swagger contact URL annotation (the commented
line starting with "@contact.url") to point to the current project/contact
location instead of "https://github.com/capcom6"; replace that value with the
new URL "https://github.com/bit-issues/backend" (or the correct contact URL) in
the annotation so the Swagger docs reflect the renamed module.
internal/db/models.go (1)

5-8: Consider adding automatic timestamp management.

The TimedModel requires manual population of CreatedAt and UpdatedAt before insert/update. You could leverage Bun's hooks or model interface to auto-populate these fields.

Example with Bun hooks
package db

import (
	"context"
	"time"

	"github.com/uptrace/bun"
)

type TimedModel struct {
	CreatedAt time.Time `bun:",nullzero,notnull" json:"created_at"`
	UpdatedAt time.Time `bun:",nullzero,notnull" json:"updated_at"`
}

var _ bun.BeforeAppendModelHook = (*TimedModel)(nil)

func (m *TimedModel) BeforeAppendModel(ctx context.Context, query bun.Query) error {
	now := time.Now().UTC()
	switch query.(type) {
	case *bun.InsertQuery:
		if m.CreatedAt.IsZero() {
			m.CreatedAt = now
		}
		m.UpdatedAt = now
	case *bun.UpdateQuery:
		m.UpdatedAt = now
	}
	return nil
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/db/models.go` around lines 5 - 8, TimedModel currently requires
manual setting of CreatedAt/UpdatedAt; implement Bun's hook by making TimedModel
satisfy bun.BeforeAppendModelHook (e.g., add var _ bun.BeforeAppendModelHook =
(*TimedModel)(nil)) and implement BeforeAppendModel(ctx context.Context, query
bun.Query) to set now := time.Now().UTC(), set CreatedAt if zero and always
update UpdatedAt on InsertQuery, and set UpdatedAt on UpdateQuery so timestamps
are auto-managed for Insert/Update operations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dev-docs`:
- Line 1: The symlink named "dev-docs" points to "../dev-docs" but the target is
missing; either remove this broken symlink or recreate/relocate the target
directory at "../dev-docs" so the link resolves correctly—update the symlink
target or delete the link depending on whether the documentation directory
should exist, and confirm via ls -l that "dev-docs" is no longer broken.

In `@internal/db/errors.go`:
- Around line 5-11: IsUniqueViolation currently looks for SQLite text ("UNIQUE
constraint failed"); update it to detect MySQL duplicate-key errors by checking
for a mysql.MySQLError with Number == 1062 (using
github.com/go-sql-driver/mysql) and fall back to matching common text like
"Duplicate entry" for safety; ensure nil checks remain and avoid importing mysql
unconditionally if build constraints require it (i.e., update
internal/db/errors.go to type-assert err to *mysql.MySQLError in
IsUniqueViolation and return true for Number == 1062, otherwise check
strings.Contains(err.Error(), "Duplicate entry")).

In `@internal/db/migrations/20260204013005_initial.sql`:
- Around line 1-9: The migration file for version 20260204013005 currently only
runs SELECTs and will be marked applied by Goose, preventing future DDL from
taking effect; either replace the placeholder statements between the goose
markers (-- +goose Up / StatementBegin ... StatementEnd) with the actual initial
schema DDL (tables, indexes, constraints) so the Up section creates the schema
and the Down section drops it, or delete this migration entirely and create new
proper migrations later; locate the sections labeled "-- +goose Up" and "--
+goose Down" in the migration for version 20260204013005 and update or remove
them accordingly.
- Line 5: Remove the stray malformed separator `---` on line 5 which is not
valid Goose or SQL syntax; open the migration `20260204013005_initial.sql`,
delete the `---` line so the file only contains proper SQL and Goose directives
(use `-- +goose` for Goose directives and `--` for comments) ensuring no other
non-SQL tokens remain.

---

Nitpick comments:
In `@internal/db/models.go`:
- Around line 5-8: TimedModel currently requires manual setting of
CreatedAt/UpdatedAt; implement Bun's hook by making TimedModel satisfy
bun.BeforeAppendModelHook (e.g., add var _ bun.BeforeAppendModelHook =
(*TimedModel)(nil)) and implement BeforeAppendModel(ctx context.Context, query
bun.Query) to set now := time.Now().UTC(), set CreatedAt if zero and always
update UpdatedAt on InsertQuery, and set UpdatedAt on UpdateQuery so timestamps
are auto-managed for Insert/Update operations.

In `@main.go`:
- Line 8: Update the Swagger contact URL annotation (the commented line starting
with "@contact.url") to point to the current project/contact location instead of
"https://github.com/capcom6"; replace that value with the new URL
"https://github.com/bit-issues/backend" (or the correct contact URL) in the
annotation so the Swagger docs reflect the renamed module.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6cd10a41-05de-4a8d-83e2-802327152258

📥 Commits

Reviewing files that changed from the base of the PR and between 2ba853a and 6fe5ec2.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (15)
  • dev-docs
  • go.mod
  • internal/app.go
  • internal/bot/handler/handler.go
  • internal/bot/handlers/start/handler.go
  • internal/bot/module.go
  • internal/config/config.go
  • internal/config/module.go
  • internal/db/errors.go
  • internal/db/migrations/20260204013005_initial.sql
  • internal/db/migrations/embed.go
  • internal/db/models.go
  • internal/db/module.go
  • internal/server/module.go
  • main.go
💤 Files with no reviewable changes (3)
  • internal/bot/handler/handler.go
  • internal/bot/module.go
  • internal/bot/handlers/start/handler.go

Comment thread dev-docs
Comment thread internal/db/errors.go
Comment thread internal/db/migrations/20260204013005_initial.sql
Comment thread internal/db/migrations/20260204013005_initial.sql
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/go.yml (1)

77-80: Consider documenting why the benchmark job is disabled or removing it.

The if: false pattern leaves an entire job that will never run. Static analysis (actionlint) also flags this as a constant false condition.

If this is temporary during the module initialization phase, consider adding a comment explaining when it should be re-enabled. If the job is no longer needed, removing it entirely would reduce workflow maintenance burden.

💡 Option 1: Add a comment explaining the disable
 benchmark:
   name: Benchmark
   runs-on: ubuntu-latest
-  if: false
+  if: false # TODO: Re-enable once benchmark baseline is established for new modules
   permissions:
💡 Option 2: Remove the job entirely if not needed

If benchmarks are not planned for this project, consider removing the entire benchmark job (lines 77-132) to keep the workflow file clean.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/go.yml around lines 77 - 80, The benchmark job currently
has a constant disable via "if: false" which actionlint flags; either remove the
entire "benchmark" job block (job name: benchmark) if it's not needed, or keep
it but replace the unconditional "if: false" with a short inline comment
explaining why it's disabled and when to re-enable it (e.g., during module
initialization or when benchmarks are added) so reviewers and linters understand
the intent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/go.yml:
- Around line 77-80: The benchmark job currently has a constant disable via "if:
false" which actionlint flags; either remove the entire "benchmark" job block
(job name: benchmark) if it's not needed, or keep it but replace the
unconditional "if: false" with a short inline comment explaining why it's
disabled and when to re-enable it (e.g., during module initialization or when
benchmarks are added) so reviewers and linters understand the intent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92c3ee63-5320-49b0-9483-660bbedaeb90

📥 Commits

Reviewing files that changed from the base of the PR and between 6fe5ec2 and b2adcd7.

📒 Files selected for processing (2)
  • .github/workflows/go.yml
  • internal/db/errors.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/db/errors.go

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

🤖 Pull request artifacts

Platform File
🐳 Docker GitHub Container Registry
🍎 Darwin arm64 backend_Darwin_arm64.tar.gz
🍎 Darwin x86_64 backend_Darwin_x86_64.tar.gz
🐧 Linux arm64 backend_Linux_arm64.tar.gz
🐧 Linux i386 backend_Linux_i386.tar.gz
🐧 Linux x86_64 backend_Linux_x86_64.tar.gz
🪟 Windows arm64 backend_Windows_arm64.zip
🪟 Windows i386 backend_Windows_i386.zip
🪟 Windows x86_64 backend_Windows_x86_64.zip

@capcom6 capcom6 force-pushed the init/add-modules branch from b2adcd7 to 9d28083 Compare April 8, 2026 07:08
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/config/config.go (1)

45-59: ⚠️ Potential issue | 🟠 Major

Do not ship hardcoded DB credentials in defaults.

Line 58 embeds username/password in source and Line 45 suppresses gosec for the whole function. This weakens security posture and makes accidental insecure deploys more likely. Prefer an empty default URL and fail fast when unset.

Suggested change
 func Default() Config {
-	//nolint:gosec // default values
 	return Config{
@@
 		Database: databaseConfig{
-			URL:             "mariadb://bit-issues:bit-issues@127.0.0.1:3306/bit-issues?charset=utf8mb4&parseTime=True&loc=UTC",
+			URL:             "",
 			ConnMaxIdleTime: 0,
 			ConnMaxLifetime: 0,
 			MaxOpenConns:    0,
 			MaxIdleConns:    0,
 		},
@@
 func New() (Config, error) {
 	cfg := Default()
@@
 	if err := config.Load(&cfg, options...); err != nil {
 		return Config{}, fmt.Errorf("failed to load config: %w", err)
 	}
+	if cfg.Database.URL == "" {
+		return Config{}, fmt.Errorf("database.url is required")
+	}
 
 	return cfg, nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/config/config.go` around lines 45 - 59, The default config currently
embeds hardcoded DB credentials in the returned Config (databaseConfig.URL) and
suppresses gosec; remove the hardcoded connection string by setting
databaseConfig.URL to an empty string, drop or narrow the //nolint:gosec
annotation, and add a fail-fast validation (e.g., in the config
constructor/Validate function that returns Config) that errors if
databaseConfig.URL is empty so the app refuses to start without an explicit,
secure DB URL; refer to the Config and databaseConfig types and the URL field
when making these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/go.yml:
- Line 80: The benchmark job is permanently disabled by the literal "if: false";
remove this dead conditional and either delete the job if you intend to remove
benchmarking permanently, or replace "if: false" with a controllable gate such
as a repository variable (e.g., use an env like RUN_BENCH and set "if:
env.RUN_BENCH == 'true'") or a workflow_dispatch input (check
github.event.inputs.run_bench) so the benchmark job can be enabled
intentionally; locate the benchmark job entry that contains "if: false" and
apply one of these replacements.

In `@go.mod`:
- Line 6: These dependencies (bunfx, goosefx, sqlfx, validatorfx) are pre-1.0
and risky for production; either replace them with stable alternatives or pin
them to exact, reviewed commits and record the rationale: update go.mod to use
specific pseudo-versions or commit SHAs (use `go get module@<commit>` to pin) or
add a temporary `replace` directive for each module to a vetted commit, and add
a short note in the repo README or a TODO in the codebase documenting why the
pre-1.0 pins are used and when to revisit; reference the module names bunfx,
goosefx, sqlfx, and validatorfx when making these edits.

---

Outside diff comments:
In `@internal/config/config.go`:
- Around line 45-59: The default config currently embeds hardcoded DB
credentials in the returned Config (databaseConfig.URL) and suppresses gosec;
remove the hardcoded connection string by setting databaseConfig.URL to an empty
string, drop or narrow the //nolint:gosec annotation, and add a fail-fast
validation (e.g., in the config constructor/Validate function that returns
Config) that errors if databaseConfig.URL is empty so the app refuses to start
without an explicit, secure DB URL; refer to the Config and databaseConfig types
and the URL field when making these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b394dfb6-93b6-4781-8247-fe485942f698

📥 Commits

Reviewing files that changed from the base of the PR and between b2adcd7 and 9d28083.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (16)
  • .github/workflows/go.yml
  • dev-docs
  • go.mod
  • internal/app.go
  • internal/bot/handler/handler.go
  • internal/bot/handlers/start/handler.go
  • internal/bot/module.go
  • internal/config/config.go
  • internal/config/module.go
  • internal/db/errors.go
  • internal/db/migrations/20260204013005_initial.sql
  • internal/db/migrations/embed.go
  • internal/db/models.go
  • internal/db/module.go
  • internal/server/module.go
  • main.go
💤 Files with no reviewable changes (3)
  • internal/bot/module.go
  • internal/bot/handlers/start/handler.go
  • internal/bot/handler/handler.go
✅ Files skipped from review due to trivial changes (7)
  • dev-docs
  • internal/db/migrations/20260204013005_initial.sql
  • main.go
  • internal/db/models.go
  • internal/db/migrations/embed.go
  • internal/db/errors.go
  • internal/server/module.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/db/module.go
  • internal/config/module.go
  • internal/app.go

Comment thread .github/workflows/go.yml
Comment thread go.mod
@capcom6 capcom6 merged commit 15d72bf into master Apr 8, 2026
7 checks passed
@capcom6 capcom6 deleted the init/add-modules branch April 8, 2026 07:17
This was referenced Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant