Overview
PROVESA Web is built as a modern, full-stack web application using SvelteKit with a clean, layered architecture that emphasizes separation of concerns, maintainability, and scalability.Technology Stack
Frontend
- SvelteKit - Full-stack framework with file-based routing
- Svelte - Reactive component framework
- Tailwind CSS - Utility-first CSS framework
- Dynamic Theming - CSS variables for real-time color customization
Backend
- SvelteKit Server - Server-side rendering and API routes
- Drizzle ORM - TypeScript ORM for database operations
- PostgreSQL - Primary database
- Better Auth - Authentication and session management
- Cloudinary - Image upload and management
Architectural Patterns
Layered Architecture
The application follows a strict three-layer architecture:Key Principles
1. Separation of Concerns
Each layer has a specific responsibility:- Routes handle HTTP requests/responses and user interactions
- Services contain business logic and orchestrate operations
- Repositories abstract database access
- Schemas define data structure
2. Dependency Flow
Data flows unidirectionally:/src/routes/admin/+page.server.js:24:
/src/lib/server/services/products.service.js:5:
/src/lib/server/repositories/products.repository.js:7:
3. Single Responsibility
Each service/repository handles one domain:products.service.js- Product managementconcursos.service.js- Contest managementfooter.service.js- Footer configurationauth.js- Authentication
4. Type Safety
Drizzle ORM provides end-to-end type safety:Authentication & Authorization
Better Auth Integration
Authentication is handled via Better Auth with session-based security:- Session Hook (
/src/hooks.server.js:5):
- Protected Routes:
- User Schema (
/src/lib/server/db/schemas/auth.schema.js):
user- User accountssession- Active sessionsaccount- OAuth providers and credentialsverification- Email verification tokens
Data Management
Database Access Pattern
All database operations use Drizzle ORM:Schema Organization
Schemas are modular and exported from a central location:File Upload Strategy
Cloudinary Integration
Image uploads are handled through a dedicated repository:- Centralized upload logic
- Automatic optimization
- CDN distribution
- Organized folder structure
Configuration Management
Dynamic Configuration
Several aspects of the site are dynamically configurable:- Theme Colors - Stored in CSS file, managed via service
- Site Config - Key-value pairs in database
- Feature Toggles - Boolean flags (e.g.,
isActiveon contests) - Singleton Configs - Single-row tables (footer, nosotros)
Environment Variables
Admin Architecture
Admin Panel Structure
The admin panel (/src/routes/admin/) uses:
- Tab-based UI - Each feature in a separate component
- Form Actions - SvelteKit actions for CRUD operations
- Server-side validation - All validation in services
- Optimistic loading - Parallel data fetching with
Promise.all
/src/routes/admin/+page.server.js:19:
Public Site Architecture
Homepage Data Loading
The homepage efficiently loads all necessary data in parallel:Error Handling
Error handling follows SvelteKit conventions:Performance Considerations
Optimization Strategies
- Parallel Data Fetching - Use
Promise.all()for independent queries - Database Indexing - Indexes on foreign keys and frequently queried fields
- Sorted Results -
sortOrderfield for consistent ordering - Cloudinary CDN - Images served from CDN
- Server-side Rendering - SEO-friendly, fast initial load
Best Practices
Code Organization
Naming Conventions
- Services:
{domain}.service.js - Repositories:
{domain}.repository.js - Schemas:
{domain}.schema.js - Components: PascalCase (e.g.,
ProductSection.svelte) - Database Tables: snake_case (e.g.,
hero_slides)
Next Steps
- Project Structure - Detailed directory breakdown
- Database Schema - Complete schema documentation
- Services & Repositories - Implementation patterns
