Public
Like
my-first-val
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
02_http.tsx
https://ikeali--3369502e3f9f11f0976576b3cceeab13.web.val.run
A comprehensive online voting platform built with Val Town, featuring secure authentication, poll management, and real-time results.
- User Authentication: Secure login/registration system
- Poll Management: Create, edit, and manage voting polls
- Voting Interface: Clean, intuitive voting experience
- Real-time Results: Live vote counting and result display
- Admin Dashboard: Manage polls and view analytics
- Security: One vote per user per poll enforcement
├── backend/
│ ├── database/
│ │ ├── migrations.ts # Database schema setup
│ │ └── queries.ts # Database query functions
│ ├── routes/
│ │ ├── auth.ts # Authentication endpoints
│ │ ├── polls.ts # Poll management endpoints
│ │ ├── votes.ts # Voting endpoints
│ │ └── static.ts # Static file serving
│ └── index.ts # Main Hono app entry point
├── frontend/
│ ├── components/
│ │ ├── App.tsx # Main React app
│ │ ├── Login.tsx # Login/register component
│ │ ├── PollList.tsx # List of available polls
│ │ ├── PollDetail.tsx # Individual poll voting interface
│ │ ├── CreatePoll.tsx # Poll creation form
│ │ └── Results.tsx # Results display component
│ ├── index.html # Main HTML template
│ ├── index.tsx # Frontend entry point
│ └── style.css # Custom styles
└── shared/
├── types.ts # Shared TypeScript types
└── utils.ts # Shared utility functions
- id (PRIMARY KEY)
- username (UNIQUE)
- email (UNIQUE)
- password_hash
- is_admin
- created_at
- id (PRIMARY KEY)
- title
- description
- creator_id (FOREIGN KEY)
- start_date
- end_date
- is_active
- created_at
- id (PRIMARY KEY)
- poll_id (FOREIGN KEY)
- option_text
- vote_count
- id (PRIMARY KEY)
- poll_id (FOREIGN KEY)
- user_id (FOREIGN KEY)
- option_id (FOREIGN KEY)
- voted_at
POST /api/auth/register
- User registrationPOST /api/auth/login
- User loginPOST /api/auth/logout
- User logoutGET /api/auth/me
- Get current user
GET /api/polls
- List all active pollsGET /api/polls/:id
- Get specific poll detailsPOST /api/polls
- Create new poll (authenticated)PUT /api/polls/:id
- Update poll (creator/admin only)DELETE /api/polls/:id
- Delete poll (creator/admin only)
POST /api/votes
- Cast a voteGET /api/polls/:id/results
- Get poll results
- The system uses SQLite for data storage
- Authentication uses session-based cookies
- The frontend is a React SPA with TailwindCSS
- Real-time updates use polling (can be upgraded to WebSockets)
- Password hashing with bcrypt
- Session-based authentication
- CSRF protection
- One vote per user per poll enforcement
- Input validation and sanitization