A monorepo for a Solana-backed group fund and Telegram integration. This repository contains a Next.js frontend, a Bun-based backend, a Telegram bot, a Prisma/Postgres data package, UI components, and an Anchor (Solana) smart contract program.
This README explains the repository layout, prerequisites, development workflow, environment variables, and useful commands for local development (Windows PowerShell examples included).
- Monorepo managed with
turboand Bun workspaces - Runtime:
bun(project configured withbun@1.2.22) and Node >= 18 - Frontend: Next.js (React 19)
- Backend & Bot: Bun + TypeScript (simple HTTP API + Telegram bot using
telegraf) - DB: PostgreSQL + Prisma
- Smart contract: Solana Anchor (Rust)
apps/backend/- Bun TypeScript backend (Express-based controllers and Solana services)telegram-bot/- Bun TypeScript Telegram bot (usestelegraf)web/- Next.js frontend (user-facing UI)docs/- Documentation site (Next.js)
packages/db/- Prisma schema + database client package (@repo/db)ui/- React UI component library (@repo/ui)eslint-config/,typescript-config/- shared config packages
contract/groupchat_fund/- Anchor program (Solana smart contract)package.json- top-level scripts powered byturbo
-
Install prerequisites (choose the tools you prefer):
-
Install Bun (recommended):
iwr https://bun.sh/install -useb | iex
-
Ensure Node >= 18 is available (some tools may use Node). For Anchor/contract you will need Rust and Solana toolchain (see Contracts section).
-
Install PostgreSQL (or use a hosted PostgreSQL). Create a database and get a
DATABASE_URLconnection string.
-
-
Install dependencies for the monorepo (root):
# from repository root bun install -
Development: run all dev tasks with Turbo (root):
bun run dev
That will run
devscripts in packages matching their package.json (for example: Next.jsweb, Bunbackend, Buntelegram-bot).
Alternatively, run per-app locally from their folders:
-
Backend (in
apps/backend):cd apps\backend bun run dev
-
Telegram bot (in
apps/telegram-bot):cd apps\telegram-bot bun run dev -
Web (in
apps/web):cd apps\web bun run dev # opens on http://localhost:3000 by default
-
The Prisma schema is in
packages/db/prisma/schema.prisma. It expects aDATABASE_URLenvironment variable. -
Common Prisma commands (from repo root or
packages/db):# generate client npx prisma generate # run migrations (development) npx prisma migrate dev --name init # open studio npx prisma studio
If using Bun exclusively, you can run
bunx prisma generateinstead ofnpx.
-
The Anchor program is in
contract/groupchat_fund. Building and deploying Anchor programs requires the Rust toolchain,anchorCLI andsolanaCLI. -
Typical commands (recommended to run in a Unix-like environment or WSL on Windows):
# in contract/groupchat_fund anchor build anchor deploy --provider.cluster Devnet -
Note: Solana program deployment usually requires a Unix-like shell and Solana CLI setup; on Windows we recommend using WSL2 or a remote Linux environment.
The project uses dotenv in several packages. Common environment variables referenced across the codebase:
DATABASE_URL- Postgres connection string used by PrismaBOT_TOKEN- Telegram bot token (used by backend & bot)BACKEND_URL- Backend API base URL (used by bot and web)WEB_APP_URL- Public URL of the web app (optional)ENCRYPTION_KEY- Hex-encoded symmetric key used to encrypt user private keys (must be provided)SOLANA_RPC_URL/NEXT_PUBLIC_SOLANA_RPC_URL- Solana RPC endpoint (defaults to Devnet)PROGRAM_ID- Optional override for the deployed Anchor program ID
Set these in a .env file in the relevant app (for example apps/backend/.env, apps/telegram-bot/.env, packages/db/.env) or set them via your environment.
Example .env (DO NOT COMMIT):
DATABASE_URL=postgresql://user:password@localhost:5432/arm_groupchat
BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
BACKEND_URL=http://localhost:5000
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
SOLANA_RPC_URL=https://api.devnet.solana.com
PROGRAM_ID=JDomJJbEK48FriJ5RVuTmgDGbNN8DLKAv33NdTydcWWdbun run dev- rundevacross workspace viaturbobun run build- runbuildacross workspace viaturbobun run lint- run lint across workspace viaturbobun run format- run Prettier formatting on repository files
You can also run scripts in each package using bun or npm from that package's folder.
- The backend and bot are Bun-first projects. They use Bun's script runner and expect
bunfor the fastest experience, but most packages will also work using Node tooling andnpxwhere appropriate. - The frontend
webanddocsapps are Next.js projects and run on standard Next tooling (next dev,next build). - Shared UI components live in
packages/uiand are consumed byapps/webandapps/docs. - Database model and relations are defined with Prisma in
packages/db.
This section describes a typical end-user journey when using ARM GroupChat via Telegram and the web dashboard.
-
1) Join the group fund
- A group admin initializes a fund (via the web dashboard or bot command) with parameters like
minContribution,tradingFeeBps, andfundName. - Members join by interacting with the Telegram bot or linking their wallet in the web app. The bot registers users by their Telegram ID and (optionally) wallet address.
- A group admin initializes a fund (via the web dashboard or bot command) with parameters like
-
2) Contribute
- A member sends a command to the Telegram bot (e.g.
/contribute) or uses the web UI to start a contribution. - The backend returns an on-chain instruction or deposit address; the member approves the transaction with their Solana wallet (or follows instructions in the bot).
- On success, the Anchor program mints shares proportional to the contribution and records a contribution transaction in the Prisma database.
- A member sends a command to the Telegram bot (e.g.
-
3) Track fund & share balances
- Members can request the fund status and their share balance from the bot (e.g.
/fund_status) or view the dashboard in the web app. - All contributions, transactions, and distributions are logged in the Postgres DB and optionally referenced by on-chain signatures.
- Members can request the fund status and their share balance from the bot (e.g.
-
4) Distributions / Withdrawals
- When a distribution is triggered (profit-only or full cashout), the backend coordinates with the Anchor program to burn shares and transfer SOL following the fund's rules.
- The bot notifies members of completed payouts and provides transaction signatures for on-chain verification.
-
5) Security & Recovery
- User private keys (if stored) are encrypted with the
ENCRYPTION_KEY; users are encouraged to manage keys locally when possible. - Failed syncs or on-chain errors are captured in
FailedSyncrecords (see Prisma schema) for retries and manual review.
- User private keys (if stored) are encrypted with the
- Please open issues or pull requests against this repository. Keep changes scoped to a package where possible.
- Follow code style (Prettier + ESLint config in
packages/*). Usebun run formatandbun run lintat root.
No license specified in repository. Check with the project owner before using this code in production.
If you need help understanding specific parts of the repo (backend controllers, solana services, telegram handlers), open an issue or reach out to the repository owner/maintainers.