Self-hosted PHP / MySQL · Persian Telegram workflows
A structured booking workflow, from request to review.
A reservation source project built around capacity management, transactional state and deliberate administrative review.
Open-source application architecture and installation reference. No live booking or payment service is operated on this website.
Source architecture · not a running reservation
- Validate Actor, tour version and seat quantity
- Lock User, tour and existing booking
- Commit together Capacity decision, price snapshot, history and notification intent
Built for a clear division of responsibility.
Travelers request.
Operators review.
Independent operators control the Telegram bot, PHP hosting, database and data policy. The application brings tour inventory, group requests, manual payment review and queued notifications into a modular monolith. This website explains the source; it does not run it.
01 / People & permissions
Two journeys.
Explicit authority.
Traveler
Start in a private Telegram chat, complete the required profile, browse or search published tours, inspect dates and price, choose 1–20 seats, then confirm a request. Track history in /bookings; a request is not a confirmed reservation.
Operator
Create a draft, set dates, integer IRR price and capacity, then publish. Authorized staff review payments and requests separately, reject or confirm, inspect aggregate reports and complete ended bookings.
Owner, manager, reviewer and reporter roles have distinct permissions. Domain services enforce ownership and RBAC independently of visible menus; queued sensitive delivery rechecks authorization.
درخواست رزرو
رزروهای من
بررسی درخواست
02 / Reservation lifecycle
A held seat is not a final confirmation.
Static state model. These are documented transitions, not interactive booking controls.
- Tour availablePublished, future start and sufficient capacity
- Reservation requested1–20 seats; validated profile policy
- Capacity heldPending request and price/payment snapshot commit
- Administrative reviewPayment and reservation decisions remain separate
- Confirmed / Rejected / CancelledEach change requires its own state, permission and time checks
Pending → confirmed, rejected or cancelled. Confirmation requires a paid payment record. A free booking is marked paid automatically; positive-price payments need manual review.
Confirmed → cancelled or completed. Travelers may cancel their own booking only before departure. Completion requires the tour to have ended. Rejection or cancellation releases held capacity.
Unpaid pending holds expire. The worker rejects expired pending/failed payments after locked rechecks. One booking identity remains per traveler/tour, including after cancellation; automatic same-tour rebooking is not supported.
03 / Capacity & consistency
Make the decision under a lock.
The reservation use case locks the user, tour and existing booking. It checks the published future tour, expected version and held capacity before writing. Pending, confirmed and completed bookings count toward used capacity; cancelled and rejected requests do not.
Booking, participant ordinals, unit-price/payment snapshot, status history and outbox intent commit together. Competing requests serialize around the tour lock. Domain rules reject over-capacity edits and stale confirmations.
Read the source contract
// ReservationService.php — simplified source excerpt
Database::atomic($this->pdo, function () {
// Lock user → tour → existing booking.
// Validate version, publication and remaining seats.
// Write booking, payment snapshot, history and outbox.
});This annotated excerpt describes coordination; it is not executable installation code. Owning transactions retry MySQL lock errors 1205/1213 up to five attempts. Nested calls join the owning transaction.
04 / Manual payment review
Evidence first.
Confirmation separately.
Authorized payment staff record a reviewed reference. The application hashes it, enforces reference uniqueness and commits payment state, audit and notification intent together. Marking payment paid does not itself confirm the reservation.
No live payment gateway or automatic refund is included. A paid cancellation or rejection requires operator-led settlement. The repository’s signed payment sandbox is restricted to disposable development/test environments and is disabled in production. This website exposes no checkout or sandbox.
05 / System architecture
One application.
A separate delivery process.
Application architecture for independent deployment. No part of this pipeline executes on GitHub Pages.
- Traveler / operatorPrivate Telegram chat
- Telegram Bot APIHTTPS update delivery
- Authenticated webhookPOST, secret and bounded payload
- PHP applicationRouter → controllers → authorized services
- MySQL / MariaDBInventory, reservations, history and outbox
- Notification workerClaim → authorize → deliver through Telegram
Operators use the same authenticated application boundary. Pure rules are separated from persistence and Telegram transport; legacy command compatibility remains behind an adapter.
06 / Delivery & retry
Persist the intent.
Deliver outside the transaction.
A separately supervised worker claims queued notifications in short database transactions, then calls Telegram outside the claim transaction. An advisory lock coordinates workers; stale five-minute leases become eligible again.
Transport failures, HTTP 429 and server errors receive bounded retries. Shared 429 cooldown survives restarts. Reminder validity and permissions are checked before delivery; obsolete reminders are suppressed.
Delivery is at least once, not exactly once. A successful send followed by a lost acknowledgement can produce a duplicate. No permanent uptime, instant delivery or zero-duplicate guarantee is made. The worker also schedules reminders, unpaid-hold expiration and configured retention.
07 / Security & data
Keep authority and identity explicit.
- Secret-header authentication precedes database access. Webhooks accept only supported actor-owned private updates; POST and a one-MiB payload boundary apply.
- Services use parameterized SQL, ownership checks and scoped roles. Update receipts and ingress limits bound replay and repeated requests.
- Optional own-account Telegram contact and checksum-valid national-code onboarding use encrypted identifiers. These checks do not establish legal identity.
- Aggregate reporting and CSV exports exclude identity columns, neutralize formulas and cap exports at 5,000 rows.
- Account erasure requires active bookings to be cancelled. Profile cleanup is opt-in; existing Telegram messages and offline backups need separate operator policies.
Do not put traveler records, identifiers, credentials or private logs into public issues, screenshots or sample data. The static site collects no traveler information.
Security and privacy reference08 / Installation reference
Infrastructure you operate.
Docker Compose, PHP 8.0–8.4, MySQL and a separately running worker. Independent live use additionally needs HTTPS and privately managed Telegram credentials.
These are documentation examples for a future independent installation. This website deploys no bot, PHP service or database and registers no webhook.
Get the source · Windows, macOS or Linux
git clone https://github.com/AlirezaBelal/travel-tour-reservation-bot.git
cd travel-tour-reservation-botOn PowerShell: Copy-Item .env.example .env. On macOS/Linux: cp .env.example .env. Configure this private file deliberately; never commit it.
Use distinct database passwords, authorized owner IDs, a strong webhook secret and an independently generated profile-encryption key. Keep credentials and backups outside public/.
Fresh isolated Docker installation
docker compose build app
docker compose run --rm migrate php bin/install.php
docker compose run --rm migrate php bin/restrict-runtime.php --confirm
docker compose up -dOnly use this sequence after reviewing and completing private configuration. The maintenance service initializes schema and reduces runtime privileges to SELECT/INSERT/UPDATE/DELETE. Normal startup launches app, database and worker.
HTTP binds to 127.0.0.1:8080; the database exposes no host port. Place an HTTPS reverse proxy in front and expose only public/. Bot credentials, domain and Telegram registration remain separately controlled operator work; no registration command is provided here.
Existing database, backup and recovery
Stop all writers, take an encrypted restricted backup, rehearse restoration and migrations in isolation, then apply additive migrations 001–004 with a maintenance account. Review compatibility before reopening traffic.
Legacy columns are retained but become stale after new writes. Code-only rollback is unsafe. Restore application and matching database together only under an operator-approved recovery plan. Never delete a valuable database volume.
Migration referenceOperations and worker supervision
Supervise the worker separately from HTTP health. A healthy web endpoint does not establish worker liveness or Telegram connectivity. Protect logs and backups, monitor pending/failed queues and document retention and key recovery. Do not clear leases blindly after a crash: external delivery may already have succeeded.
Deployment and recovery reference09 / Evidence & limits
Test the rules.
Respect the boundaries.
The repository tests PHP 8.0–8.4, MySQL 8.0 and MariaDB 10.11, capacity races, transactions, synthetic workflows and container install/restore. PHPStan and coding-standard checks cover the application and retained legacy renderer.
These checks do not certify a live Telegram account, production host, payment provider or backup policy. Prices are integer IRR; entry uses Gregorian dates with configurable display timezone and UTC storage. Group records describe seat counts, not individual companion identities.
Review the acceptance gates before independently operating the application. The source remains GPL-3.0-only; its notices and licensing obligations apply.
Source code, explained honestly.
Explore the architecture.
Plan your own installation.
No active tour inventory, reservation form, payment portal or Telegram conversation is provided here.