Directory Overview
PROVESA Web follows SvelteKit’s conventions with additional organizational patterns for maintainability:Source Directory (src/)
Library Code (src/lib/)
Reusable components, utilities, and server-side logic.
Server Code (src/lib/server/)
All server-side logic is isolated here. This code never runs in the browser.
Database Layer (src/lib/server/db/)
Services Layer (src/lib/server/services/)
Business logic and data orchestration.
- Validate input data
- Handle file uploads (Cloudinary integration)
- Transform data (e.g., JSON parsing)
- Calculate derived values (e.g.,
sortOrder) - Orchestrate multiple repository calls
- Business rule enforcement
Repositories Layer (src/lib/server/repositories/)
Database access abstraction.
getAll()- Fetch all records (sorted)getById(id)- Fetch single recordcreate(data)- Insert new recordupdate(id, data)- Update existing recordremove(id)- Delete record
Authentication (src/lib/server/auth.js)
Better Auth configuration:
File Uploads (src/lib/server/cloudinary.js)
Cloudinary configuration for image uploads.
Routes (src/routes/)
SvelteKit file-based routing with server-side data loading.
+page.svelte- Page component (UI)+page.server.js- Server-side data loading and form actions+layout.svelte- Shared layout wrapper+layout.server.js- Layout data loading+server.js- API endpoint (no UI)
Hooks (src/hooks.server.js)
Global server-side request handling:
event.locals.session and event.locals.user available in all server-side code.
Static Assets (static/)
Public files served directly:
/favicon.png, /images/logo.png
Database Migrations (drizzle/)
Drizzle Kit migration files:
Configuration Files
package.json
Dependencies and scripts:
svelte.config.js
SvelteKit configuration:
drizzle.config.js
Drizzle ORM configuration:
File Naming Conventions
Components
- PascalCase:
ProductSection.svelte,HeroSlider.svelte - Suffix: Always
.sveltefor components
Server Files
- kebab-case:
site-config.service.js,hero_slides.schema.js - Suffix:
.service.js,.repository.js,.schema.js
Routes
- kebab-case:
restablecer-password/,politicas/ - SvelteKit prefixes:
+page.svelte,+layout.server.js
Database Tables
- snake_case:
hero_slides,empleo_sucursales,concursos_ganadores
Import Path Aliases
SvelteKit provides the$lib alias:
$app/*- SvelteKit app modules$env/*- Environment variables
Code Organization Best Practices
1. Colocation
Group related files together:2. Single Responsibility
One feature per file:products.service.jshandles ONLY productsfooter.service.jshandles ONLY footer
3. Consistent Exports
Named exports for services/repositories:4. Clear Dependencies
Import from higher-level abstractions:Next Steps
- Database Schema - Complete database structure
- Services & Repositories - Implementation patterns
- Architecture Overview - High-level design patterns
