Architecture Overview
GenLayer Points is a full-stack web application built with a Django REST API backend and a Svelte 5 frontend, connected through RESTful APIs. The system uses blockchain integration for authentication and validator data.Technology Stack
Frontend
Svelte 5
Modern reactive UI framework with runes mode for optimal performance and developer experience.
Vite
Fast build tool with hot module replacement and optimized production builds.
Tailwind CSS
Utility-first CSS framework for rapid UI development with consistent styling.
Axios
HTTP client for API communication with interceptors for auth and error handling.
Backend
Django 4.2+
Robust web framework with ORM, admin interface, and extensive ecosystem.
Django REST Framework
Powerful toolkit for building Web APIs with serialization and viewsets.
PostgreSQL
Production database with ACID compliance and advanced features.
SIWE
Sign-In With Ethereum for decentralized authentication.
Infrastructure
- AWS App Runner - Managed container service for backend
- AWS Amplify - Frontend hosting with CI/CD
- AWS RDS - Managed PostgreSQL database
- Docker - Containerization for consistent deployments
Component Architecture
Backend Components
Django Apps Structure
Each Django app follows the Model-View-Serializer pattern:Core Apps
- users
- contributions
- leaderboard
- validators
- builders
- stewards
Purpose: User management and authenticationKey Models:
User- Custom user model with email auth and Ethereum address
- User registration and profile management
- Ethereum address linking
- GitHub OAuth integration
- Referral system
/api/v1/users/me/- Current user profile/api/v1/users/by-address/{address}/- User lookup
Frontend Components
Component Hierarchy
State Management
Svelte Stores for global state:authState- Authentication status and wallet addressuserStore- Current logged-in user datatoastStore- Notification queue
Data Flow
Contribution Submission Flow
Authentication Flow
Leaderboard Calculation
Key Design Patterns
Backend Patterns
1. Base Model Pattern
All models inherit fromBaseModel for automatic timestamps:
2. Context-Aware Serialization
Optimize API performance with light serializers:3. Signal-Based Updates
Automatic leaderboard updates via Django signals:4. Frozen Points Pattern
Points are calculated once and frozen to prevent retroactive changes:Frontend Patterns
1. Component Composition
Reusable components with props:2. Store Pattern
Global state with Svelte stores:3. API Client Pattern
Centralized API with interceptors:Security Architecture
Authentication
- SIWE (Sign-In With Ethereum) for wallet-based auth
- Session cookies (httpOnly, secure, sameSite)
- CSRF protection for state-changing operations
- No JWT in localStorage (security best practice)
Authorization
- Django permissions for admin operations
- Object-level permissions for user-owned resources
- Steward roles for submission review
Input Validation
- Django model validation at database level
- DRF serializer validation at API level
- Frontend validation for user experience
- reCAPTCHA v2 for spam prevention
Data Protection
- Environment variables for secrets
- AWS Parameter Store for production config
- HTTPS only in production
- CORS configuration for API access control
Performance Considerations
Backend Optimizations
-
Query Optimization
select_related()for ForeignKey/OneToOneprefetch_related()for reverse/ManyToMany- Database indexing on frequently queried fields
-
Serialization
- Light serializers for list views
- Full serializers for detail views
- Conditional field inclusion
-
Caching
- Session caching
- QuerySet caching where appropriate
Frontend Optimizations
-
Code Splitting
- Route-based lazy loading
- Dynamic imports for large components
-
Asset Optimization
- Vite’s automatic code splitting
- Image optimization
- CSS purging with Tailwind
-
State Management
- Minimize store subscriptions
- Use derived state for computed values
- Debounce API calls
Scalability
Horizontal Scaling
- Stateless backend - Can run multiple instances
- Load balancer - AWS Application Load Balancer
- Database connection pooling - pgBouncer for PostgreSQL
Vertical Scaling
- Database optimization - Indexes, query optimization
- App Runner auto-scaling - Based on CPU/memory
- RDS scaling - Upgrade instance types as needed
Monitoring & Logging
Backend Logging
Error Tracking
- Django error emails in production
- Structured logging for debugging
- API error responses with details
Next Steps
Data Model
Detailed database schema
Authentication Flow
SIWE implementation details
Deployment
AWS deployment guide
Environment Variables
Configuration reference