Skip to content

ObjectVision is a cutting-edge object detection platform that leverages advanced machine learning techniques for real-time object identification and analysis.

Notifications You must be signed in to change notification settings

imtiaj-007/ObjectVision-Frontend

Repository files navigation

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.

ObjectVision Portal Image


πŸ“‘ Table of Contents


🌟 Features

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

πŸ“₯ Installation

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

πŸ’» Development Setup

  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

πŸ“‚ Project Structure

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

πŸ› οΈ Technologies Used

ObjectVision Frontend leverages a modern tech stack to deliver a performant and maintainable application:

Core Technologies

  • 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

UI and Styling

State Management

Form Management and Validation

Data Visualization

  • Recharts: Composable charting library
  • D3.js: Data-driven document manipulation

Testing

Documentation

  • TypeDoc: Documentation generator for TypeScript
  • Storybook: UI component documentation and testing

DevOps & Build Tools


πŸ” Environment Variables

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.


πŸ”„ API Integration

ObjectVision Frontend communicates with the backend API using a standardized approach:

Service Example

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...
};

πŸ“Š State Management

ObjectVision uses Redux Toolkit for state management, organized into logical slices:

Store Configuration

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;

Slice Example

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;

πŸ—οΈ Building for Production

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

πŸ§ͺ Testing

ObjectVision Frontend implements a comprehensive testing strategy:

Unit Testing

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

Component Testing

Test UI components with React Testing Library:

npm run test:components

End-to-End Testing

Run end-to-end tests with Cypress:

# Open Cypress test runner
npm run cypress:open

# Run Cypress tests headlessly
npm run cypress:run

Visual Regression Testing

Compare UI snapshots for visual changes:

npm run test:visual

πŸ”„ Continuous Integration

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

⚑ Performance Optimization

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

πŸ‘₯ Contributing

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

❓ Troubleshooting

Common issues and their solutions:

Installation Problems

Issue: Dependencies fail to install correctly Solution: Clear npm cache and retry:

npm cache clean --force
rm -rf node_modules
npm install

Development Server Issues

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

Build Errors

Issue: TypeScript compilation errors during build Solution: Run type checking separately to identify issues:

npm run type-check

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Contact


Made with ❀️ by the ObjectVision Team

Releases

No releases published

Packages

No packages published

Languages