Frontend Development
The Med Agenda frontend is a modern single-page application (SPA) built with React 18, Vite, and TypeScript, featuring role-based dashboards for administrators, doctors, and patients.Technology Stack
Core Technologies
- React 18.3.1: UI library with hooks and modern features
- Vite 5.4.9: Next-generation build tool with fast HMR
- TypeScript 5.6.2: Type-safe JavaScript development
- React Router DOM 6.27.0: Client-side routing
UI & Styling
- Tailwind CSS 3.4.14: Utility-first CSS framework
- Radix UI: Accessible, unstyled UI primitives
@radix-ui/react-label@radix-ui/react-select@radix-ui/react-scroll-area@radix-ui/react-separator@radix-ui/react-slot
- Lucide React 0.453.0: Beautiful icon library
- Class Variance Authority: Component variant management
- Tailwind Merge: Merge Tailwind classes efficiently
- Tailwindcss Animate: Animation utilities
HTTP & State
- Axios 1.7.7: Promise-based HTTP client
- React Hooks: Built-in state management
- dotenv 16.4.5: Environment variable management
Development Tools
- ESLint 9.13.0: Code linting
- TypeScript ESLint: TypeScript-specific linting rules
- Vite Plugin React: React support for Vite
- PostCSS & Autoprefixer: CSS processing
Project Structure
React + Vite Setup
Entry Point
main.tsx:
Vite Configuration
vite.config.ts:
Routing with React Router DOM
Route Structure
App.tsx:
Route Organization
Public Routes:/- Landing page/information/pdf- PDF information scraping/information/news- Medical news/information/doctor- Doctor information
/:userType/login- Dynamic login (admin, doctor, patient)/:userType/register- Dynamic registration
/admin/*- Admin dashboard and management/doctor/*- Doctor dashboard and tools/patient/*- Patient dashboard and services
API Client Configuration
Axios Setup
src/api/api.ts:
Environment Variables
.env (create this file):
example.env:
API Usage Example
State Management
Local State with useState
Form State
UI Components
Radix UI Primitives
Med Agenda uses Radix UI for accessible, unstyled components:Tailwind CSS Styling
tailwind.config.js:
Component Library Structure
src/components/ui/ contains reusable UI components built with Radix UI and Tailwind:
button.tsx- Button variantsinput.tsx- Input fieldsselect.tsx- Dropdown selectlabel.tsx- Form labelscard.tsx- Card containerscroll-area.tsx- Scrollable areaseparator.tsx- Visual divider
Build and Development Commands
Development
Build
Preview
Linting
TypeScript Configuration
tsconfig.json
Best Practices
Component Organization
Error Handling
Environment Variables
- Prefix with
VITE_to expose to client - Access via
import.meta.env.VITE_VARIABLE_NAME - Never commit
.envfiles with sensitive data
Development Workflow
- Start Backend:
cd backend/gestaoConsultasMedicas && mvn spring-boot:run - Start Frontend:
cd frontend && npm run dev - Access App: http://localhost:5173
- Make Changes: Hot Module Replacement (HMR) automatically updates
- Build:
npm run buildfor production - Deploy: Upload
dist/to hosting (Vercel, Netlify, etc.)
Deployment
Vercel (Recommended)
vercel.json:
Build Configuration
- Build Command:
npm run build - Output Directory:
dist - Node Version: 18.x or higher
Performance Optimization
- Code Splitting: React Router automatically splits routes
- Lazy Loading: Use
React.lazy()for heavy components - Memoization: Use
useMemoanduseCallbackfor expensive operations - Image Optimization: Use WebP format and lazy loading
- Bundle Analysis: Run
vite build --analyzeto inspect bundle size
Troubleshooting
CORS Issues
If you encounter CORS errors, ensure the backend allows requests fromhttp://localhost:5173.
API Connection
Verify.env file has correct VITE_URL_API value.
TypeScript Errors
Runnpm run build to catch type errors before runtime.