create-bunspace 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +181 -0
  2. package/dist/bin.js +5755 -0
  3. package/dist/templates/monorepo/CLAUDE.md +164 -0
  4. package/dist/templates/monorepo/LICENSE +21 -0
  5. package/dist/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
  6. package/dist/templates/monorepo/README.md +74 -0
  7. package/dist/templates/monorepo/SYNC_VERIFICATION.md +1 -0
  8. package/dist/templates/monorepo/apps/example/package.json +19 -0
  9. package/dist/templates/monorepo/apps/example/src/index.ts +23 -0
  10. package/dist/templates/monorepo/apps/example/src/types/index.ts +7 -0
  11. package/dist/templates/monorepo/apps/example/src/utils/index.ts +7 -0
  12. package/dist/templates/monorepo/core/packages/main/package.json +41 -0
  13. package/dist/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
  14. package/dist/templates/monorepo/core/packages/main/src/index.ts +80 -0
  15. package/dist/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
  16. package/dist/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
  17. package/dist/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
  18. package/dist/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
  19. package/dist/templates/monorepo/core/packages/utils/package.json +43 -0
  20. package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
  21. package/dist/templates/monorepo/core/packages/utils/src/index.ts +2 -0
  22. package/dist/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
  23. package/dist/templates/monorepo/core/packages/utils/src/result.ts +146 -0
  24. package/dist/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
  25. package/dist/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
  26. package/dist/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
  27. package/dist/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
  28. package/dist/templates/monorepo/oxlint.json +14 -0
  29. package/dist/templates/monorepo/package.json +39 -0
  30. package/dist/templates/monorepo/tsconfig.json +35 -0
  31. package/dist/templates/telegram-bot/.oxlintrc.json +33 -0
  32. package/dist/templates/telegram-bot/.prettierignore +5 -0
  33. package/dist/templates/telegram-bot/.prettierrc +26 -0
  34. package/dist/templates/telegram-bot/CLAUDE.deploy.md +356 -0
  35. package/dist/templates/telegram-bot/CLAUDE.dev.md +266 -0
  36. package/dist/templates/telegram-bot/CLAUDE.md +280 -0
  37. package/dist/templates/telegram-bot/Dockerfile +46 -0
  38. package/dist/templates/telegram-bot/README.md +245 -0
  39. package/dist/templates/telegram-bot/apps/.gitkeep +0 -0
  40. package/dist/templates/telegram-bot/bun.lock +208 -0
  41. package/dist/templates/telegram-bot/core/.env.example +71 -0
  42. package/dist/templates/telegram-bot/core/README.md +1067 -0
  43. package/dist/templates/telegram-bot/core/package.json +15 -0
  44. package/dist/templates/telegram-bot/core/src/config/env.ts +131 -0
  45. package/dist/templates/telegram-bot/core/src/config/index.ts +97 -0
  46. package/dist/templates/telegram-bot/core/src/config/logging.ts +110 -0
  47. package/dist/templates/telegram-bot/core/src/handlers/control.ts +85 -0
  48. package/dist/templates/telegram-bot/core/src/handlers/health.ts +83 -0
  49. package/dist/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
  50. package/dist/templates/telegram-bot/core/src/index.ts +161 -0
  51. package/dist/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
  52. package/dist/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
  53. package/dist/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
  54. package/dist/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
  55. package/dist/templates/telegram-bot/core/src/types/bot.ts +92 -0
  56. package/dist/templates/telegram-bot/core/src/types/constants.ts +50 -0
  57. package/dist/templates/telegram-bot/core/src/types/result.ts +1 -0
  58. package/dist/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
  59. package/dist/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
  60. package/dist/templates/telegram-bot/core/src/utils/commands.ts +63 -0
  61. package/dist/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
  62. package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
  63. package/dist/templates/telegram-bot/core/src/utils/memory.ts +33 -0
  64. package/dist/templates/telegram-bot/core/src/utils/result.ts +26 -0
  65. package/dist/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
  66. package/dist/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
  67. package/dist/templates/telegram-bot/core/tsconfig.json +9 -0
  68. package/dist/templates/telegram-bot/docker-compose.yml +37 -0
  69. package/dist/templates/telegram-bot/docs/cli-commands.md +377 -0
  70. package/dist/templates/telegram-bot/docs/development.md +363 -0
  71. package/dist/templates/telegram-bot/docs/environment.md +460 -0
  72. package/dist/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
  73. package/dist/templates/telegram-bot/docs/examples/simple-command.md +207 -0
  74. package/dist/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
  75. package/dist/templates/telegram-bot/docs/getting-started.md +223 -0
  76. package/dist/templates/telegram-bot/docs/troubleshooting.md +489 -0
  77. package/dist/templates/telegram-bot/package.json +49 -0
  78. package/dist/templates/telegram-bot/packages/utils/package.json +12 -0
  79. package/dist/templates/telegram-bot/packages/utils/src/index.ts +2 -0
  80. package/dist/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
  81. package/dist/templates/telegram-bot/packages/utils/src/result.ts +80 -0
  82. package/dist/templates/telegram-bot/tools/README.md +47 -0
  83. package/dist/templates/telegram-bot/tools/commands/doctor.ts +460 -0
  84. package/dist/templates/telegram-bot/tools/commands/index.ts +35 -0
  85. package/dist/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
  86. package/dist/templates/telegram-bot/tools/commands/setup.ts +368 -0
  87. package/dist/templates/telegram-bot/tools/commands/status.ts +140 -0
  88. package/dist/templates/telegram-bot/tools/index.ts +16 -0
  89. package/dist/templates/telegram-bot/tools/package.json +12 -0
  90. package/dist/templates/telegram-bot/tools/utils/index.ts +13 -0
  91. package/dist/templates/telegram-bot/tsconfig.json +22 -0
  92. package/dist/templates/telegram-bot/vitest.config.ts +29 -0
  93. package/package.json +35 -0
  94. package/templates/monorepo/CLAUDE.md +164 -0
  95. package/templates/monorepo/LICENSE +21 -0
  96. package/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
  97. package/templates/monorepo/README.md +74 -0
  98. package/templates/monorepo/apps/example/package.json +19 -0
  99. package/templates/monorepo/apps/example/src/index.ts +23 -0
  100. package/templates/monorepo/apps/example/src/types/index.ts +7 -0
  101. package/templates/monorepo/apps/example/src/utils/index.ts +7 -0
  102. package/templates/monorepo/core/packages/main/package.json +41 -0
  103. package/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
  104. package/templates/monorepo/core/packages/main/src/index.ts +80 -0
  105. package/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
  106. package/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
  107. package/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
  108. package/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
  109. package/templates/monorepo/core/packages/utils/package.json +43 -0
  110. package/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
  111. package/templates/monorepo/core/packages/utils/src/index.ts +2 -0
  112. package/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
  113. package/templates/monorepo/core/packages/utils/src/result.ts +146 -0
  114. package/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
  115. package/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
  116. package/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
  117. package/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
  118. package/templates/monorepo/oxlint.json +14 -0
  119. package/templates/monorepo/package.json +39 -0
  120. package/templates/monorepo/tsconfig.json +35 -0
  121. package/templates/telegram-bot/.oxlintrc.json +33 -0
  122. package/templates/telegram-bot/.prettierignore +5 -0
  123. package/templates/telegram-bot/.prettierrc +26 -0
  124. package/templates/telegram-bot/CLAUDE.deploy.md +356 -0
  125. package/templates/telegram-bot/CLAUDE.dev.md +266 -0
  126. package/templates/telegram-bot/CLAUDE.md +280 -0
  127. package/templates/telegram-bot/Dockerfile +46 -0
  128. package/templates/telegram-bot/README.md +245 -0
  129. package/templates/telegram-bot/apps/.gitkeep +0 -0
  130. package/templates/telegram-bot/bun.lock +208 -0
  131. package/templates/telegram-bot/core/.env.example +71 -0
  132. package/templates/telegram-bot/core/README.md +1067 -0
  133. package/templates/telegram-bot/core/package.json +15 -0
  134. package/templates/telegram-bot/core/src/config/env.ts +131 -0
  135. package/templates/telegram-bot/core/src/config/index.ts +97 -0
  136. package/templates/telegram-bot/core/src/config/logging.ts +110 -0
  137. package/templates/telegram-bot/core/src/handlers/control.ts +85 -0
  138. package/templates/telegram-bot/core/src/handlers/health.ts +83 -0
  139. package/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
  140. package/templates/telegram-bot/core/src/index.ts +161 -0
  141. package/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
  142. package/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
  143. package/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
  144. package/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
  145. package/templates/telegram-bot/core/src/types/bot.ts +92 -0
  146. package/templates/telegram-bot/core/src/types/constants.ts +50 -0
  147. package/templates/telegram-bot/core/src/types/result.ts +1 -0
  148. package/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
  149. package/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
  150. package/templates/telegram-bot/core/src/utils/commands.ts +63 -0
  151. package/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
  152. package/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
  153. package/templates/telegram-bot/core/src/utils/memory.ts +33 -0
  154. package/templates/telegram-bot/core/src/utils/result.ts +26 -0
  155. package/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
  156. package/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
  157. package/templates/telegram-bot/core/tsconfig.json +9 -0
  158. package/templates/telegram-bot/docker-compose.yml +37 -0
  159. package/templates/telegram-bot/docs/cli-commands.md +377 -0
  160. package/templates/telegram-bot/docs/development.md +363 -0
  161. package/templates/telegram-bot/docs/environment.md +460 -0
  162. package/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
  163. package/templates/telegram-bot/docs/examples/simple-command.md +207 -0
  164. package/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
  165. package/templates/telegram-bot/docs/getting-started.md +223 -0
  166. package/templates/telegram-bot/docs/troubleshooting.md +489 -0
  167. package/templates/telegram-bot/package.json +49 -0
  168. package/templates/telegram-bot/packages/utils/package.json +12 -0
  169. package/templates/telegram-bot/packages/utils/src/index.ts +2 -0
  170. package/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
  171. package/templates/telegram-bot/packages/utils/src/result.ts +80 -0
  172. package/templates/telegram-bot/tools/README.md +47 -0
  173. package/templates/telegram-bot/tools/commands/doctor.ts +460 -0
  174. package/templates/telegram-bot/tools/commands/index.ts +35 -0
  175. package/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
  176. package/templates/telegram-bot/tools/commands/setup.ts +368 -0
  177. package/templates/telegram-bot/tools/commands/status.ts +140 -0
  178. package/templates/telegram-bot/tools/index.ts +16 -0
  179. package/templates/telegram-bot/tools/package.json +12 -0
  180. package/templates/telegram-bot/tools/utils/index.ts +13 -0
  181. package/templates/telegram-bot/tsconfig.json +22 -0
  182. package/templates/telegram-bot/vitest.config.ts +29 -0
@@ -0,0 +1,266 @@
1
+ # CLAUDE.dev - Guía de Desarrollo
2
+
3
+ > **Parte de**: [CLAUDE.md](./CLAUDE.md) | Ver también: [CLAUDE.deploy.md](./CLAUDE.deploy.md)
4
+
5
+ Guía de desarrollo para extender y modificar el bot template.
6
+
7
+ **Documentación relacionada**:
8
+ - [docs/development/setup.mdx](./docs/development/setup.mdx)
9
+ - [docs/development/patterns.mdx](./docs/development/patterns.mdx)
10
+
11
+ ---
12
+
13
+ ## Development Standards
14
+
15
+ ### Code Style
16
+
17
+ - TypeScript strict mode enabled
18
+ - `noUncheckedIndexedAccess: true` - arrays need undefined checks
19
+ - Semi: false, singleQuote: true
20
+ - Result type pattern para error handling
21
+ - Better Logger para logging (no console.*)
22
+
23
+ ### Before Commit Checklist
24
+
25
+ - [ ] `bun run typecheck` → 0 errores
26
+ - [ ] `bun run lint` → 0 warnings, 0 errors
27
+ - [ ] `bun test` → all tests pass
28
+ - [ ] No `console.*` statements
29
+ - [ ] Código formateado (`bun run format:check`)
30
+
31
+ ---
32
+
33
+ ## Agregando Commands
34
+
35
+ ### 1. Crear Handler
36
+
37
+ **Archivo**: `core/src/handlers/mycommand.ts`
38
+
39
+ ```typescript
40
+ import type { Context } from 'telegraf'
41
+
42
+ export async function handleMyCommand(ctx: Context): Promise<void> {
43
+ await ctx.reply('Respuesta del comando')
44
+ }
45
+ ```
46
+
47
+ ### 2. Registrar en Bot
48
+
49
+ **Archivo**: `core/src/index.ts`
50
+
51
+ ```typescript
52
+ import { handleMyCommand } from './handlers/mycommand.js'
53
+ bot.command('mycommand', handleMyCommand)
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Agregando Middleware
59
+
60
+ ### 1. Crear Middleware
61
+
62
+ **Archivo**: `core/src/middleware/custom.ts`
63
+
64
+ ```typescript
65
+ import type { Context, Middleware } from 'telegraf'
66
+
67
+ export function customMiddleware(): Middleware<Context> {
68
+ return async (ctx, next) => {
69
+ // Pre-processing
70
+ await next()
71
+ // Post-processing
72
+ }
73
+ }
74
+ ```
75
+
76
+ ### 2. Registrar Middleware
77
+
78
+ **Archivo**: `core/src/index.ts`
79
+
80
+ ```typescript
81
+ import { customMiddleware } from './middleware/custom.js'
82
+ bot.use(customMiddleware())
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Patterns
88
+
89
+ ### Result Type Pattern
90
+
91
+ Railway-oriented programming para error handling sin excepciones:
92
+
93
+ ```typescript
94
+ import { ok, err, type Result, botError } from './types/result.js'
95
+
96
+ function divide(a: number, b: number): Result<number> {
97
+ if (b === 0) {
98
+ return err(botError('INVALID_ARGS', 'Cannot divide by zero'))
99
+ }
100
+ return ok(a / b)
101
+ }
102
+
103
+ const result = divide(10, 2)
104
+ if (result.ok) {
105
+ console.log(result.value) // 5
106
+ } else {
107
+ console.error(result.error.message)
108
+ }
109
+ ```
110
+
111
+ **Utilities disponibles**: `ok`, `err`, `isOk`, `isErr`, `unwrap`, `unwrapOr`, `map`, `mapErr`, `flatMap`, `tap`, `tapErr`, `match`, `collect`, `all`
112
+
113
+ ### Singleton Pattern
114
+
115
+ - `BotManager` - Lifecycle y stats
116
+ - `LogStreamer` - Buffer de logs
117
+ - `InstanceManager` - Lock management
118
+ - `Config` - Cached configuration
119
+
120
+ ---
121
+
122
+ ## Logging System
123
+
124
+ ### Usar Better Logger
125
+
126
+ ```typescript
127
+ import { botLogger, kv, badge, colorText, colors } from './middleware/logging.js'
128
+
129
+ botLogger.info('Información')
130
+ botLogger.success('Operación exitosa')
131
+ botLogger.warn('Advertencia')
132
+ botLogger.error('Error', error)
133
+ ```
134
+
135
+ ### Crear Logger Especializado
136
+
137
+ ```typescript
138
+ import { component } from '@mks2508/better-logger'
139
+
140
+ const myLogger = component('MyModule')
141
+ myLogger.info('Módulo iniciado')
142
+ ```
143
+
144
+ ### Formatting Avanzado
145
+
146
+ ```typescript
147
+ // Key-Value formatting
148
+ botLogger.info(kv({ user: '123', action: 'start' }))
149
+
150
+ // Badge
151
+ botLogger.info(badge('CMD', 'rounded'))
152
+
153
+ // Colored text
154
+ botLogger.success(colorText('Success', colors.success))
155
+
156
+ // Duration
157
+ const { formatDuration } = await import('./middleware/logging.js')
158
+ botLogger.info(formatDuration(1234)) // "1.2s"
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Testing
164
+
165
+ ### Escribiendo Tests
166
+
167
+ Usa `bun test` con sintaxis similar a Jest:
168
+
169
+ ```typescript
170
+ import { describe, test, expect } from 'bun:test'
171
+
172
+ describe('Mi Módulo', () => {
173
+ test('debe hacer algo', () => {
174
+ const result = miFuncion()
175
+ expect(result).toBe('expected')
176
+ })
177
+ })
178
+ ```
179
+
180
+ ### Archivos de Test
181
+
182
+ - **Nombre**: `*.test.ts` o `*.spec.ts`
183
+ - **Ubicación**: Junto al archivo que testean
184
+ - **Ejemplo**: `core/src/types/result.test.ts`
185
+
186
+ ### Ejecutar Tests
187
+
188
+ ```bash
189
+ bun test # Ejecutar todos
190
+ bun test --verbose # Output detallado
191
+ bun test --watch # Watch mode
192
+ bun test path/to/test.ts # Test específico
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Environment Variables (Desarrollo)
198
+
199
+ ### Archivo: `core/.env.example`
200
+
201
+ Variables requeridas para desarrollo:
202
+
203
+ | Variable | Descripción |
204
+ | -------- | ----------- |
205
+ | `TG_BOT_TOKEN` | Token from @BotFather |
206
+ | `TG_MODE` | `polling` o `webhook` |
207
+ | `LOG_LEVEL` | `debug`, `info`, `warn`, `error` |
208
+ | `TG_DEBUG` | Habilitar debug mode |
209
+ | `TG_INSTANCE_CHECK` | Habilitar detección de instancias |
210
+
211
+ ---
212
+
213
+ ## Troubleshooting Development
214
+
215
+ ### Typecheck Errors
216
+
217
+ ```bash
218
+ # Ejecutar typecheck detallado
219
+ tsgo --traceback
220
+ ```
221
+
222
+ ### Tests Fallan
223
+
224
+ ```bash
225
+ # Ejecutar tests con output detallado
226
+ bun test --verbose
227
+
228
+ # Ejecutar solo un archivo de test
229
+ bun test core/src/types/result.test.ts
230
+ ```
231
+
232
+ ### Bot No Responde
233
+
234
+ 1. Verificar `TG_BOT_TOKEN` es válido
235
+ 2. Chequear `/health` command
236
+ 3. Verificar `TG_AUTHORIZED_USER_IDS` para control commands
237
+
238
+ ---
239
+
240
+ ## Quick Reference
241
+
242
+ ### Comandos de Desarrollo
243
+
244
+ ```bash
245
+ bun run dev # Watch mode
246
+ bun run typecheck # Type check
247
+ bun run lint # Lint check
248
+ bun run format # Format code
249
+ bun test # Run tests
250
+ ```
251
+
252
+ ### Archivos Clave para Desarrollo
253
+
254
+ - `core/src/index.ts` - Entry point, command registration
255
+ - `core/src/handlers/` - Command handlers
256
+ - `core/src/middleware/` - Telegraf middleware
257
+ - `core/src/config/` - Configuration and env validation
258
+ - `packages/utils/src/` - Shared utilities
259
+
260
+ ---
261
+
262
+ ## Ver También
263
+
264
+ - [CLAUDE.md](./CLAUDE.md) - Entry point principal
265
+ - [CLAUDE.deploy.md](./CLAUDE.deploy.md) - Deployment y entornos
266
+ - [README.md](./README.md) - Quick start del proyecto
@@ -0,0 +1,280 @@
1
+ # CLAUDE.md - mks-telegram-bot
2
+
3
+ > **Template**: Monorepo para bots de Telegram con Bun, Telegraf y TypeScript
4
+ > **Versión**: 0.1.0
5
+
6
+ Template monorepo diseñado para ser usado como `bun create mks2508/mks-telegram-bot` o como GitHub template repository.
7
+
8
+ **Objetivo**: Template reutilizable para crear bots de Telegram con las mejores prácticas, tipado estricto y arquitectura modular.
9
+
10
+ ---
11
+
12
+ ## Quick Start
13
+
14
+ ```bash
15
+ # Clonar o usar como template
16
+ bun create mks2508/mks-telegram-bot my-bot
17
+
18
+ # Instalar dependencias
19
+ bun install
20
+
21
+ # Configurar variables de entorno
22
+ cp core/.env.example core/.env
23
+
24
+ # Desarrollo
25
+ bun run dev
26
+ ```
27
+
28
+ ---
29
+
30
+ ## Contextos Especializados
31
+
32
+ Este template tiene contextos separados por dominio:
33
+
34
+ | Archivo | Propósito |
35
+ | ------- | --------- |
36
+ | [CLAUDE.dev.md](./CLAUDE.dev.md) | Desarrollo, patterns, testing |
37
+ | [CLAUDE.deploy.md](./CLAUDE.deploy.md) | Deployment, Docker, entornos |
38
+ | [docs/](./docs/) | Documentación web (MDX, futuro) |
39
+
40
+ ### CLAUDE.dev.md
41
+
42
+ Ver [CLAUDE.dev.md](./CLAUDE.dev.md) para:
43
+ - Development standards y code style
44
+ - Cómo agregar commands y middleware
45
+ - Testing patterns
46
+ - Result type pattern y Singleton pattern
47
+ - Better Logger usage
48
+
49
+ ### CLAUDE.deploy.md
50
+
51
+ Ver [CLAUDE.deploy.md](./CLAUDE.deploy.md) para:
52
+ - Multi-environment (local, staging, production)
53
+ - Multi-instance management
54
+ - Docker deployment
55
+ - ngrok integration
56
+ - VPS deployment guide
57
+
58
+ ---
59
+
60
+ ## Critical Files for Claude
61
+
62
+ When modifying this codebase, prioritize understanding:
63
+
64
+ - `core/src/index.ts` - Bot entry point, command registration
65
+ - `core/src/config/env.ts` - Environment schema validation
66
+ - `core/src/utils/instance-manager.ts` - Multi-instance locking
67
+ - `packages/utils/src/` - Shared utilities (logger, result)
68
+
69
+ ---
70
+
71
+ ## Session Context Template
72
+
73
+ When starting a new session, include:
74
+ - **User's goal**: developing vs deploying vs extending
75
+ - **Current environment**: local/staging/production
76
+ - **Any errors or issues encountered**: Paste error messages
77
+
78
+ ---
79
+
80
+ ## Monorepo Structure
81
+
82
+ ```
83
+ mks-telegram-bot/
84
+ ├── core/ # @mks2508/telegram-bot-core
85
+ │ ├── .env.local # Local development
86
+ │ ├── .env.staging # Staging environment
87
+ │ ├── .env.production # Production environment
88
+ │ ├── tmp/ # Instance lock files
89
+ │ └── src/ # Bot source code
90
+ ├── packages/ # Shared code
91
+ │ └── utils/ # @mks2508/telegram-bot-utils
92
+ ├── tools/ # CLI tools
93
+ │ └── commands/ # ngrok, status
94
+ ├── apps/ # Future: examples, docs
95
+ ├── docs/ # Future MDX site
96
+ ├── Dockerfile # Multi-stage build
97
+ └── docker-compose.yml # Local dev containers
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Commands
103
+
104
+ ```bash
105
+ # Development
106
+ bun run dev # Hot reload (watch mode)
107
+ bun run start # Production mode
108
+
109
+ # CLI tools
110
+ bun run status # Show running instances
111
+ bun run ngrok # Start ngrok tunnel
112
+
113
+ # Quality
114
+ bun run typecheck # Type check (tsgo ~10x faster)
115
+ bun run lint # Lint (oxlint)
116
+ bun run format # Format (prettier)
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Environment Variables
122
+
123
+ ### Multi-Environment Support
124
+
125
+ El proyecto soporta múltiples entornos con archivos `.env` separados:
126
+
127
+ | Archivo | Uso |
128
+ | ------- | --- |
129
+ | `core/.env.local` | Desarrollo local (polling mode) |
130
+ | `core/.env.staging` | Testing con bot de test |
131
+ | `core/.env.production` | Producción con bot real |
132
+
133
+ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
134
+
135
+ ### Required Variables
136
+
137
+ | Variable | Tipo | Description |
138
+ | -------- | ---- | ----------- |
139
+ | `TG_BOT_TOKEN` | string | Bot token from @BotFather |
140
+ | `TG_MODE` | enum | `polling` or `webhook` |
141
+
142
+ ### Instance Detection Variables
143
+
144
+ | Variable | Default | Description |
145
+ | -------- | ------- | ----------- |
146
+ | `TG_ENV` | `local` | Environment: local/staging/production |
147
+ | `TG_INSTANCE_NAME` | `mks-bot` | Unique instance name for locking |
148
+ | `TG_INSTANCE_CHECK` | `true` | Enable instance conflict detection |
149
+
150
+ ---
151
+
152
+ ## Technology Stack
153
+
154
+ | Tool | Purpose | Version |
155
+ | ---- | ------- | ------- |
156
+ | **Bun** | Runtime & package manager | 1.3+ |
157
+ | **Telegraf** | Telegram Bot API | 4.16+ |
158
+ | **TypeScript** | Language | 5.9+ |
159
+ | **tsgo** | Type-checking | native-preview |
160
+ | **Zod** | Schema validation | 3.24+ |
161
+ | **Better Logger** | Logging | 4.0.0 |
162
+ | **@mks2508/no-throw** | Result type | 0.1.0 |
163
+ | **oxlint** | Linting | latest |
164
+ | **prettier** | Formatting | 3.4+ |
165
+ | **commander** | CLI framework | 14.0+ |
166
+
167
+ ---
168
+
169
+ ## Architecture Overview
170
+
171
+ ```
172
+ ┌─────────────────────────────────────────────────────────────┐
173
+ │ Telegram API (Telegraf) │
174
+ └─────────────────────────┬───────────────────────────────────┘
175
+
176
+ ┌─────────────────┼─────────────────┐
177
+ │ │ │
178
+ ┌────▼────┐ ┌───────▼───────┐ ┌──────▼──────┐
179
+ │Middleware│ │ Handlers │ │ BotManager │
180
+ │ • auth │ │ • health │ │ InstanceMgr │
181
+ │ • error │ │ • control │ │ • stats │
182
+ │ • topics │ │ • logs │ │ • lifecycle │
183
+ └──────────┘ └──────────────┘ └─────────────┘
184
+ │ │
185
+ └────────────┬───────────────────┘
186
+
187
+ ┌────────▼────────┐
188
+ │ InstanceManager │
189
+ │ • acquireLock │
190
+ │ • releaseLock │
191
+ └─────────────────┘
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Bot Commands
197
+
198
+ ### Public Commands
199
+
200
+ | Command | Handler | Description |
201
+ | ------- | ------- | ----------- |
202
+ | `/start` | inline | Welcome message |
203
+ | `/health` | handleHealth | Bot health status |
204
+ | `/uptime` | handleUptime | Uptime information |
205
+ | `/stats` | handleStats | Bot statistics |
206
+ | `/logs` | handleLogs | Log streaming status |
207
+
208
+ ### Control Commands (requires auth)
209
+
210
+ | Command | Handler | Description |
211
+ | ------- | ------- | ----------- |
212
+ | `/stop` | handleStop | Graceful shutdown |
213
+ | `/restart` | handleRestart | Restart with stats reset |
214
+ | `/mode` | handleMode | Switch polling/webhook |
215
+ | `/webhook` | handleWebhook | Show webhook config |
216
+
217
+ ---
218
+
219
+ ## Development Workflow
220
+
221
+ ### Before Commit
222
+
223
+ - [ ] `bun run typecheck` → 0 errores
224
+ - [ ] `bun run lint` → 0 warnings, 0 errors
225
+ - [ ] `bun test` → all tests pass (if tests exist)
226
+ - [ ] No `console.*` (use Better Logger)
227
+
228
+ ### Code Style
229
+
230
+ - TypeScript strict mode enabled
231
+ - `noUncheckedIndexedAccess: true` - arrays need undefined checks
232
+ - Semi: false, singleQuote: true
233
+ - Result type pattern para error handling
234
+
235
+ ---
236
+
237
+ ## Documentation Web
238
+
239
+ Ver [docs/](./docs/) para documentación completa (futuro MDX site con Astro/Starlight).
240
+
241
+ ---
242
+
243
+ ## Future Apps
244
+
245
+ El directorio `apps/` está preparado para:
246
+ - `apps/example/` - Ejemplo de bot completo
247
+ - `apps/docs/` - Documentación interactiva
248
+ - `apps/cli/` - CLI extendida para gestión
249
+
250
+ ---
251
+
252
+ ## Deployment
253
+
254
+ ### Docker
255
+
256
+ ```bash
257
+ # Build image
258
+ docker build -t mks-telegram-bot .
259
+
260
+ # Run with docker-compose
261
+ docker-compose up bot-production
262
+ ```
263
+
264
+ ### Multi-Instance
265
+
266
+ El template soporta múltiples instancias simultáneas con detección de conflictos:
267
+
268
+ ```bash
269
+ # Ver instancias corriendo
270
+ bun run status
271
+
272
+ # Iniciar en entorno específico
273
+ TG_ENV=staging bun run start
274
+ ```
275
+
276
+ ---
277
+
278
+ ## License
279
+
280
+ MIT
@@ -0,0 +1,46 @@
1
+ # Build stage
2
+ FROM oven/bun:1.3 AS builder
3
+ WORKDIR /app
4
+
5
+ # Copy package files
6
+ COPY package.json bun.lock ./
7
+ COPY core/package.json core/
8
+
9
+ # Install dependencies
10
+ RUN bun install --frozen-lockfile
11
+
12
+ # Copy TypeScript config and source
13
+ COPY tsconfig.json ./
14
+ COPY core/tsconfig.json core/
15
+ COPY core/src core/src
16
+
17
+ # Production stage
18
+ FROM oven/bun:1.3 AS production
19
+ WORKDIR /app
20
+
21
+ # Copy node_modules from builder
22
+ COPY --from=builder /app/node_modules ./node_modules
23
+ COPY --from=builder /app/core/node_modules ./core/node_modules
24
+
25
+ # Copy source and config files
26
+ COPY --from=builder /app/core/src ./core/src
27
+ COPY --from=builder /app/core/package.json ./core/
28
+ COPY --from=builder /app/core/tsconfig.json ./core/
29
+
30
+ # Create necessary directories
31
+ RUN mkdir -p /app/core/tmp /app/core/logs
32
+
33
+ # Set environment variables
34
+ ENV TG_ENV=production
35
+ ENV NODE_ENV=production
36
+ ENV TG_MODE=webhook
37
+
38
+ # Healthcheck
39
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
40
+ CMD bun run cli status || exit 1
41
+
42
+ # Expose webhook port
43
+ EXPOSE 3000
44
+
45
+ # Run the bot
46
+ CMD ["bun", "run", "start"]