feat: add bot and api services with config, logger and database packages

- Add bot service with telegram integration and webhook/polling modes
- Add api service with hono, swagger and zod-openapi
- Create config package for environment variable management
- Create logger package for colored console logging
- Create database package with prisma integration
- Remove next.js web and docs apps
- Update turbo.json for new services
- Add dockerfiles and gitea workflows for deployment
This commit is contained in:
Yuu Ottosoka
2025-07-08 19:46:08 +03:00
parent 393c175460
commit 71365836d3
85 changed files with 5635 additions and 4333 deletions

2
apps/api/.env.example Normal file
View File

@@ -0,0 +1,2 @@
PORT=3001
NODE_ENV=development

58
apps/api/Dockerfile Normal file
View File

@@ -0,0 +1,58 @@
FROM node:lts-alpine AS base
# Install system dependencies needed for canvas and other native modules
RUN apk add --no-cache \
python3 \
make \
g++ \
cairo-dev \
jpeg-dev \
pango-dev \
musl-dev \
giflib-dev \
pixman-dev \
pangomm-dev \
libjpeg-turbo-dev \
freetype-dev
# Install turbo globally
RUN npm install -g turbo
FROM base AS pruner
WORKDIR /app
COPY . .
RUN turbo prune api --docker
# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
WORKDIR /app
# First install the dependencies (this is done before copying the source code to better leverage Docker layer caching)
COPY .gitignore .gitignore
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/package-lock.json ./package-lock.json
RUN npm ci
# Build the project
COPY --from=pruner /app/out/full/ .
RUN turbo run build --filter=api...
FROM base AS runner
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 hono
USER hono
COPY --from=installer --chown=hono:nodejs /app/apps/api/dist ./dist
COPY --from=installer --chown=hono:nodejs /app/apps/api/package.json ./package.json
# Copy node_modules from installer stage
COPY --from=installer --chown=hono:nodejs /app/node_modules ./node_modules
COPY --from=installer --chown=hono:nodejs /app/apps/api/node_modules ./apps/api/node_modules
# Expose port
EXPOSE 3001
CMD ["npm", "start"]

1
apps/api/README.md Normal file
View File

@@ -0,0 +1 @@
# `api`

28
apps/api/package.json Normal file
View File

@@ -0,0 +1,28 @@
{
"name": "api",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "NODE_PATH=./src tsnd --respawn --transpile-only --exit-child src/index.ts",
"build": "tsc",
"start": "NODE_PATH=./dist node ./dist/index.js"
},
"dependencies": {
"@hono/node-server": "^1.15.0",
"@hono/swagger-ui": "^0.5.2",
"@hono/zod-openapi": "^0.9.0",
"@hono/zod-validator": "^0.4.3",
"@repo/config": "*",
"@repo/logger": "*",
"@repo/typescript-config": "*",
"dotenv": "^17.1.0",
"hono": "^4.8.4",
"hono-openapi": "^0.4.8",
"zod": "^3.25.76",
"zod-openapi": "^4.2.4"
},
"devDependencies": {
"ts-node-dev": "^2.0.0",
"typescript": "latest"
}
}

10
apps/api/src/config.ts Normal file
View File

@@ -0,0 +1,10 @@
import { createConfig } from '@repo/config';
import z from 'zod';
import 'dotenv/config';
export const config = createConfig({
schema: {
PORT: z.string().default('3001'),
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
},
});

35
apps/api/src/index.ts Normal file
View File

@@ -0,0 +1,35 @@
import { serve } from '@hono/node-server';
import { OpenAPIHono } from '@hono/zod-openapi';
import { swaggerUI } from '@hono/swagger-ui';
import { config } from './config';
import { logger } from '@repo/logger';
const app = new OpenAPIHono();
// OpenAPI documentation
app.doc('/doc', {
openapi: '3.0.0',
info: {
version: '1.0.0',
title: 'API Documentation',
description: 'API built with Hono and Zod OpenAPI',
},
});
// Swagger UI
app.get('/ui', swaggerUI({ url: '/doc' }));
// Health check
app.get('/health', (c) => {
return c.json({ status: 'ok', timestamp: new Date().toISOString() });
});
const port = parseInt(config.PORT);
logger.info(`Starting API server on port ${port}`);
logger.info(`Swagger UI available at http://localhost:${port}/ui`);
serve({
fetch: app.fetch,
port,
});

9
apps/api/tsconfig.json Normal file
View File

@@ -0,0 +1,9 @@
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}