A Telegram Mini App built with Next.js 16 that supports Bitcoin membership reward accrual with subscription management for Sri Lankan users.
- Telegram Integration: Native Telegram Mini App experience with SDK integration
- Bitcoin Wallet: Track Bitcoin balance and transactions in satoshis
- Membership Plans: Weekly and monthly subscription plans with automatic Bitcoin rewards
- Payment Integration: PayHere payment gateway for Sri Lankan Rupee transactions
- KYC Verification: User verification system for compliance
- Reward Tracking: Visual charts showing Bitcoin price history and membership rewards
- Referral System: Earn rewards for inviting friends
- Currency Formatting: LKR/satoshi amounts formatted for Sri Lankan users
- Framework: Next.js 16 with App Router
- Language: TypeScript
- Styling: Tailwind CSS with hand-built UI primitives (
src/components/ui/) - Database: MongoDB with Mongoose ODM
- State Management:
- Zustand (global state)
- TanStack Query (server state management)
- Forms: React Hook Form + Zod validation
- Charts: Chart.js with react-chartjs-2
- Telegram SDK: @telegram-apps/sdk-react
- HTTP Client: Custom
fetchywrapper for API calls
-
Clone the repository
git clone https://github.com/your-repo/BitcoinDeepa-TMA-Bot.git cd BitcoinDeepa-TMA-Bot -
Install dependencies
bun install # or npm install -
Environment Setup Create a
.env.localfile with your environment variables:MONGODB_URI=your_mongodb_connection_string API_BASE_URL=http://localhost:3347
-
Run the development server
bun dev # or npm run dev -
Open in browser Navigate to
http://localhost:3347
# Development
bun dev # Start development server on port 3347
bun start # Start production server on port 3347
# Build and Quality
bun run build # Build production bundle
bun run lint # ESLint code checking
bun run format # Prettier code formatting
# Git Hooks
bun run init-git-hooks # Initialize git hooks from .githooks/Important: Always run
bun run formatandbun run buildbefore committing changes.
src/
├── app/ # Next.js App Router pages
│ ├── api/ # API routes
│ │ ├── auth/ # Telegram authentication
│ │ ├── packages/ # Membership plan packages
│ │ ├── subscription/ # Subscription management
│ │ ├── transaction/ # Transaction handling
│ │ └── user/ # User management & KYC
│ ├── context/ # App-wide providers (Telegram SDK, theme, TanStack Query)
│ ├── dashboard/ # Main app dashboard (auth-guarded)
│ │ ├── activity/ # Transaction/reward activity feed
│ │ ├── news/ # News listing & article detail
│ │ ├── plans/ # Membership plans
│ │ └── tasks/ # Reward tasks
│ ├── plans/choose/ # Plan selection (onboarding)
│ └── verification/ # KYC verification flow
├── components/ # Reusable components
│ ├── ui/ # Hand-built UI primitives
│ └── dashboard/ # Dashboard-specific components, mirrors app/dashboard structure
├── db/ # Database connection and schema
├── hooks/ # Shared hooks (auth guard, Telegram platform, etc.)
│ └── query/ # TanStack Query hooks, one per endpoint
├── lib/ # Utility libraries
│ ├── auth.ts # Authentication helpers
│ ├── fetchy.ts # HTTP client wrapper
│ ├── query-keys.ts # TanStack Query key registry
│ ├── store.ts # Zustand global state
│ ├── types.ts # TypeScript definitions
│ └── validations.ts # Zod schemas
└── styles/ # Global styles and themes
- All HTTP requests use
fetchyfrom@/lib/fetchy - RESTful API routes in
src/app/api/ - MongoDB connection via
src/db/connect.ts
- Telegram-based authentication using
@/lib/auth - Auth token stored in localStorage
- Dashboard layout (
src/app/dashboard/layout.tsx) runsuseAuthGuardto gate access
- Global UI State: Zustand store (
@/lib/store) - Server State: TanStack Query with keys in
@/lib/query-keys - Form State: React Hook Form with Zod validation
- User: Profile with subscription, wallet, and rewards data
- Subscription: Weekly/monthly membership plans
- Transaction: Bitcoin transactions with multiple types
- Wallet: Bitcoin balance with USD/LKR tracking
The app integrates with PayHere payment gateway for Sri Lankan users:
- Subscription plans in Sri Lankan Rupees (LKR)
- Automatic Bitcoin purchase with membership plans
- Real-time Bitcoin price tracking
- Transaction history with detailed analytics
- Telegram Web App security validation
- Token-based authentication
- KYC verification system
- Secure payment processing
- Environment variable protection
- Optimized for mobile viewing (max-width: 28rem /
max-w-md) - Telegram Mini App SDK integration, expanded to full screen on launch
- Bottom navigation for authenticated users
The app is configured for deployment on Railway:
{
"build": {
"builder": "NIXPACKS",
"buildCommand": "bun install && bun run build"
},
"deploy": {
"startCommand": "bun run start",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
},
"environments": {
"production": {
"variables": {
"NODE_ENV": "production",
"NODE_OPTIONS": "--max-old-space-size=512",
"NEXT_TELEMETRY_DISABLED": "1"
}
}
}
}- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes following the coding standards
- Run quality checks:
bun run format && bun run build - Commit your changes:
git commit -m 'feat: add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
feat:for new featuresfix:for bug fixesdocs:for documentation changesstyle:for formatting changesrefactor:for code refactoringtest:for adding testschore:for maintenance tasks
This project is private and proprietary. All rights reserved.
For support and questions:
- Create an issue in this repository
- Contact the development team
Built with ❤️ for the Sri Lankan Bitcoin community 🇱🇰