This commit is contained in:
2026-01-23 20:35:40 +03:00
parent cf3b0e48ec
commit 66c151653e
137 changed files with 41495 additions and 0 deletions

View File

@@ -0,0 +1,399 @@
# Design Document
## Overview
The car maintenance management system is designed as a modern, responsive web application built with Remix, featuring Arabic language support with RTL layout, role-based authentication, and comprehensive business management capabilities. The system follows a modular architecture with clear separation of concerns, utilizing Prisma for database operations and Tailwind CSS for styling.
## Architecture
### High-Level Architecture
```mermaid
graph TB
A[Client Browser] --> B[Remix Frontend]
B --> C[Remix Backend/API Routes]
C --> D[Prisma ORM]
D --> E[SQLite Database]
F[Authentication Middleware] --> C
G[Session Management] --> C
H[Route Protection] --> B
subgraph "Frontend Components"
I[Dashboard Layout]
J[RTL Components]
K[Responsive Navigation]
L[Form Components]
end
B --> I
B --> J
B --> K
B --> L
```
### Technology Stack
- **Frontend Framework**: Remix with React 18
- **Backend**: Remix server-side rendering and API routes
- **Database**: SQLite with Prisma ORM
- **Styling**: Tailwind CSS with RTL support
- **Authentication**: Custom session-based authentication
- **TypeScript**: Full type safety throughout the application
## Components and Interfaces
### 1. Authentication System
#### Session Management
- Custom session-based authentication using Remix sessions
- Secure cookie storage with httpOnly and secure flags
- Session expiration and renewal mechanisms
- CSRF protection for form submissions
#### User Authentication Flow
```mermaid
sequenceDiagram
participant U as User
participant A as Auth Route
participant S as Session Store
participant D as Database
U->>A: Submit login credentials
A->>D: Validate user credentials
D-->>A: Return user data
A->>S: Create session
S-->>A: Return session cookie
A-->>U: Redirect with session cookie
```
#### Route Protection Middleware
- Higher-order component for protecting routes based on auth levels
- Automatic redirection to login for unauthenticated users
- Role-based access control for different user types
### 2. Database Schema Design
#### Core Entities and Relationships
```mermaid
erDiagram
User {
int id PK
string name
string username UK
string email UK
string password
enum status
int authLevel
datetime createdDate
datetime editDate
}
Customer {
int id PK
string name
string phone
string email
string address
datetime createdDate
datetime updateDate
}
Vehicle {
int id PK
string plateNumber UK
string bodyType
string manufacturer
string model
string trim
int year
string transmission
string fuel
int cylinders
decimal engineDisplacement
enum useType
int ownerId FK
datetime lastVisitDate
datetime suggestedNextVisitDate
datetime createdDate
datetime updateDate
}
MaintenanceVisit {
int id PK
int vehicleId FK
int customerId FK
string maintenanceType
string description
decimal cost
string paymentStatus
int kilometers
datetime visitDate
datetime createdDate
datetime updateDate
}
Expense {
int id PK
string description
string category
decimal amount
datetime expenseDate
datetime createdDate
datetime updateDate
}
Income {
int id PK
int maintenanceVisitId FK
decimal amount
datetime incomeDate
datetime createdDate
datetime updateDate
}
Customer ||--o{ Vehicle : owns
Vehicle ||--o{ MaintenanceVisit : has
Customer ||--o{ MaintenanceVisit : books
MaintenanceVisit ||--|| Income : generates
```
### 3. UI/UX Design System
#### RTL Layout Implementation
- CSS logical properties for directional layouts
- Arabic font integration (Noto Sans Arabic, Cairo)
- Tailwind CSS RTL plugin configuration
- Component-level RTL support with `dir="rtl"` attribute
#### Responsive Design Breakpoints
```css
/* Mobile First Approach */
sm: 640px /* Small devices */
md: 768px /* Medium devices */
lg: 1024px /* Large devices */
xl: 1280px /* Extra large devices */
2xl: 1536px /* 2X Extra large devices */
```
#### Color Scheme and Theming
- Primary colors: Blue gradient (#3B82F6 to #1E40AF)
- Secondary colors: Gray scale for neutral elements
- Success: Green (#10B981)
- Warning: Amber (#F59E0B)
- Error: Red (#EF4444)
- Dark mode support for future enhancement
- Design : use constant design for all pages, forms and buttons.
### 4. Navigation and Layout System
#### Dashboard Layout Structure
```mermaid
graph LR
A[App Shell] --> B[Sidebar Navigation]
A --> C[Main Content Area]
A --> D[Header Bar]
B --> E[Logo Area]
B --> F[Navigation Menu]
B --> G[User Profile]
C --> H[Page Content]
C --> I[Breadcrumbs]
D --> J[Mobile Menu Toggle]
D --> K[User Actions]
```
#### Sidebar Navigation Features
- Collapsible sidebar with full/icon-only modes
- Mobile-responsive hamburger menu
- Active state indicators
- Smooth animations and transitions
- Persistent state across page navigation
### 5. Form and Data Management
#### Form Validation Strategy
- Client-side validation using HTML5 and custom validators
- Server-side validation with Zod schemas
- Real-time validation feedback
- Internationalized error messages in Arabic
#### Data Table Components
- Sortable columns with Arabic text support
- Pagination with RTL navigation
- Search and filtering capabilities
- Responsive table design with horizontal scrolling
- Bulk actions for data management
## Data Models
### User Model
```typescript
interface User {
id: number;
name: string;
username: string;
email: string;
password: string; // hashed
status: 'active' | 'inactive';
authLevel: 1 | 2 | 3; // 1=superadmin, 2=admin, 3=user
createdDate: Date;
editDate: Date;
}
```
### Vehicle Model
```typescript
interface Vehicle {
id: number;
plateNumber: string;
bodyType: string;
manufacturer: string;
model: string;
trim?: string;
year: number;
transmission: 'Automatic' | 'Manual';
fuel: 'Gasoline' | 'Diesel' | 'Hybrid' | 'Mild Hybrid' | 'Electric';
cylinders?: number;
engineDisplacement?: number;
useType: 'personal' | 'taxi' | 'apps' | 'loading' | 'travel';
ownerId: number;
lastVisitDate?: Date;
suggestedNextVisitDate?: Date;
createdDate: Date;
updateDate: Date;
}
```
### Maintenance Visit Model
```typescript
interface MaintenanceVisit {
id: number;
vehicleId: number;
customerId: number;
maintenanceType: string;
description: string;
cost: number;
paymentStatus: string;
kilometers: number;
visitDate: Date;
nextVisitDelay: 1 | 2 | 3 | 4; // months
createdDate: Date;
updateDate: Date;
}
```
## Error Handling
### Client-Side Error Handling
- Global error boundary for React components
- Form validation error display
- Network error handling with retry mechanisms
- User-friendly error messages in Arabic
### Server-Side Error Handling
- Centralized error handling middleware
- Database constraint violation handling
- Authentication and authorization error responses
- Logging and monitoring for production debugging
### Error Response Format
```typescript
interface ErrorResponse {
success: false;
error: {
code: string;
message: string;
details?: any;
};
}
```
## Testing Strategy
### Unit Testing
- Component testing with React Testing Library
- Business logic testing for utility functions
- Database model testing with Prisma
- Authentication flow testing
### Integration Testing
- API route testing with Remix testing utilities
- Database integration testing
- Authentication middleware testing
- Form submission and validation testing
### End-to-End Testing
- User journey testing for critical paths
- Cross-browser compatibility testing
- Mobile responsiveness testing
- RTL layout verification
### Testing Tools
- Jest for unit testing
- React Testing Library for component testing
- Playwright for E2E testing
- MSW (Mock Service Worker) for API mocking
## Security Considerations
### Authentication Security
- Password hashing using bcrypt
- Secure session management
- CSRF protection
- Rate limiting for authentication attempts
### Data Protection
- Input sanitization and validation
- SQL injection prevention through Prisma
- XSS protection through proper escaping
- Secure headers configuration
### Access Control
- Role-based access control (RBAC)
- Route-level protection
- API endpoint authorization
- Data filtering based on user permissions
## Performance Optimization
### Frontend Performance
- Code splitting with Remix route-based splitting
- Image optimization and lazy loading
- CSS optimization with Tailwind purging
- Bundle size monitoring and optimization
### Backend Performance
- Database query optimization with Prisma
- Caching strategies for frequently accessed data
- Connection pooling for database connections
- Response compression and minification
### Mobile Performance
- Touch-friendly interface design
- Optimized images for different screen densities
- Reduced JavaScript bundle size for mobile
- Progressive Web App (PWA) capabilities
## Deployment and Infrastructure
### Development Environment
- Local SQLite database for development
- Hot module replacement with Vite
- TypeScript compilation and type checking
- ESLint and Prettier for code quality
### Production Deployment
- Build optimization with Remix production build
- Database migration strategy
- Environment variable management
- Health check endpoints for monitoring
### Monitoring and Logging
- Application performance monitoring
- Error tracking and reporting
- User analytics and usage metrics
- Database performance monitoring

View File

@@ -0,0 +1,165 @@
# Requirements Document
## Introduction
This document outlines the requirements for a comprehensive car maintenance management system built with Remix, SQLite, and Prisma. The system is designed for business owners to track vehicle visits and maintenance records with a focus on Arabic language support, RTL design, and mobile-friendly responsive UI/UX.
## Requirements
### Requirement 1: Core Framework and Database Setup
**User Story:** As a business owner, I want a robust web application built on modern technologies, so that I can reliably manage my car maintenance business operations.
#### Acceptance Criteria
1. WHEN the application is deployed THEN the system SHALL use Remix as the web framework
2. WHEN data needs to be stored THEN the system SHALL use SQLite database with Prisma ORM
3. WHEN the application starts THEN the system SHALL initialize properly with all database connections established
### Requirement 2: Arabic Language and RTL Support
**User Story:** As an Arabic-speaking business owner, I want the interface to support Arabic language with proper RTL layout, so that I can use the system naturally in my native language.
#### Acceptance Criteria
1. WHEN the application loads THEN the system SHALL display all text in Arabic with RTL text direction
2. WHEN viewing any page THEN the system SHALL render Arabic fonts correctly
3. WHEN navigating the interface THEN all UI components SHALL support RTL layout orientation
4. WHEN using forms THEN input fields SHALL align properly for RTL text entry
### Requirement 3: Responsive Design and Mobile Support
**User Story:** As a business owner who works on different devices, I want a responsive interface that works seamlessly on desktop, tablet, and mobile, so that I can manage my business from anywhere.
#### Acceptance Criteria
1. WHEN accessing the application on desktop THEN the system SHALL display a full dashboard layout
2. WHEN accessing the application on tablet THEN the system SHALL adapt the layout for medium screens
3. WHEN accessing the application on mobile THEN the system SHALL provide a mobile-optimized interface
4. WHEN resizing the browser window THEN the system SHALL smoothly transition between responsive breakpoints
### Requirement 4: Dashboard Navigation System
**User Story:** As a user, I want an intuitive navigation system with collapsible sidebar, so that I can efficiently access different sections of the application.
#### Acceptance Criteria
1. WHEN viewing the dashboard THEN the system SHALL display a collapsible sidebar navigation menu
2. WHEN the sidebar is collapsed THEN the system SHALL show icon-only navigation
3. WHEN on mobile devices THEN the system SHALL provide a hamburger menu for navigation
4. WHEN navigating between sections THEN the system SHALL provide smooth transitions
5. WHEN the sidebar state changes THEN the system SHALL maintain the state across page navigation
### Requirement 5: User Authentication System
**User Story:** As a system administrator, I want a secure custom authentication system, so that I can control access to the application and protect sensitive business data.
#### Acceptance Criteria
1. WHEN a user attempts to sign in THEN the system SHALL authenticate using username or email with password
2. WHEN storing passwords THEN the system SHALL hash passwords securely
3. WHEN managing sessions THEN the system SHALL implement proper session management
4. WHEN authentication fails THEN the system SHALL display appropriate error messages
5. WHEN authentication succeeds THEN the system SHALL redirect to the appropriate dashboard
### Requirement 6: User Management and Access Control
**User Story:** As a superadmin, I want to manage user accounts with different access levels, so that I can control who has access to what features in the system.
#### Acceptance Criteria
1. WHEN creating users THEN the system SHALL support three auth levels: 1=superadmin, 2=admin, 3=user
2. WHEN an admin views users THEN the system SHALL hide superadmin accounts from admin users
3. WHEN a superadmin views users THEN the system SHALL display all user accounts
4. WHEN managing user status THEN the system SHALL support "active" and "inactive" status
5. WHEN no admin users exist THEN the system SHALL allow access to the signup page
6. WHEN admin users exist THEN the system SHALL restrict access to the signup page
### Requirement 7: Customer Management
**User Story:** As a business owner, I want to manage customer information, so that I can maintain records of vehicle owners and their contact details.
#### Acceptance Criteria
1. WHEN adding a customer THEN the system SHALL store customer contact information
2. WHEN viewing customers THEN the system SHALL display a searchable list of all customers
3. WHEN editing customer information THEN the system SHALL update records with proper validation
4. WHEN deleting a customer THEN the system SHALL handle associated vehicle relationships appropriately
5. WHEN creating a customer THEN the system SHALL validate required fields and uniqueness constraints
### Requirement 7.1: Enhanced Customer Details View
**User Story:** As a business owner, I want a comprehensive customer details view that shows all related information in one place, so that I can quickly access customer vehicles, maintenance history, and take relevant actions.
#### Acceptance Criteria
1. WHEN viewing a customer's details THEN the system SHALL display a redesigned "المعلومات الأساسية" (Basic Information) section with improved layout
2. WHEN viewing customer details THEN the system SHALL show all vehicles owned by the customer
3. WHEN clicking on a vehicle in the customer details THEN the system SHALL navigate to the vehicles page filtered by that specific vehicle's plate number
4. WHEN viewing customer details THEN the system SHALL provide a "Show All Vehicles" button that opens the vehicles page filtered by the customer
5. WHEN viewing customer details THEN the system SHALL display the latest 3 maintenance visits for the customer
6. WHEN viewing customer details THEN the system SHALL provide a button to view all maintenance visits filtered by the customer
7. WHEN no maintenance visits exist THEN the system SHALL display an appropriate message encouraging the first visit
8. WHEN viewing vehicle information THEN the system SHALL show key details like plate number, manufacturer, model, and year
9. WHEN viewing maintenance visit information THEN the system SHALL show visit date, maintenance type, cost, and payment status
### Requirement 8: Vehicle Management
**User Story:** As a business owner, I want to manage detailed vehicle information, so that I can track each vehicle's specifications and maintenance history.
#### Acceptance Criteria
1. WHEN adding a vehicle THEN the system SHALL store plate number, body type, manufacturer, model, year, transmission, fuel type, and use type
2. WHEN entering vehicle details THEN the system SHALL provide dropdown lists for body type, transmission, and fuel type options
3. WHEN saving a vehicle THEN the system SHALL ensure plate number uniqueness
4. WHEN linking vehicles THEN the system SHALL associate each vehicle with a customer owner
5. WHEN viewing vehicles THEN the system SHALL display last visit date and suggested next visit date
6. WHEN editing vehicle information THEN the system SHALL update records with proper validation
### Requirement 9: Maintenance Visit Management
**User Story:** As a service technician, I want to record maintenance visits with detailed information, so that I can track what work was performed and when.
#### Acceptance Criteria
1. WHEN creating a maintenance visit THEN the system SHALL link the visit to a specific vehicle and customer
2. WHEN recording visit details THEN the system SHALL store maintenance type, description, cost, and kilometers
3. WHEN completing a visit THEN the system SHALL update the vehicle's last visit date to the current date
4. WHEN setting next visit THEN the system SHALL calculate suggested next visit date based on selected delay period
5. WHEN selecting visit delay THEN the system SHALL provide options for 1, 2, 3, and 4 months
6. WHEN saving a visit THEN the system SHALL generate corresponding income records
### Requirement 10: Financial Management
**User Story:** As a business owner, I want to track expenses and income, so that I can monitor the financial performance of my maintenance business.
#### Acceptance Criteria
1. WHEN recording expenses THEN the system SHALL store expense details with proper categorization
2. WHEN a maintenance visit is completed THEN the system SHALL automatically generate income records
3. WHEN viewing financial data THEN the system SHALL provide summaries of income and expenses
4. WHEN managing financial records THEN the system SHALL support full CRUD operations
5. WHEN calculating totals THEN the system SHALL provide accurate financial reporting
### Requirement 11: Data Validation and Error Handling
**User Story:** As a user, I want proper validation and clear error messages, so that I can understand and correct any input errors quickly.
#### Acceptance Criteria
1. WHEN submitting forms THEN the system SHALL validate all required fields
2. WHEN validation fails THEN the system SHALL display clear, localized error messages
3. WHEN database operations fail THEN the system SHALL handle errors gracefully
4. WHEN unique constraints are violated THEN the system SHALL provide specific error feedback
5. WHEN network errors occur THEN the system SHALL provide appropriate user feedback
### Requirement 12: Database Seeding and Initial Setup
**User Story:** As a system administrator, I want the system to initialize with essential data, so that I can start using the application immediately after deployment.
#### Acceptance Criteria
1. WHEN the database is first created THEN the system SHALL seed one superadmin account
2. WHEN seeding data THEN the system SHALL create essential system configuration data
3. WHEN running seed scripts THEN the system SHALL handle existing data appropriately
4. WHEN initializing THEN the system SHALL set up proper database relationships and constraints

View File

@@ -0,0 +1,201 @@
# Implementation Plan
- [x] 1. Set up project foundation and database schema
- Configure Prisma schema with all required models and relationships
- Set up database migrations and seed data
- Configure TypeScript types for all models
- _Requirements: 1.1, 1.2, 1.3, 12.1, 12.2, 12.3, 12.4_
- [x] 2. Implement authentication system foundation
- Create session management utilities and middleware
- Implement password hashing and validation functions
- Create authentication helper functions and types
- _Requirements: 5.1, 5.2, 5.3, 5.4, 5.5_
- [x] 3. Create authentication routes and forms
- Implement signin route with username/email login support
- Create signup route with conditional access control
- Build authentication form components with validation
- Implement proper error handling and user feedback
- _Requirements: 5.1, 5.4, 5.5, 6.5, 6.6, 11.1, 11.2, 11.4_
- [x] 4. Set up RTL layout and Arabic language support
- Configure Tailwind CSS for RTL support and Arabic fonts
- Create base layout components with RTL orientation
- Implement responsive design utilities and breakpoints
- Test Arabic text rendering and layout behavior
- _Requirements: 2.1, 2.2, 2.3, 2.4, 3.1, 3.2, 3.3, 3.4_
- [x] 5. Build dashboard layout and navigation system
- Create responsive sidebar navigation component
- Implement collapsible sidebar with icon-only mode
- Build mobile hamburger menu and responsive behavior
- Add smooth transitions and state persistence
- _Requirements: 4.1, 4.2, 4.3, 4.4, 4.5_
- [x] 6. Implement route protection and access control
- Create route protection middleware for different auth levels
- Implement role-based access control logic
- Add automatic redirection for unauthorized access
- Test access control for all user types
- _Requirements: 6.1, 6.2, 6.3, 6.4_
- [x] 7. Create user management system
- Build user listing page with role-based filtering
- Implement user creation, editing, and status management
- Create user deletion functionality with proper validation
- Add search and filtering capabilities for user management
- _Requirements: 6.1, 6.2, 6.3, 6.4, 7.1, 7.2, 7.3, 7.4, 7.5_
- [x] 8. Implement customer management CRUD operations
- Create customer model and database operations
- Build customer listing page with search functionality
- Implement customer creation and editing forms
- Add customer deletion with relationship handling
- _Requirements: 7.1, 7.2, 7.3, 7.4, 7.5, 11.1, 11.2, 11.3_
- [x] 9. Build vehicle management system
- Create vehicle model with all required fields and relationships
- Implement vehicle registration form with dropdown selections
- Build vehicle listing and search functionality
- Add vehicle editing and deletion capabilities
- _Requirements: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 11.1, 11.2, 11.4_
- [x] 10. Implement maintenance visit management
- Create maintenance visit model and database operations
- Build visit registration form with vehicle and customer linking
- Implement visit delay selection and next visit date calculation
- Add visit listing, editing, and deletion functionality
- _Requirements: 9.1, 9.2, 9.3, 9.4, 9.5, 9.6_
- [x] 11. Create financial management system
- Implement expense management CRUD operations
- Build automatic income generation from maintenance visits
- Create financial reporting and summary views
- Add expense and income listing with filtering
- _Requirements: 10.1, 10.2, 10.3, 10.4, 10.5_
- [x] 12. Build reusable form components and validation
- Create reusable form input components with RTL support
- Implement client-side and server-side validation
- Build data table components with Arabic text support
- Add pagination, sorting, and filtering utilities
- _Requirements: 11.1, 11.2, 11.3, 11.4, 11.5_
- [x] 13. Enhance customer details view with comprehensive information display (note that i do not use dynamic page $... i use popup forms for update and view details)
- Redesign the "المعلومات الأساسية" (Basic Information) section with improved layout
- Display all customer vehicles with clickable navigation to filtered vehicle pages
- Add "Show All Vehicles" button that opens vehicles page filtered by customer
- Show latest 3 maintenance visits with key information (date, type, cost, payment status)
- Add "View All Visits" button that opens maintenance visits page filtered by customer
- Implement proper navigation with URL parameters for filtering
- Add responsive design for mobile and tablet views
- _Requirements: 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9_
- [ ] 14. Implement comprehensive error handling
- Create global error boundary components
- Implement centralized error handling middleware
- Add proper error logging and user feedback
- Create Arabic error message translations
- _Requirements: 11.1, 11.2, 11.3, 11.4, 11.5_
- [ ] 15. Add responsive design and mobile optimization
- Optimize all components for mobile devices
- Test and refine responsive breakpoints
- Implement touch-friendly interactions
- Verify RTL layout on all screen sizes
- _Requirements: 3.1, 3.2, 3.3, 3.4, 4.3, 4.4_
- [ ] 16. Create database seeding and initial setup
- Implement database seed script with superadmin account
- Create essential system data initialization
- Add proper error handling for existing data
- Test database initialization and migration process
- _Requirements: 12.1, 12.2, 12.3, 12.4_
- [ ] 17. Implement comprehensive testing suite
- Write unit tests for all business logic functions
- Create integration tests for API routes and database operations
- Add component tests for UI components
- Implement end-to-end tests for critical user journeys
- _Requirements: All requirements validation through testing_
- [ ] 18. Final integration and system testing
- Test complete user workflows from authentication to data management
- Verify all CRUD operations work correctly with proper validation
- Test role-based access control across all features
- Validate Arabic language support and RTL layout throughout the system
- _Requirements: All requirements integration testing_