Overview
OdontologyApp is built on a modern full-stack architecture using SvelteKit as the foundation. The application follows a monolithic architecture with clear separation between frontend and backend concerns.Technology Stack
- Frontend Framework: Svelte 5 with SvelteKit 2
- Backend Runtime: Node.js (via SvelteKit server)
- Database: MySQL 2 with connection pooling
- Authentication: bcryptjs for password hashing
- Validation: Zod schemas with sveltekit-superforms
- UI Library: Custom component library
- Build Tool: Vite 7
Project Structure
SvelteKit Architecture
File-Based Routing
SvelteKit uses a file-based routing system where the directory structure insrc/routes/ maps directly to URL paths:
- +page.svelte: Defines a page component
- +page.server.js: Server-side load function for the page
- +layout.svelte: Shared layout wrapper for child routes
- +layout.server.js: Server-side layout data
- +server.js: API endpoint handler
Configuration Files
svelte.config.js (src/routes/svelte.config.js:1-17):Frontend Architecture
Component Organization
Components are organized by function and reusability:-
UI Components (
src/lib/components/ui/):- Generic, reusable UI primitives
- Examples: Button, Modal, DataTable, EmptyState
- No business logic, pure presentation
-
Input Components (
src/lib/components/inputs/):- Form field components with validation
- Examples: TextInput, DateInput, SelectInput
- Consistent styling and error handling
-
Domain Components (
src/lib/components/Odontology/):- Dental-specific functionality
- Examples: Odontogram, ToothSVG, PatientFinance
- Contains business logic
State Management
OdontologyApp uses Svelte 5’s native reactivity system:- $state: Reactive state variables
- $derived: Computed values
- $effect: Side effects
- $bindable: Two-way binding for component props
Form Handling
Forms use sveltekit-superforms with Zod schemas for validation:Backend Architecture
Server Hooks
The global request handler inhooks.server.js (src/hooks.server.js:1-68) processes all requests:
API Endpoints
API routes follow RESTful conventions using+server.js files:
Example: Patient API (src/routes/api/patients/+server.js:1-80):
Request Flow
- Request arrives → hits
hooks.server.js - Authentication check → validates session cookie
- Authorization check → verifies route access
- Route handler → processes request in
+server.jsor+page.server.js - Permission check → validates user permissions using RBAC
- Database query → executes stored procedure via connection pool
- Response → returns JSON or renders page
Data Flow Patterns
Server-Side Rendering (SSR)
Pages load data on the server before rendering:Client-Side Fetching
For dynamic interactions, components fetch from API endpoints:Security Architecture
See the Security page for detailed information on:- Authentication and session management
- Role-Based Access Control (RBAC)
- Permission system
- CSRF protection
- SQL injection prevention
Database Integration
See the Database page for details on:- Schema design
- Connection pooling
- Stored procedures
- Query patterns
Component Library
See the Components page for documentation on:- UI component library
- Input components
- Dental-specific components
- Usage examples
