# zodiadevias/blockchain-based-voting-system architecture

> Architecture diagram of the GitHub repository zodiadevias/blockchain-based-voting-system, 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/zodiadevias/blockchain-based-voting-system
- Repository: https://github.com/zodiadevias/blockchain-based-voting-system

## Overview

##### Project Type and Purpose
- BlockVote is primarily a full-stack decentralized application (DApp) built using Angular for the frontend. It integrates with blockchain smart contracts (managed via Truffle) to handle voting operations in a decentralized manner.
- The Angular portion of the project manages user interactions across several components (authentication, candidate listing, voting interfaces, dashboards, profiles, and results). The smart contract components manage the on-chain voting logic, candidate registration, and state migration (via migrations and Truffle configurations).

##### Project File Structure
- Top-level files and directories indicate both Angular frontend and a smart contract backend:
- The "src" directory contains various Angular components (auth, candidates, dashboard, header, profile, results, vote) and configuration files that make up the client-side application.
- The "contract" directory contains subdirectories with the Solidity smart contracts, Truffle migration scripts, and test files. This confirms a blockchain component in the system.
- Presence of configuration files such as angular.json, truffle-config.js, package.json, and tsconfig files indicate standard Angular and blockchain development practices.
- The contracts folder within "contract" and the associated deployment/migration files indicate that the blockchain portion is central to the vote recording and verification.

##### Key Project Components to Capture in the DFD
a. Client/User Interface:
- Angular Frontend: Represents the entire Angular application (including components like auth, candidates, vote, results, etc.)
- User Agent (Browser): The end user interacts with the application via a web browser.

b. Business Logic / Service Layer:
- Blockchain Service (blockchain.service.ts): Acts as an intermediary between the UI and the blockchain network. This service is responsible for interacting with the smart contracts.

c. Blockchain (Smart Contracts):
- Smart Contracts: Deployed on the blockchain network; manage vote transactions, candidate data, and state management.
- Deployment/Migration Scripts (in the contract/migrations folder): They convey how the smart contracts are deployed and managed on the blockchain.

d. Data Persistence and External Services:
- While there is no traditional database in this project, the blockchain itself serves as the persistent data store for votes and candidates.
- Any client-side state (e.g. using ethers.js or similar libraries referenced in the angular cache) that facilitates interaction with the blockchain network should be represented.

##### Relationships and Data Flow
- Users interact with the Angular frontend via their browsers.
- Responses and events from the blockchain (e.g., successful vote submission, updated candidate counts) flow back through the Blockchain Service to update the UI state.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        A1("User Browser"):::frontend
        subgraph "Angular Frontend Components"
            F1("Auth"):::frontend
            F2("Candidates"):::frontend
            F3("Dashboard"):::frontend
            F4("Header"):::frontend
            F5("Profile"):::frontend
            F6("Results"):::frontend
            F7("Vote"):::frontend
            F8("App"):::frontend
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        B1("Blockchain Service"):::service
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        C1("Smart Contracts (Client)"):::blockchain
        C2("Additional Smart Contracts"):::blockchain
        C3("Truffle Migration Scripts"):::migration
    end

    %% Data Flow Relationships
    A1 -->|"user_input"| F1
    A1 -->|"user_input"| F2
    A1 -->|"user_input"| F3
    A1 -->|"user_input"| F4
    A1 -->|"user_input"| F5
    A1 -->|"user_input"| F6
    A1 -->|"user_input"| F7
    A1 -->|"user_input"| F8

    F1 -->|"service_call"| B1
    F2 -->|"service_call"| B1
    F3 -->|"service_call"| B1
    F4 -->|"service_call"| B1
    F5 -->|"service_call"| B1
    F6 -->|"service_call"| B1
    F7 -->|"service_call"| B1
    F8 -->|"service_call"| B1

    B1 -->|"contract_call"| C1
    C1 -->|"response"| B1
    B1 -->|"ui_update"| F1
    B1 -->|"ui_update"| F2
    B1 -->|"ui_update"| F3
    B1 -->|"ui_update"| F4
    B1 -->|"ui_update"| F5
    B1 -->|"ui_update"| F6
    B1 -->|"ui_update"| F7
    B1 -->|"ui_update"| F8

    C3 -->|"deploy"| C1
    C1 -->|"includes"| C2

    %% Click Events for Angular Frontend Components
    click F1 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/auth"
    click F2 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/candidates"
    click F3 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/dashboard"
    click F4 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/header"
    click F5 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/profile"
    click F6 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/results"
    click F7 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/vote"
    click F8 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/src/app"

    %% Click Event for Blockchain Service
    click B1 "https://github.com/zodiadevias/blockchain-based-voting-system/blob/main/src/blockchain.service.ts"

    %% Click Events for Blockchain Components
    click C1 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/contract/client/src/contracts"
    click C2 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/contract/contracts"
    click C3 "https://github.com/zodiadevias/blockchain-based-voting-system/tree/main/contract/migrations"

    %% Styles
    classDef frontend fill:#A3D5FF,stroke:#1E90FF,stroke-width:2px;
    classDef service fill:#BFFCC6,stroke:#32CD32,stroke-width:2px;
    classDef blockchain fill:#FFE4B5,stroke:#FF8C00,stroke-width:2px;
    classDef migration fill:#FFC0CB,stroke:#FF69B4,stroke-width:2px;
```
