A comprehensive survey platform with Telegram bot integration, built with Next.js, Prisma, and PostgreSQL. This platform allows administrators to create surveys and questions, while users can participate via a Telegram bot. The web interface provides detailed analytics with pie charts and demographic breakdowns.
- User registration with demographic information (name, age, gender, region)
- Interactive survey participation with targeted questions
- Questions automatically filtered based on user demographics
- Multiple choice questions with inline keyboards
- Progress tracking through surveys
- Direct database integration (no API calls for answers)
- Analytics Dashboard: View survey results with interactive pie charts
- Admin Panel: Complete CRUD operations for topics and questions
- Question Targeting: Create questions for specific demographics (age, gender, region)
- Auto-Notifications: Automatically send new questions to targeted users via Telegram
- User Management: View and filter users by demographics
- Real-time Data: Live updates of survey responses
- Security: Authentication, rate limiting, input validation, CSRF protection
- Pie charts for answer distribution
- Demographic breakdowns (by gender, age groups, regions)
- Response tracking and statistics
- Export capabilities
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Prisma ORM
- Database: PostgreSQL
- Charts: Recharts
- Bot: node-telegram-bot-api
- Styling: Tailwind CSS with dark mode support
- Dev Tools: Biome (linting/formatting), TypeScript
- Node.js 18+
- PostgreSQL database
- Telegram Bot Token (from @BotFather)
-
Clone and Install
git clone <repository-url> cd library npm install
-
Environment Setup Copy
.env.exampleto.envand configure:DATABASE_URL="postgresql://user:password@host:port/database" TELEGRAM_BOT_TOKEN="your_telegram_bot_token_here"
-
Database Setup
# Run database migrations npm run db:migrate # Generate Prisma client npm run db:generate # Seed initial data (optional) npm run seed
-
Create Admin User
# Create the first admin user npm run create-admin -
Development
# Start the web application npm run dev # Start the Telegram bot (in another terminal) npm run bot
-
Production
# Build the application npm run build # Start both web app and bot together npm start
Open http://localhost:3000 to view the web interface.
-
Analytics Dashboard (
/)- View all topics and their questions
- Select questions to see detailed analytics
- Interactive pie charts show answer distributions
- Demographic breakdowns available
-
Admin Panel (
/admin)- Topics Tab: Create, view, and delete survey topics
- Questions Tab: Add questions with multiple options to topics
- Users Tab: View registered users and apply demographic filters
-
Registration
- Send
/startto begin registration - Provide name, age, gender, and region
- Registration is required before participating
- Send
-
Surveys
- Send
/surveysto see available topics - Select a topic to start answering questions
- Navigate through questions with inline keyboards
- Receive completion confirmation
- Send
GET/POST /api/topics- Topics managementGET/PUT/DELETE /api/topics/[id]- Individual topic operationsPOST /api/questions- Create questionsGET/PUT/DELETE /api/questions/[id]- Question operationsGET /api/questions/[id]/analytics- Question analyticsGET/POST /api/users- User operations (with filtering)POST /api/answers- Submit answers
tgId(String, Primary Key): Telegram user IDname(String): User's full namegender(String): "male" or "female"region(String): Uzbekistan regionage(Int): User's age
id(Int, Auto-increment): Topic IDname(String, Unique): Topic namequestions[]: Related questions
id(Int, Auto-increment): Question IDname(String): Question textoptions(String[]): Array of answer optionstopicId(Int): Foreign key to TopictargetGender(String, Optional): Target gender ("male"/"female" or null for all)targetMinAge(Int, Optional): Minimum age for targetingtargetMaxAge(Int, Optional): Maximum age for targetingtargetRegions(String[], Optional): Array of target regions
id(Int, Auto-increment): Answer IDoption(String): Selected optionquestionId(Int): Foreign key to QuestionuserTgId(String): Foreign key to User- Unique constraint on (questionId, userTgId)
# Development
npm run dev # Start Next.js development server
npm run bot # Start Telegram bot
# Database
npm run db:migrate # Run Prisma migrations
npm run db:generate # Generate Prisma client
npm run db:studio # Open Prisma Studio
npm run seed # Seed initial data
# Production
npm run build # Build for production
npm start # Start both web app and Telegram bot
npm run start:web # Start only web app
npm run start:bot # Start only Telegram bot
# Code Quality
npm run lint # Check code with Biome
npm run format # Format code with Biomesrc/
├── app/
│ ├── api/ # Next.js API routes
│ │ ├── topics/ # Topic CRUD operations
│ │ ├── questions/ # Question CRUD operations
│ │ ├── users/ # User management
│ │ └── answers/ # Answer submissions
│ ├── admin/ # Admin panel page
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Analytics dashboard
├── bot/
│ └── telegram-bot.ts # Telegram bot implementation
├── components/
│ └── PieChart.tsx # Reusable chart component
├── lib/
│ ├── prisma.ts # Prisma client setup
│ └── database.ts # Database service functions
prisma/
├── schema.prisma # Database schema
└── migrations/ # Database migrations
scripts/
└── seed.ts # Database seeding script
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy automatically on push
- Create a new service
- Connect repository
- Set build command:
npm install && npm run db:generate - Set start command:
npm run bot - Add environment variables
- Use managed PostgreSQL from Vercel, Railway, or Supabase
- Update
DATABASE_URLin environment variables
- Fork the repository
- Create a feature branch
- Make your changes
- Run
npm run lintandnpm run format - Submit a pull request
MIT License - see LICENSE file for details.