This project represents a simple Telegram bot API with a backend for authentication.
To run this project locally, you will need the following dependencies:
- nvm (Node Version Manager): Used to manage Node.js versions.
- dbmate: A database migration tool.
- sqlc: Generate type-safe Go from SQL.
- docker: Container platform to run the database.
-
Clone the repository:
git clone [email protected]:rexemtoxa/tg-bot.git cd tg-bot
-
Install the dependencies listed above.
-
Frontend Setup:
- Navigate to the frontend folder:
cd frontend
- Switch to the correct Node.js version:
nvm use
- Install Node.js dependencies:
npm ci
- Build the frontend:
npm run build
- Navigate to the frontend folder:
-
Backend Setup:
- Navigate to the backend folder:
cd backend
- Switch to the correct Node.js version:
nvm use
- Install Node.js dependencies:
npm ci
- Copy the example environment variables file and adjust values if necessary:
cp .env.example .env
- Navigate to the backend folder:
-
Start the database container:
make start-dev-env
-
Enjoy! Do not forget to generate the bot token from the BotFather.
For additional commands, please check the scripts
section in the package.json
files in both the frontend and backend folders.
-
Continuous Integration (CI):
- Runs tests on PRs and pushes.
- Executes linters to ensure code quality.
-
Continuous Deployment (CD):
- After each commit to the main branch, deployment to DigitalOcean starts.
- The bot is deployed as a separate worker to avoid scaling problems since only one bot with one token can exist at a time.
- The backend is deployed separately to facilitate scaling.
- Before each deployment, a migration job attempts to apply migrations to the database instance.
- If something goes wrong during the build or deployment process, a rollback to the previous version is initiated.
- Cover all backend handlers with types.
- Generate OpenAPI schema from backend handlers.
- Validate all requests by JSON schema at runtime.
- Generate web client from OpenAPI schema.
- Extract dependencies like DB queries from the backend server to some dependency injection to facilitate testing.
- Write a few integration tests using Playwright or a similar tool and include these steps in the CI pipeline.
- Move handling of temp tokens/sessions to Redis.
- Improve logging.
PS. CI/CD and deployed app were destroyed at 19.05