The backend is built using Rust with the Actix-web framework. It provides RESTful APIs for poll creation, management, and real-time updates. The database used is MongoDB. Authentication is handled using Passkey Authentication (WebAuthn/FIDO2) and JWT tokens.
- User authentication with Passkeys and JWT.
- Poll creation, deletion, and management.
- Real-time updates using Server-Sent Events (SSE).
- Protected routes using JWT custom middleware function.
-
Routes:
-
Authentication
POST /api/auth/register/start
: Initiates Passkey registration.POST /api/auth/register/finish
: Completes Passkey registration.POST /api/auth/login/start
: Initiates Passkey authentication.POST /api/auth/login/finish
: Completes Passkey authentication.
-
Poll
GET /api/
: Retrieves all polls.POST /api/polls
: Creates a new poll.GET /api/polls/[pollId]
: Retrieves poll details.POST /api/polls/[pollId]/vote
: Casts vote for a poll option.POST /api/polls/[pollId]/close
: Closes a poll (only for poll creators).POST /api/polls/[pollId]/reset
: Resets votes for a poll (only for poll creators).
-
Real Time Updates
GET /api/socket/create-client
: Creates an SSE client and sends to client for real-time updates.
-
-
Libraries:
webauthn-rs
for WebAuthn implementation.jsonwebtoken
for JWT handling.actix-web
for Web Server Setup.
- Technology: MongoDB
- Structure:
user
collection for storing user data.poll
collection for poll details.
- Environment Variables:
DATABASE_URL
: MongoDB connection string.JWT_SECRET
: Secret key for JWT.DATABASE_NAME
: MongoDB Database name.
Before setting up the project, make sure you have the following installed:
- Rust: Follow the installation guide on Rust's official website.
- MongoDB: Install MongoDB locally or use a cloud service like MongoDB Atlas.
- OpenSSL: Required for Passkey (WebAuthn) authentication.
-
Clone the repository:
git clone https://github.com/Azeem-0/polling_application_backend.git cd polling_application_backend
-
Install dependencies
cargo build
-
Set up environment variables:
DATABASE_URL=<your-mongodb-connection-string> JWT_SECRET=<your-secret-key-for-jwt> WEBAUTHN_ORIGIN=<your-web-auth-origin-url>
-
Run the server:
cargo run
- Access the api endpoints as described in the documentation above.
You can view the documentation of the APIs on http://localhost:3001/swagger-ui/.