object-detection - v1.0.0

ObjectVision Frontend

ObjectVision Logo

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.

[Portal Image]



ObjectVision Frontend provides a comprehensive set of features:

  • Real-time Object Detection: Process images and video streams with instant visual feedback
  • Interactive Dashboard: Monitor detection statistics and metrics through intuitive visualizations
  • Batch Processing: Upload and process multiple files at once with progress tracking
  • Customizable Detection Parameters: Adjust confidence thresholds and detection models
  • Export & Share: Download detection results in various formats or share via direct links
  • Responsive Design: Seamless experience across desktop, tablet, and mobile devices
  • Dark/Light Mode: Support for user preference and system theme detection
  • Accessibility: WCAG 2.1 compliant interface with keyboard navigation support

To get started with the frontend of ObjectVision, follow these steps:

  1. Prerequisites:

    • Node.js (v18.0.0 or later)
    • npm (v9.0.0 or later)
    • Git
  2. Clone the repository:

    git clone https://github.com/imtiaj-007/ObjectVision-Frontend.git
    cd objectvision-frontend
  3. Install dependencies:

    npm install --legacy-peer-deps
    
  4. Setup environment variables:

    cp .env.example .env.development
    

    Edit .env.development with your configuration (see Environment Variables section).

  5. Generate TypeDoc documentation (optional):

    npm run docs
    

  1. Start the development server:

    npm run dev
    

    This launches the frontend app at http://localhost:3000. Changes are automatically reflected in the browser.

  2. TypeScript development tips:

    • Ensure your IDE has TypeScript support enabled
    • Run type checking in watch mode with npm run type-check:watch
    • Use the provided TSConfig for consistent settings
  3. Working with ShadCN components:

    # Install a new component
    npx shadcn-ui@latest add button

    # Update existing components
    npx shadcn-ui@latest add button --overwrite
  4. 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:

  • Next.js 15: React framework with server-side rendering, route handling, and optimized builds
  • TypeScript: Strongly-typed programming language for enhanced developer experience
  • React 18: UI library with concurrent rendering features
  • Recharts: Composable charting library
  • D3.js: Data-driven document manipulation
  • TypeDoc: Documentation generator for TypeScript
  • Storybook: UI component documentation and testing

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:

  1. Optimized build:

    npm run build:prod
    

    This creates an optimized build with:

    • Code minification
    • Tree shaking to eliminate unused code
    • Image optimization
    • Static HTML generation where applicable
  2. Test the production build locally:

    npm start
    
  3. Analyze bundle size (optional):

    npm run analyze
    

    This generates a visual report of bundle sizes to identify optimization opportunities.

  4. Deployment considerations:

    • Enable caching headers for static assets
    • Configure CDN for assets and API proxy if applicable
    • Set up proper environment variables for the production environment
    • Implement health checks and monitoring

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:

    • Code linting and formatting
    • TypeScript type checking
    • Unit and component tests
    • Bundle size analysis
  • Main Branch Deployment:

    • Automated build and deployment to staging
    • End-to-end tests on staging environment
    • Manual approval for production deployment

ObjectVision Frontend implements several performance optimizations:

  • Code Splitting: Dynamic imports for route-based code splitting
  • Image Optimization: Next.js Image component for responsive images
  • Font Optimization: Local font hosting with optimized loading
  • Lazy Loading: Components and sections loaded only when needed
  • Memoization: React.memo, useMemo, and useCallback for expensive operations
  • Service Worker: Offline capabilities and asset caching
  • Bundle Analysis: Regular bundle size monitoring

We welcome contributions to ObjectVision Frontend! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch:
    git checkout -b feature/your-feature-name
    
  3. Make your changes:
    • Follow the coding standards and style guide
    • Add tests for new features
    • Update documentation as needed
  4. Run the tests:
    npm test
    
  5. Submit a pull request:
    • Provide a clear description of the changes
    • Reference any related issues
    • Include screenshots or GIFs for UI changes

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