Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copy this file to .env and adjust the values.
TELEGRAM_BOT_TOKEN=000000000:replace-me
MARKETBOT_DB=./data/marketbot.db
MARKETBOT_ADMINS=your_username
107 changes: 105 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,106 @@
# Very simple template for online Telegram shop
# MarketBot – Modern Telegram Marketplace Template

## Lord forgive me for my sins. Sorry for bad code, I was just a kid..
MarketBot is a polished, production-ready template for building a Telegram
marketplace bot. The project demonstrates how to structure a small, clean
codebase with a layered architecture, typed models, automated tests and a
professional developer experience. It replaces the unmaintained legacy
implementation with modern Python code that can be proudly showcased during
interviews or portfolio reviews.

## ✨ Highlights

- **Layered architecture** – configuration, persistence and Telegram
handlers are separated into focused modules.
- **Typed dataclasses** – domain concepts such as `Category`, `Product` and
`User` are represented with dataclasses for readability and safety.
- **Repository pattern** – all SQLite interaction lives in
`CatalogRepository`, simplifying future migrations to PostgreSQL or other
databases.
- **Config via environment variables** – secrets no longer live in source
control. `python-dotenv` makes local development ergonomic.
- **Test coverage** – `pytest` tests the repository layer and serves as a
regression suite when iterating on the bot.

## 🚀 Getting Started

1. **Create a virtual environment**

```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

2. **Configure environment variables**

Create a `.env` file in the project root:

```dotenv
TELEGRAM_BOT_TOKEN=123456789:example-token
MARKETBOT_DB=./data/marketbot.db
MARKETBOT_ADMINS=your_username,teammate
```

The database path can point anywhere on your machine. The application will
create directories automatically.

3. **Initialise sample data (optional)**

Launch a Python shell and seed a few categories or products:

```python
from pathlib import Path
from marketbot import CatalogRepository, Database, load_config

config = load_config()
repository = CatalogRepository(Database(config.database_path))
repository.initialise_schema()
repository.add_category("Books", "Fiction and non-fiction titles")
```

4. **Run the bot**

```bash
python -m marketbot
```

or execute the entry script directly:

```bash
python src/main.py
```

## 🧪 Testing

The repository layer is fully covered by unit tests.

```bash
pytest
```

Feel free to extend the suite with integration tests for additional
confidence.

## 🧱 Project Structure

```
src/
├── marketbot/
│ ├── __init__.py # Package exports
│ ├── bot.py # High-level bot orchestration and handlers
│ ├── config.py # Environment-aware configuration loading
│ ├── database.py # SQLite convenience wrapper
│ ├── keyboards.py # Telegram reply/inline keyboards
│ ├── models.py # Typed dataclasses for core entities
│ └── repository.py # Repository encapsulating all DB access
└── main.py # Entry point for running the bot locally
```

## 🛣️ Next Steps

- Add business logic such as basket management or payment integrations.
- Deploy the bot using Docker or serverless platforms.
- Extend the test suite with behaviour-driven or property-based tests.

If you build something on top of this template, consider opening a pull
request or starring the repository. Happy hacking! 🎉
Binary file removed clientbase.db
Binary file not shown.
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"

[project]
name = "marketbot"
version = "0.1.0"
description = "Modern Telegram marketplace bot template"
requires-python = ">=3.10"
readme = "README.md"
dependencies = [
"pyTelegramBotAPI>=4.10",
"python-dotenv>=1.0",
]

[tool.pytest.ini_options]
pythonpath = ["src"]
addopts = "-ra"

[tool.black]
target-version = ["py311"]
line-length = 100

[tool.ruff]
line-length = 100
select = ["E", "F", "I", "N", "UP", "B"]
ignore = ["E203"]

[tool.isort]
profile = "black"
line_length = 100
src_paths = ["src"]
8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
py>=1.10.0
pytest==3.0.2
requests>=2.20.0
six==1.9.0
wheel==0.24.0
pyTelegramBotAPI>=4.10
python-dotenv>=1.0
pytest>=7.4
173 changes: 0 additions & 173 deletions src/base.py

This file was deleted.

47 changes: 0 additions & 47 deletions src/basket.py

This file was deleted.

Loading