This document summarizes the complete integration between the client and backend APIs.
-
Extended User Controllers (
userControllers.extended.ts)- Complete profile retrieval with related data
- Project CRUD operations
- Experience CRUD operations
- Achievement CRUD operations
- Certification CRUD operations
- Profile Links CRUD operations
-
File Upload System (
uploadRoutes.ts)- Single file upload endpoint
- Multiple file upload endpoint
- File deletion endpoint
- Support for images, PDFs, and Word documents
- 10MB file size limit
-
Enhanced Routes (
userRoutes.ts)- Added routes for all new CRUD operations
- Proper authentication and validation
- Rate limiting applied
-
Comprehensive API Hook (
use-user-api.ts)- All backend API endpoints wrapped in React hooks
- Proper error handling and loading states
- Token-based authentication
- File upload functionality
-
Enhanced Profile Hook (
use-profile.ts)- Backend integration for all profile operations
- Fallback to mock data when backend unavailable
- Real-time synchronization with backend
- Optimistic updates with error recovery
-
Authentication System (
use-auth.tsx)- Complete auth context with backend integration
- Token management and persistence
- Profile completion workflow
- Session management
-
Client API Routes (Next.js API routes)
/api/user/profile/[userId]/complete- Get complete profile/api/user/profile/[userId]/projects- Project operations/api/user/projects/[projectId]- Individual project operations- Updated environment variable usage
- User Model: Contains references to all related entities
- Project Model: Linked to users with ownership
- Experience Model: Professional experience tracking
- Achievement Model: Achievement and award tracking
- Certificate Model: Certification management
- ProfileLink Model: Social/professional links
- Server:
multerfor file uploads with TypeScript types - Client: Enhanced hooks and providers
POST /api/user/login- User loginGET /api/user/verify-token- Token verificationPOST /api/user/complete-profile- Complete user profile
GET /api/user/profile/:userId- Get basic profileGET /api/user/profile/:userId/complete- Get complete profile with relationsPUT /api/user/profile/:userId- Update profile
POST /api/user/profile/:userId/projects- Create projectGET /api/user/profile/:userId/projects- Get user projectsPUT /api/user/projects/:projectId- Update projectDELETE /api/user/projects/:projectId- Delete project
POST /api/user/profile/:userId/experiences- Create experienceGET /api/user/profile/:userId/experiences- Get user experiencesPUT /api/user/experiences/:experienceId- Update experienceDELETE /api/user/experiences/:experienceId- Delete experience
POST /api/user/profile/:userId/achievements- Create achievementGET /api/user/profile/:userId/achievements- Get user achievementsPUT /api/user/achievements/:achievementId- Update achievementDELETE /api/user/achievements/:achievementId- Delete achievement
POST /api/user/profile/:userId/certifications- Create certificationGET /api/user/profile/:userId/certifications- Get user certificationsPUT /api/user/certifications/:certificationId- Update certificationDELETE /api/user/certifications/:certificationId- Delete certification
POST /api/user/profile/:userId/profile-links- Create profile linkGET /api/user/profile/:userId/profile-links- Get user profile linksPUT /api/user/profile-links/:profileLinkId- Update profile linkDELETE /api/user/profile-links/:profileLinkId- Delete profile link
POST /api/upload/single- Upload single filePOST /api/upload/multiple- Upload multiple filesDELETE /api/upload/:filename- Delete file
POST /api/admin/login- Admin loginPOST /api/admin/create-user- Create userPOST /api/admin/create-bulk-users- Create multiple usersGET /api/admin/users- Get all usersPOST /api/admin/resend-verification/:userId- Resend verification emailDELETE /api/admin/user/:userId- Delete user
NEXT_API_PUBLIC_URL='http://localhost:5000'
NEXT_PUBLIC_API_URL='http://localhost:5000/api'
JWT_SECRET=your_jwt_secret
DB_CONNECTION_STRING=your_mongodb_connection
PORT=5000
-
Install new dependencies:
cd server npm install multer npm install --save-dev @types/multer -
Start the server:
npm run dev
- The client hooks are ready to use
- Start the client:
cd client npm run dev
import { useProfile } from '@/hooks/use-profile';
import { useAuth } from '@/hooks/use-auth';
function ProfileComponent() {
const { user } = useAuth();
const {
projects,
addProject,
updateProject,
deleteProject,
uploadFile,
isLoading
} = useProfile(user?.id);
const handleAddProject = async (projectData) => {
await addProject(projectData);
};
const handleFileUpload = async (file) => {
const uploadResult = await uploadFile(file);
console.log('File uploaded:', uploadResult.url);
};
// Component JSX...
}import { useUserAPI } from '@/hooks/use-user-api';
function SomeComponent() {
const userAPI = useUserAPI();
const handleOperation = async () => {
try {
const projects = await userAPI.getUserProjects(userId);
const newProject = await userAPI.createProject(userId, projectData);
const uploadResult = await userAPI.uploadFile(file);
} catch (error) {
console.error('API Error:', error);
}
};
}- JWT token authentication for all protected routes
- File upload restrictions (type and size)
- Rate limiting on API endpoints
- Request validation using Joi schemas
- Proper error handling and logging
- All client hooks provide fallback to mock data when backend is unavailable
- File uploads are stored in the server's
uploadsdirectory - Complete profile endpoint populates all related data in a single request
- All CRUD operations maintain referential integrity in the database
- Authentication state is persisted in localStorage
The integration is now complete and ready for production use!