Frontend Architecture
Overview
The frontend of the Blockchain Record Keeping System is built using Next.js, a React framework that enables server-side rendering and static site generation. The application follows modern web development practices with TypeScript for type safety and component-based architecture.
Tech Stack
- Framework: Next.js (App Router)
- Language: TypeScript
- Component Library: Custom components with TailwindCSS
- Web3 Integration: ethers.js
- File Storage: IPFS via Pinata API
Application Structure
src/
├── app/ # Next.js App Router pages
├── components/ # Reusable UI components
├── contracts/ # Contract ABIs
├── lib/ # Utility functions
├── services/ # Service layer (blockchain interactions)
└── types/ # TypeScript type definitions
Key Components
Blockchain Service (src/services/blockchain.ts
)
The blockchain service is the central interface between the frontend and the smart contracts. It provides methods for:
- Initializing wallet connection
- Interacting with smart contracts
- Managing roles and permissions
- Handling record operations
- Student management
Pages
The application includes the following key pages:
- Home (
/
): Landing page with features overview - Login (
/login
): Connect wallet page - Dashboard (
/dashboard
): Role-specific dashboard - Records (
/records
): View and manage records - Add Record (
/records/add
): Form to add new records - Verify (
/verify
): Public record verification - Admin (
/admin
): Admin control panel
UI Components
Custom UI components include:
- Button: Customizable button component
- Header: Navigation and wallet connection
- Footer: Site footer with links
- MainLayout: Layout wrapper with header and footer
Authentication & Authorization
The application uses a wallet-based authentication system:
- Authentication: Users connect their Ethereum wallet (e.g., MetaMask)
- Authorization: The system checks the user's role from the smart contract
- Access Control: UI components and pages adapt based on the user's role
Data Flow
- User Interaction: User interacts with UI components
- Service Layer: Component calls methods in the blockchain service
- Web3 Provider: Service uses ethers.js to interact with the blockchain
- Smart Contract: Contract processes the request and returns data
- UI Update: Service returns data to the component for rendering
File Upload Process
The application uses IPFS for document storage:
- User selects a document file
- Frontend calls the
/api/upload
API route - API route uploads the file to Pinata IPFS service
- Pinata returns an IPFS hash
- IPFS hash is stored in the smart contract with the record
Record Verification
The verification flow allows anyone to verify record authenticity:
- User enters record ID on verification page
- Frontend retrieves record data from blockchain
- System checks record validity
- UI displays verification result with record details
Security Considerations
- Public Data: Record IDs and metadata are public on the blockchain
- Private Data: Actual documents are accessible only to the student and issuing university
- Sharing Model: Students control who can access their records
- Role Separation: Different user roles have separate access permissions