ObjectVision is a cutting-edge object detection platform that leverages advanced machine learning techniques for real-time object identification and analysis. The frontend of ObjectVision is built using Next.js 15, TypeScript, and ShadCN for the UI components, making it a modern and robust solution for interacting with the platform.
[]
ObjectVision Frontend provides a comprehensive set of features:
To get started with the frontend of ObjectVision, follow these steps:
Prerequisites:
Clone the repository:
git clone https://github.com/imtiaj-007/ObjectVision-Frontend.git
cd objectvision-frontend
Install dependencies:
npm install --legacy-peer-deps
Setup environment variables:
cp .env.example .env.development
Edit .env.development
with your configuration (see Environment Variables section).
Generate TypeDoc documentation (optional):
npm run docs
Start the development server:
npm run dev
This launches the frontend app at http://localhost:3000
. Changes are automatically reflected in the browser.
TypeScript development tips:
npm run type-check:watch
Working with ShadCN components:
# Install a new component
npx shadcn-ui@latest add button
# Update existing components
npx shadcn-ui@latest add button --overwrite
Linting and formatting:
# Run ESLint
npm run lint
# Fix linting issues automatically
npm run lint:fix
# Format code with Prettier
npm run format
The frontend project follows a clean, modular, and scalable architecture:
objectvision-frontend/
โโโ app/ # Next.js app-based pages and layouts
โ โโโ (auth)/ # Authentication-related routes
โ โโโ (dashboard)/ # Protected dashboard routes
โ โโโ layout.tsx # Root layout component
โ โโโ page.tsx # Homepage component
โโโ components/ # Reusable UI components
โ โโโ auth/ # Authentication-related components
โ โโโ dashboard/ # Dashboard-specific components
โ โโโ predictions/ # Object detection components
โ โโโ layout/ # Layout components (header, footer, etc.)
โ โโโ ui/ # ShadCN UI components
โ โโโ pages/ # Actual Page components
โโโ configuration/ # Project settings and configurations
โ โโโ api.config.ts # API configuration
โ โโโ constants.ts # Application constants
โ โโโ settings.ts # Environment variable management
โโโ hooks/ # Custom React hooks
โ โโโ api/ # API-related hooks
โ โโโ store/ # Redux store hooks
โ โโโ ui/ # UI-related hooks
โโโ schemas/ # Zod validation schemas
โ โโโ auth-schema.ts # Authentication form schemas
โ โโโ detection-schema.ts # Detection parameter schemas
โ โโโ user-schema.ts # User data schemas
โโโ services/ # API services
โ โโโ api-service.ts # Base API service
โ โโโ auth-service.ts # Authentication service
โ โโโ detection-service.ts # Detection service
โโโ store/ # Redux store configuration
โ โโโ features/ # Redux slices and thunks
โ โโโ providers/ # Redux provider
โ โโโ store.ts # Store configuration
โโโ types/ # TypeScript type definitions
โ โโโ api-types.ts # API-related types
โ โโโ detection-types.ts # Detection-related types
โ โโโ common-types.ts # Common type definitions
โโโ utils/ # Utility functions
โ โโโ date-utils.ts # Date manipulation utilities
โ โโโ file-utils.ts # Formatting utilities
โ โโโ promise-utils.ts # Promise helpers
โโโ docs/ # Generated TypeDoc documentation
โโโ .env.example # Example environment variables
โโโ .eslintrc.js # ESLint configuration
โโโ .prettierrc # Prettier configuration
โโโ jest.config.js # Jest testing configuration
โโโ next.config.mjs # Next.js configuration
โโโ package.json # Project dependencies and scripts
โโโ tailwind.config.js # Tailwind CSS configuration
โโโ tsconfig.json # TypeScript configuration
ObjectVision Frontend leverages a modern tech stack to deliver a performant and maintainable application:
ObjectVision Frontend uses environment variables for configuration. Create a .env.development
file with the following variables:
# URLs
NEXT_PUBLIC_ENV=development
NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000
NEXT_PUBLIC_LOGO_URL=http://localhost:3000/logo.png
NEXT_PUBLIC_BACKEND_URL=http://localhost:8000
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000/api
NEXT_PUBLIC_GOOGLE_OAUTH_URL=http://localhost:8000/api/oauth
# Secret Keys
NEXT_PUBLIC_API_KEY=your-api-key
NEXT_PUBLIC_SECRET_KEY=your-secret-key
NEXT_PUBLIC_RAZORPAY_KEY_ID=your-razorpay-key
# Google Analytics Credentials (optional)
NEXT_PUBLIC_GTAG_ID=your-g-tag
NEXT_PUBLIC_GOOGLE_VERIFICATION_CODE=your-google-verification-code
For production deployment, set these variables in your hosting environment.
ObjectVision Frontend communicates with the backend API using a standardized approach:
Each API domain has its own service, for example services/detection-service.ts
:
import axiosClient from '@utils/axios';
import { DetectionParams, DetectionResult } from '../types/detection-types';
export const DetectionService = {
detectObjects: async (imageData: File, params: DetectionParams): Promise<DetectionResult> => {
const formData = new FormData();
formData.append('image', imageData);
formData.append('params', JSON.stringify(params));
const response = await apiClient.post('/detect', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
},
getBatchStatus: async (batchId: string): Promise<BatchStatus> => {
const response = await apiClient.get(`/batch/${batchId}/status`);
return response.data;
},
// More detection-related API methods...
};
ObjectVision uses Redux Toolkit for state management, organized into logical slices:
The Redux store is configured in store/store.ts
:
import { configureStore } from '@reduxjs/toolkit';
import { setupListeners } from '@reduxjs/toolkit/query';
import { api } from './services/api';
import authReducer from './slices/authSlice';
import detectionReducer from './slices/detectionSlice';
import uiReducer from './slices/uiSlice';
export const store = configureStore({
reducer: {
auth: authReducer,
detection: detectionReducer,
ui: uiReducer,
[api.reducerPath]: api.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(api.middleware),
});
setupListeners(store.dispatch);
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
Each feature has its own slice, for example store/slices/detectionSlice.ts
:
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { DetectionState, DetectionResult } from '../../types/detection.types';
const initialState: DetectionState = {
results: [],
isProcessing: false,
currentBatchId: null,
error: null,
detectionParameters: {
confidenceThreshold: 0.5,
modelType: 'standard',
},
};
export const detectionSlice = createSlice({
name: 'detection',
initialState,
reducers: {
startDetection: (state) => {
state.isProcessing = true;
state.error = null;
},
detectionSuccess: (state, action: PayloadAction<DetectionResult>) => {
state.results.push(action.payload);
state.isProcessing = false;
},
detectionFailed: (state, action: PayloadAction<string>) => {
state.isProcessing = false;
state.error = action.payload;
},
updateParameters: (state, action: PayloadAction<Partial<DetectionParameters>>) => {
state.detectionParameters = {
...state.detectionParameters,
...action.payload,
};
},
clearResults: (state) => {
state.results = [];
},
},
});
export const {
startDetection,
detectionSuccess,
detectionFailed,
updateParameters,
clearResults,
} = detectionSlice.actions;
export default detectionSlice.reducer;
To create a production-ready build of ObjectVision Frontend:
Optimized build:
npm run build:prod
This creates an optimized build with:
Test the production build locally:
npm start
Analyze bundle size (optional):
npm run analyze
This generates a visual report of bundle sizes to identify optimization opportunities.
Deployment considerations:
ObjectVision Frontend implements a comprehensive testing strategy:
Run unit tests with Jest:
# Run all tests
npm test
# Run tests in watch mode
npm test:watch
# Run tests with coverage report
npm test:coverage
Test UI components with React Testing Library:
npm run test:components
Run end-to-end tests with Cypress:
# Open Cypress test runner
npm run cypress:open
# Run Cypress tests headlessly
npm run cypress:run
Compare UI snapshots for visual changes:
npm run test:visual
ObjectVision uses GitHub Actions for CI/CD. The workflow is defined in .github/workflows/ci.yml
:
Pull Request Checks:
Main Branch Deployment:
ObjectVision Frontend implements several performance optimizations:
We welcome contributions to ObjectVision Frontend! Here's how to get started:
git checkout -b feature/your-feature-name
npm test
Common issues and their solutions:
Issue: Dependencies fail to install correctly Solution: Clear npm cache and retry:
npm cache clean --force
rm -rf node_modules
npm install
Issue: Hot module replacement not working Solution: Check for conflicting global installations:
npm list -g next
# If found, uninstall global Next.js
npm uninstall -g next
Issue: TypeScript compilation errors during build Solution: Run type checking separately to identify issues:
npm run type-check
This project is licensed under the MIT License - see the LICENSE file for details.
Made with โค๏ธ by the ObjectVision Team