Overview
Trazea is built on a modern, scalable architecture that combines Feature-Sliced Design (FSD) methodology with a powerful tech stack centered around React, TypeScript, and Supabase. The architecture is designed to support complex workflows including multi-location inventory management, request tracking, warranty management, and technician movements.Architectural Principles
1. Feature-Sliced Design (FSD)
The codebase follows FSD methodology, organizing code into layers with clear responsibilities and unidirectional dependencies:2. Separation of Concerns
- UI Layer: React components focused purely on presentation
- Business Logic: Separated into feature-specific logic and shared utilities
- Data Layer: Supabase handles authentication, database, storage, and real-time subscriptions
- State Management: Client state (Zustand) vs. Server state (TanStack Query)
3. Type Safety
TypeScript is used throughout with strict mode enabled, providing:- Compile-time error detection
- Enhanced IDE autocomplete and refactoring
- Self-documenting code through interfaces and types
- Type inference with Zod schema validation
System Architecture
Core Components
Frontend Architecture
App Layer (src/app/)
The application foundation containing:
- Providers: Authentication, React Query, Theme providers
- Routing: Main application routing configuration
- Global Configuration: Supabase client, Sentry setup
- Styles: Global CSS and Tailwind configuration
Pages Layer (src/pages/)
Complete application views that compose features and widgets:
- auth: Login, registration, approval flow
- inventario: Multi-location inventory management
- spares: Spare parts catalog
- orders: Scooter order tracking
- records: Movement history and logs
- count: Physical inventory counting
- requests: Inter-location request management
- dynamo: Scooter-specific functionality
Widgets Layer (src/widgets/)
Reusable composite components:
- nav: Sidebar navigation and main menu
- notifications: In-app notification center
- pagination: Generic pagination controls
Features Layer (src/features/)
User-facing functionality modules:
- auth-login: Authentication flows (email + Google OAuth)
- spares-create: Spare parts CRUD operations
- spares-upload: Bulk Excel import
- spares-request-workshop: Request workflow with cart
- guarantees-create: Warranty registration
- guarantees-dashboard: Warranty management
- count-spares: Physical count auditing
- inventory-filters: Advanced search and filtering
- record-save-movement: Technician movement logging
Entities Layer (src/entities/)
Domain models and business logic:
- user: Authentication, roles, permissions
- locations: Multi-location management
- inventario: Inventory items and stock
- repuestos: Spare parts catalog
- guarantees: Warranty management
- requests: Request workflow
- movimientos: Technician movements
- technical: Technician data
- records: Audit logs and history
Shared Layer (src/shared/)
Reusable foundation:
- ui: Base components (buttons, inputs, dialogs, badges)
- lib: Utilities, formatters, helpers
- model: Common types and interfaces
- api: Shared API utilities
Backend Architecture (Supabase)
Supabase provides a complete backend-as-a-service:PostgreSQL Database
- 17 main tables organized by domain
- Views for complex queries (e.g.,
vista_repuestos_inventario) - Triggers for automatic logging and notifications
- Functions for business logic and data transformations
Authentication
- Email/password authentication
- Google OAuth integration
- User approval workflow
- Role-based access control (RBAC)
Row Level Security (RLS)
All tables implement RLS policies to ensure:- Users only access data for their assigned locations
- Role-based data filtering
- Automatic multi-tenancy support
- Protection against unauthorized access
Storage
- Product images for spare parts
- Warranty evidence photos
- User avatars
- Excel import files
Data Flow
Request Flow Example
State Management Flow
Client State (Zustand):- UI state (modals, filters, selections)
- User preferences
- Form data (before submission)
- Local-only state
- Database records
- API responses
- Cached data with automatic revalidation
- Background refetching
Security Architecture
Authentication Flow
- User logs in via email/password or Google OAuth
- Supabase validates credentials and issues JWT
- JWT stored in httpOnly cookie
- All API requests include JWT in Authorization header
- Supabase validates JWT on every request
- Row Level Security filters data based on user context
Authorization
- Role-based permissions: Stored as JSON in
rolestable - Multi-location access: Via
usuarios_localizacionjunction table - Granular permissions: Each feature checks specific permissions
- Admin approval: New users require admin approval before access
Data Protection
- All communication over HTTPS
- Row Level Security on all tables
- Input validation with Zod schemas
- SQL injection prevention via parameterized queries
- XSS protection via React’s automatic escaping
Monitoring & Error Tracking
Sentry Integration
Version: 10.26.0 Capabilities:- Automatic error capture in production
- Stack traces with source maps
- User context (ID, email, role)
- Breadcrumbs for debugging
- Performance monitoring
- Release tracking
src/app/lib/sentry.ts
Build & Development
Build System
Vite 7.2.2 (Rolldown variant) provides:- Lightning-fast Hot Module Replacement (HMR)
- Optimized production builds
- Code splitting and lazy loading
- Tree shaking for minimal bundle size
- CSS optimization
Development Workflow
- Development:
pnpm dev- Local server with HMR - Type Checking:
tsc -b- TypeScript compilation - Linting:
eslint .- Code quality checks - Building:
pnpm build- Production-ready bundle - Preview:
pnpm preview- Test production build locally
Progressive Web App (PWA)
Trazea is built as a PWA usingvite-plugin-pwa, providing:
- Offline capability
- Install to home screen
- App-like experience on mobile
- Service worker for caching
- Push notifications (planned)
Scalability Considerations
Frontend Scalability
- Code splitting: Each page lazy-loaded
- Component lazy loading: Heavy components loaded on demand
- Virtual scrolling: For large lists
- Debounced search: Reduced API calls
- Pagination: Limited data fetching
Backend Scalability
- Database indexing: On frequently queried columns
- Query optimization: Using views for complex joins
- Connection pooling: Managed by Supabase
- CDN for assets: Static files served via CDN
- Caching strategy: TanStack Query cache + Supabase cache
Deployment Architecture
Production Environment
- Hosting: Vercel (recommended) or Docker
- Database: Supabase managed PostgreSQL
- CDN: Automatic via Vercel Edge Network
- SSL: Automatic HTTPS
- Environment: Isolated production database
CI/CD Pipeline
- Push to
mainbranch - Vercel automatically triggers build
- Run TypeScript compilation
- Run linting checks
- Build production bundle
- Deploy to Vercel Edge Network
- Sentry release tracking
Next Steps
Feature-Sliced Design
Detailed FSD implementation and folder structure
Tech Stack
Technologies, versions, and rationale
Database Model
Complete database schema and relationships
Security
Authentication, authorization, and RLS