# 1iamcube1/voting_project architecture

> Architecture diagram of the GitHub repository 1iamcube1/voting_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1iamcube1/voting_project
- Repository: https://github.com/1iamcube1/voting_project

## Overview

##### Main Components
- Frontend: Contains all UI elements, static assets (CSS, JavaScript, images), and HTML pages that users interact with.
- Backend: Built in Python (likely using Flask, FastAPI, or a similar framework) that handles business logic, user authentication, data processing, and interactions with the blockchain.
- Blockchain/Smart Contracts: Managed through Truffle, with contract definitions in the contracts folder, migration scripts in the migrations folder, and deployment settings in truffle-config.js.
- Supporting Utilities: Modules for handling blockchain interactions (blockchain.py), database operations (database.py), and sending emails (send_email.py).

##### File Structure and Map Architecture Elements
- Frontend Structure:
- Folder hierarchy (assets, css, js, pages) clearly separates static resources and page templates, which indicates a conventional client-side application.
- Backend Structure:
- Organized into controllers, routes (API endpoints for authentication and voting), and models. This suggests an MVC-like pattern.
- Separate folders for smart contracts (contracts), migration scripts (migrations), and build artifacts (build/contracts) for deploying and interacting with blockchain smart contracts.
- Presence of utility modules that encapsulate specific functionalities (e.g., blockchain integration, database connections).
- Configuration Files:
- .env.example (for environment variables) and requirements.txt (for dependency management) indicate how the project should be set up.
- Truffle configuration (truffle-config.js) under backend suggests direct integration with smart contract deployment tools.

##### Establish Relationships and Interactions
- The UI (frontend) sends requests to the backend via defined API endpoints (auth_routes, vote_routes). These routes handle user interactions such as logging in or casting votes.
- The backend controllers process requests and use models to interact with the database. For voting operations, the backend calls utility functions (blockchain.py) to interact with the smart contracts deployed on the blockchain.
- Smart contracts (Voting.json) are compiled, deployed, and managed by the Truffle framework with deployment and migration scripts, ensuring the decentralized layer maintains vote integrity.

##### Architectural Patterns and Technologies
- MVC (or similar separation of concerns) in the backend.
- Client-Server Architecture: Clear separation between the frontend and backend, with RESTful API endpoints.
- Blockchain Integration: Use of Truffle and Ganache for smart contracts, ensuring votes are recorded and verifiable.
- Emphasis on modularity: Each major functionality (authentication, voting, email notifications, blockchain interaction) is encapsulated in its own module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FAssets["Assets"]:::frontend
        FCSS["CSS"]:::frontend
        FJS["JS"]:::frontend
        FPages["Pages"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        MainApp["Main App (app.py)"]:::backend
        Controllers["Controllers"]:::backend
        Models["Models"]:::backend
        AuthRoutes["Auth Routes"]:::backend
        VoteRoutes["Vote Routes"]:::backend
    end

    %% Utility Components
    subgraph "Utility Modules"
        BlockchainUtil["Blockchain Utility (blockchain.py)"]:::utilities
        DatabaseUtil["Database Utility (database.py)"]:::utilities
        EmailUtil["Email Utility (send_email.py)"]:::utilities
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        Contracts["Contracts"]:::blockchain
        Migrations["Migrations"]:::blockchain
        BuildContracts["Build Contracts"]:::blockchain
        TruffleConfig["Truffle Config"]:::blockchain
    end

    %% Connections between Frontend and Backend API Endpoints
    FPages -->|"triggers"| AuthRoutes
    FPages -->|"triggers"| VoteRoutes

    %% Backend internal connections
    MainApp -->|"initializes"| Controllers
    AuthRoutes -->|"routes_to"| Controllers
    VoteRoutes -->|"routes_to"| Controllers
    Controllers -->|"uses"| Models

    %% Controllers calling utility modules
    Controllers -->|"calls"| BlockchainUtil
    Controllers -->|"calls"| DatabaseUtil
    Controllers -->|"calls"| EmailUtil

    %% Blockchain utility interacting with blockchain components
    BlockchainUtil -->|"invokes"| Contracts

    %% Style Definitions
    classDef frontend fill:#f6d55c,stroke:#000,stroke-width:2px;
    classDef backend fill:#3caea3,stroke:#fff,stroke-width:2px;
    classDef utilities fill:#20639b,stroke:#fff,stroke-width:2px;
    classDef blockchain fill:#ed553b,stroke:#fff,stroke-width:2px;

    %% Click Events for Frontend
    click FAssets "https://github.com/1iamcube1/voting_project/tree/main/frontend/assets"
    click FCSS "https://github.com/1iamcube1/voting_project/tree/main/frontend/css"
    click FJS "https://github.com/1iamcube1/voting_project/tree/main/frontend/js"
    click FPages "https://github.com/1iamcube1/voting_project/tree/main/frontend/pages"

    %% Click Events for Backend
    click MainApp "https://github.com/1iamcube1/voting_project/blob/main/backend/app.py"
    click Controllers "https://github.com/1iamcube1/voting_project/tree/main/backend/controllers"
    click Models "https://github.com/1iamcube1/voting_project/tree/main/backend/models"
    click AuthRoutes "https://github.com/1iamcube1/voting_project/blob/main/backend/routes/auth_routes.py"
    click VoteRoutes "https://github.com/1iamcube1/voting_project/blob/main/backend/routes/vote_routes.py"

    %% Click Events for Utility Modules
    click BlockchainUtil "https://github.com/1iamcube1/voting_project/blob/main/backend/utils/blockchain.py"
    click DatabaseUtil "https://github.com/1iamcube1/voting_project/blob/main/backend/utils/database.py"
    click EmailUtil "https://github.com/1iamcube1/voting_project/blob/main/backend/utils/send_email.py"

    %% Click Events for Blockchain Layer
    click Contracts "https://github.com/1iamcube1/voting_project/tree/main/backend/contracts"
    click Migrations "https://github.com/1iamcube1/voting_project/tree/main/backend/migrations"
    click BuildContracts "https://github.com/1iamcube1/voting_project/tree/main/backend/build/contracts"
    click TruffleConfig "https://github.com/1iamcube1/voting_project/blob/main/backend/truffle-config.js"
```
