> For the complete documentation index, see [llms.txt](https://docs.hipersnipe.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hipersnipe.com/architecture/overview.md).

# System overview

HiperSnipe follows a layered architecture: Telegram UI handlers on top, asset/PnL services in the middle, and blockchain execution at the bottom.

## High-level diagram

```
┌─────────────────────────────────────────────────────────────┐
│                     Telegram users                          │
└──────────────────────────┬──────────────────────────────────┘
                           │
┌──────────────────────────▼──────────────────────────────────┐
│  main.py (aiogram)                                          │
│  handlers/  menus.py  shared.py                             │
└──────────┬───────────────────────────────┬──────────────────┘
           │                               │
┌──────────▼──────────┐         ┌──────────▼──────────────────┐
│  assets.py          │         │  limit_engine.py          │
│  pnl_tracker.py     │         │  WSS price oracle         │
│  db_handler_aio.py  │◄───────►│  TP/SL + limit execution  │
└──────────┬──────────┘         └──────────┬────────────────┘
           │                               │
┌──────────▼───────────────────────────────▼──────────────────┐
│  swap.py  swap_engine/  swap_jupiter.py  swap_pumpfun.py   │
│  wallet.py  rpc_manager.py  utils/solana_rpc.py            │
└──────────────────────────┬──────────────────────────────────┘
                           │
┌──────────────────────────▼──────────────────────────────────┐
│  Solana mainnet (Helius RPC, Jito, Jupiter, Pump.fun)       │
└─────────────────────────────────────────────────────────────┘
```

## Core principles

1. **Handlers own UI** — All Telegram interaction lives in `handlers/`.
2. **DB owns state** — User settings, orders, shields, and encrypted keys in SQLite via `db_handler_aio.py` and `db/*_dao.py`.
3. **Engines own automation** — `limit_engine.py` executes limits and shields; `dca_engine.py` runs DCA schedules.
4. **Swap layer owns chain** — `swap.py` and `swap_engine/` build and send transactions.

## Data flow: paste CA → trade

1. User pastes a contract address in any chat.
2. `handlers/trading_ca_handler.py` detects the mint.
3. `handlers/trading_token_ui.py` builds the Trading UI (parallel metadata, balance, PnL).
4. User taps Buy → `handlers/trading_buy_sell.py` → `handlers/trading_execution.py` resolves slippage/fees.
5. `swap.py` routes to Pump direct, Lightning, or Jupiter.
6. Trade recorded in `users.trades` JSON; PnL replayed by `pnl_tracker.py`.

## Multi-process design

| Process           | Writes DB          | Reads WSS | Sends txs               |
| ----------------- | ------------------ | --------- | ----------------------- |
| `main.py`         | Yes (user actions) | No        | Yes (manual buys/sells) |
| `limit_engine.py` | Yes (order state)  | Yes       | Yes (automated exits)   |

SQLite WAL mode allows concurrent reads/writes across processes.

## Related pages

* [Bot and background engines](/architecture/bot-and-engines.md)
* [Swap engine and routing](/architecture/swap-engine.md)
* [Database and migrations](/architecture/database.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hipersnipe.com/architecture/overview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
