143 lines
4.8 KiB
Markdown
143 lines
4.8 KiB
Markdown
# Activity Inventory - Questionnaire Voting App
|
|
|
|
A web application that allows admins to create shareable questionnaires where users can add activities and vote on them using upvotes and downvotes.
|
|
|
|
## Tech Stack
|
|
|
|
- **Frontend**: React 18, TypeScript, Vite, Tailwind CSS
|
|
- **Backend**: Express.js, TypeScript
|
|
- **Database**: SQLite with `better-sqlite3`
|
|
- **Containerization**: Docker with multi-stage build
|
|
|
|
## Features
|
|
|
|
- **Admin Dashboard**: Create and manage questionnaires with unique shareable URLs
|
|
- **User Management**: Add/remove admin users and change passwords
|
|
- **Public Voting**: Share questionnaire URLs for users to add activities and vote
|
|
- **Upvote/Downvote System**: Users can upvote or downvote activities
|
|
- **Comments**: Users can comment on activities and reply to comments
|
|
- **Name Persistence**: Visitor names are stored in cookies for 30 days
|
|
- **Docker Support**: Easy deployment with Docker and docker-compose
|
|
|
|
## Quick Start with Docker
|
|
|
|
1. Clone the repository and navigate to the project directory
|
|
|
|
2. Start the application:
|
|
```bash
|
|
docker-compose up -d --build
|
|
```
|
|
|
|
3. Access the app at `http://localhost:4000`
|
|
|
|
4. Login with default credentials:
|
|
- Username: `admin`
|
|
- Password: `admin123`
|
|
|
|
5. Create a questionnaire and share the unique URL with participants
|
|
|
|
## Development Setup
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
2. Start the development servers (frontend + backend):
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
3. Access the app at `http://localhost:5177` (Vite dev server)
|
|
- API requests are proxied to `http://localhost:4000`
|
|
|
|
## Configuration
|
|
|
|
Environment variables can be set in `docker-compose.yml` or via a `.env` file:
|
|
|
|
| Variable | Description | Default |
|
|
|----------|-------------|---------|
|
|
| `PORT` | Server port | `4000` |
|
|
| `SESSION_SECRET` | Secret for session encryption | `super-secret-session-key-change-me` |
|
|
| `DB_PATH` | SQLite database path | `/app/data/questionnaire.db` |
|
|
| `DEFAULT_ADMIN_USER` | Default admin username | `admin` |
|
|
| `DEFAULT_ADMIN_PASS` | Default admin password | `admin123` |
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
questionnaire/
|
|
├── docker-compose.yml # Docker Compose configuration
|
|
├── Dockerfile # Multi-stage Docker build
|
|
├── package.json # Node.js dependencies
|
|
├── vite.config.ts # Vite configuration
|
|
├── tailwind.config.js # Tailwind CSS configuration
|
|
├── tsconfig.json # TypeScript configuration
|
|
├── index.html # HTML entry point
|
|
├── server/ # Express backend (TypeScript)
|
|
│ ├── index.ts # Server entry point
|
|
│ ├── database.ts # SQLite database operations
|
|
│ ├── middleware/
|
|
│ │ └── auth.ts
|
|
│ └── routes/
|
|
│ ├── admin.ts
|
|
│ ├── auth.ts
|
|
│ └── questionnaire.ts
|
|
└── src/ # React frontend (TypeScript)
|
|
├── main.tsx # React entry point
|
|
├── App.tsx # App router
|
|
├── index.css # Tailwind imports
|
|
├── context/
|
|
│ └── AuthContext.tsx
|
|
├── components/
|
|
│ ├── AdminLayout.tsx
|
|
│ └── ProtectedRoute.tsx
|
|
└── pages/
|
|
├── Login.tsx
|
|
├── Dashboard.tsx
|
|
├── QuestionnaireForm.tsx
|
|
├── QuestionnaireDetail.tsx
|
|
├── Users.tsx
|
|
├── ChangePassword.tsx
|
|
├── PublicQuestionnaire.tsx
|
|
└── NotFound.tsx
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### Public Routes
|
|
- `GET /api/q/:uuid` - Get questionnaire data
|
|
- `POST /api/q/:uuid/set-name` - Set visitor name
|
|
- `POST /api/q/:uuid/activities` - Add an activity
|
|
- `POST /api/q/:uuid/activities/:id/vote` - Vote on an activity
|
|
- `GET /api/q/:uuid/activities/:id/comments` - Get comments
|
|
- `POST /api/q/:uuid/activities/:id/comments` - Add a comment
|
|
|
|
### Auth Routes
|
|
- `GET /api/auth/status` - Check authentication status
|
|
- `POST /api/auth/login` - Login
|
|
- `POST /api/auth/logout` - Logout
|
|
|
|
### Admin Routes (requires authentication)
|
|
- `GET /api/admin/questionnaires` - List all questionnaires
|
|
- `POST /api/admin/questionnaires` - Create questionnaire
|
|
- `GET /api/admin/questionnaires/:id` - Get questionnaire details
|
|
- `PUT /api/admin/questionnaires/:id` - Update questionnaire
|
|
- `DELETE /api/admin/questionnaires/:id` - Delete questionnaire
|
|
- `DELETE /api/admin/activities/:id` - Delete activity
|
|
- `GET /api/admin/users` - List all users
|
|
- `POST /api/admin/users` - Create user
|
|
- `DELETE /api/admin/users/:id` - Delete user
|
|
- `POST /api/admin/change-password` - Change password
|
|
|
|
## Security Notes
|
|
|
|
- Change the default admin password immediately after first login
|
|
- Set a strong `SESSION_SECRET` in production
|
|
- The application uses bcrypt for password hashing
|
|
- Session cookies are HTTP-only
|
|
|
|
## License
|
|
|
|
MIT
|