The SQR Voting System is a web-based platform designed for creating, managing, and participating in surveys and polls. The system allows users to register, log in, create polls with single or multiple-choice answers, vote in polls, and view survey results. Authorized users can also close polls at any time or set a specific closing date for a poll.
- Egor Nisckikh - Team Leader, Backend Developer
- Almaz Gayazov - Backend Developer, Tester
- Renata Latypova - Backend Developer, Tester
- Artemij Volkonitin - Tester
- Julia Martynova - Frontend Developer
- Python 3.11+
- Poetry
- SQLite
-
Clone the repository:
git clone https://github.com/Fridorovich/voting.git
-
Install dependencies:
poetry install
-
Create a
.envfile with the following content:DATABASE_URL=sqlite:///./sqr_voting.db SECRET_KEY=your-secret-key ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 REFRESH_TOKEN_EXPIRE_DAYS=7
-
Apply database migrations:
alembic upgrade head
-
Run the server:
uvicorn app.main:app --reload
-
Access documentation at:
http://127.0.0.1:8000/docs
- Python 3.11
- FastAPI - Web framework
- SQLite - Database
- Poetry - Dependency management
- Alembic - Database migrations
- JWT - Authentication
- Pytest - Testing framework
- Coverage.py - Test coverage analysis
- Flake8, Bandit - Code quality and security analysis
- Streamlit - Frontend
- Docker, Docker Compose - Containerization and orchestration
- Authentication Module: User registration, login, token generation, and refresh mechanisms.
- Voting Module: Poll creation, voting, and result viewing.
- Administration Module: Poll management, closing polls, and setting poll expiration dates.
- User registration and authentication using JWT tokens.
- Poll creation with single/multiple choice options.
- Voting functionality with single-use voting and the ability to change votes.
- Poll closing by the creator or automatically based on set dates.
- Poll result viewing with real-time updates.
- Robust error handling and logging for all actions.
The CI pipeline is implemented using GitHub Actions. The pipeline includes the following stages:
-
Setup: The environment is configured to use Python 3.11.
-
Dependency Installation: Poetry is installed and dependencies are managed in an isolated environment.
-
Code Quality Analysis:
flake8is run to check code style compliance with PEP8.banditis used for security analysis to identify potential vulnerabilities.
-
Testing:
- All tests are executed using
pytestwith detailed output enabled. - Test coverage is assessed with
coverage.py. The coverage report is generated in HTML format and currently shows 89% coverage.
- All tests are executed using
-
Dockerization:
- If the branch is
main, the Docker image is built and pushed to Docker Hub usingdocker/build-push-action.
- If the branch is
- The application is containerized using Docker and orchestrated with Docker Compose.
- The
backendservice is built from the Dockerfile and exposed on port 8000. - The application applies database migrations on startup using Alembic.
- Data persistence is handled through volume mounts for the SQLite database.
-
Build the image:
docker-compose build
-
Run the container:
docker-compose up
-
Stop the container:
docker-compose down
-
The project is managed using Poetry, a robust tool for dependency management and packaging.
-
The
pyproject.tomlfile defines dependencies in two groups:main: Production dependencies such asfastapi,sqlalchemy,uvicorn.dev: Development tools likeflake8,bandit,pytest-cov.
-
To install dependencies:
poetry install --with dev
The logging system is implemented using Python's built-in logging module. The logging configuration is initialized in the setup_logging() function, located in the app/shared/logging.py file.
-
Log Directory: Logs are stored in the
logsdirectory. If the directory does not exist, it is automatically created. -
Log File: The main log file is
sqr_voting_system.log. -
Log Rotation:
- Maximum file size: 10 MB
- Backup count: 5 log files are retained before the oldest logs are removed.
-
Log Format: The log format includes the timestamp, log level, module name, and the log message. Example:
[2025-05-08 14:23:56] [INFO] [app.modules.auth.services] User authenticated: id=1 -
Log Levels: The system logs events at the following levels:
INFO,WARNING,ERROR,CRITICAL.
- The testing strategy includes unit testing, integration testing, and security testing.
- All tests are located in the
app/tests/directory and are structured by module (e.g.,auth,voting).
-
Total test coverage: 89%
-
Key coverage results:
app/modules/auth/routes.py: 100%app/modules/auth/services.py: 100%app/modules/voting/routes.py: 67%app/modules/voting/services.py: 70%app/modules/admin/routes.py: 54%app/modules/admin/routes.py: 98%
-
Maintainability Index: A (calculated using
radon mi). All files in the project received a rating ofA, indicating a high level of maintainability. -
Recovery Time (MTTR): 0.296 seconds (measured using docker-compose up -d), significantly below the target of 15 minutes.
-
Performance Analysis:
- Poll creation: Average response time - 2 ms, Min - 1 ms, Max - 4 ms (target ≤ 500 ms)
- Voting: Average response time - 2 ms, Min - 0 ms, Max - 4 ms (target ≤ 300 ms)
- Result retrieval: Average response time - 2 ms, Min - 0 ms, Max - 9 ms (target ≤ 1 second)
- Passwords are hashed using JWT and bcrypt.
- Protection against SQL Injection and XSS.
- All actions are logged for accountability.
- Implementing structured testing and coverage analysis significantly reduces potential bugs.
- Automated CI pipelines streamline deployment and testing.
- Comprehensive Dockerization ensures consistency across environments.
- Increase test coverage for the
votingandadminmodules to align with the 100% goal achieved in theauthmodule. - Implement additional security checks with Bandit for more comprehensive analysis.
- Expand the frontend to provide a more interactive user experience.
- Public access: https://voting-inno.ru or http://79.174.93.194:8501/