Skip to content

dev-sam17/SmartBrain_Project

Repository files navigation

🧠 SmartBrain - AI Face Detection App

A full-stack web application that uses artificial intelligence to detect faces in images. Built with React.js frontend, Node.js/Express backend, and powered by Clarifai's face detection API.

SmartBrain Demo React Node.js Docker

🌟 Features

  • AI-Powered Face Detection: Detect multiple faces in uploaded images or URLs
  • Real-time Processing: Instant face detection with visual bounding boxes
  • File Upload Support: Upload images directly or provide image URLs
  • Image Compression: Automatic optimization for large images (5MB+ handling)
  • User Authentication: Firebase-based sign up/sign in system
  • Responsive Design: Modern UI with animated particle backgrounds
  • Glass-morphism Effects: Beautiful gradient animations and modern styling
  • RESTful API: Clean backend architecture with Express.js

πŸš€ Live Demo

The application serves both frontend and backend on a single port for easy deployment.

πŸ› οΈ Technology Stack

Frontend

  • React.js (18.2.0) - UI framework
  • React Router - Client-side routing
  • Firebase - Authentication
  • OGL - WebGL particles background
  • Tachyons - CSS framework

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • Clarifai API - AI face detection
  • CORS - Cross-origin resource sharing
  • Body-parser - Request parsing

DevOps

  • Docker - Containerization
  • Docker Compose - Multi-container orchestration
  • Multi-stage builds - Optimized production images

πŸ“ Project Structure

SmartBrain_Project/
β”œβ”€β”€ facerecognitionbrain/          # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/            # Reusable components
β”‚   β”‚   β”œβ”€β”€ routes/               # Page components
β”‚   β”‚   β”œβ”€β”€ contexts/             # React contexts
β”‚   β”‚   └── utils/                # Utility functions
β”‚   β”œβ”€β”€ public/                   # Static assets
β”‚   └── build/                    # Production build
β”œβ”€β”€ server/                       # Express backend
β”‚   β”œβ”€β”€ server.js                 # Main server file
β”‚   β”œβ”€β”€ package.json             # Server dependencies
β”‚   └── .env                     # Environment variables
β”œβ”€β”€ docker-compose.yml           # Production Docker setup
β”œβ”€β”€ docker-compose.dev.yml       # Development Docker setup
β”œβ”€β”€ Dockerfile                   # Production container
└── package.json                # Root project scripts

πŸ”§ Installation & Setup

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Clarifai API account

Local Development

  1. Clone the repository

    git clone https://github.com/dev-sam17/SmartBrain_Project.git
    cd SmartBrain_Project
  2. Install all dependencies

    npm run install-all
  3. Set up environment variables Create .env file in the server/ directory:

    CLARIFAI_USER_ID=your_user_id
    CLARIFAI_APP_ID=your_app_id
    CLARIFAI_PAT=your_personal_access_token
    CLARIFAI_MODEL_ID=face-detection
  4. Run in development mode

    npm run dev
  5. Build and run production

    npm run build-and-start

🐳 Docker Setup

Production Deployment

  1. Using Docker Compose (Recommended)

    docker-compose up --build -d
  2. Using Docker directly

    docker build -t smartbrain .
    docker run -p 3001:3001 --env-file server/.env smartbrain

Development with Docker

docker-compose -f docker-compose.dev.yml up --build

This runs frontend and backend in separate containers with hot reload.

πŸ“š API Documentation

Base URL

http://localhost:3001/api

Endpoints

Method Endpoint Description
GET /api Get all users
GET /api/profile/:id Get user profile
POST /api/signin User authentication
POST /api/signup User registration
POST /api/imageurl Face detection
PUT /api/image Update user entry count

Face Detection API

POST /api/imageurl

{
  "input": "image_url_or_base64_data"
}

Response:

{
  "outputs": [
    {
      "data": {
        "regions": [
          {
            "region_info": {
              "bounding_box": {
                "top_row": 0.123,
                "left_col": 0.456,
                "bottom_row": 0.789,
                "right_col": 0.012
              }
            }
          }
        ]
      }
    }
  ]
}

🎨 Features in Detail

Face Detection

  • Supports both image URLs and file uploads
  • Automatic image compression for files >5MB
  • Real-time bounding box visualization
  • Multiple face detection in single image

User Interface

  • Animated particle background using WebGL
  • Glass-morphism design elements
  • Responsive layout for all devices
  • Loading states and error handling

Performance Optimizations

  • Image compression and resizing
  • Lazy loading components
  • Optimized Docker builds
  • Static file serving from Express

πŸ”’ Environment Variables

Required environment variables for Clarifai API:

CLARIFAI_USER_ID=your_clarifai_user_id
CLARIFAI_APP_ID=your_clarifai_app_id  
CLARIFAI_PAT=your_personal_access_token
CLARIFAI_MODEL_ID=face-detection

πŸš€ Deployment

Production Build

npm run build-and-start

Docker Production

docker-compose up -d

Health Checks

The application includes health check endpoints for monitoring:

  • Container health check on /api
  • 30-second intervals with 3 retries

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ Available Scripts

Script Description
npm run install-all Install dependencies for all packages
npm run build Build React app for production
npm start Start production server
npm run dev Run both frontend and backend in development
npm run build-and-start Build and start production server

πŸ› Troubleshooting

Common Issues

  1. Port 3001 already in use

    lsof -ti:3001 | xargs kill -9
  2. Clarifai API errors

    • Verify environment variables
    • Check API key permissions
    • Ensure sufficient API credits
  3. Docker build fails

    • Check Docker daemon is running
    • Verify .dockerignore excludes node_modules
    • Ensure sufficient disk space

πŸ“„ License

This project is licensed under the ISC License.

πŸ‘¨β€πŸ’» Author

dev-sam17

πŸ™ Acknowledgments

  • Clarifai for face detection API
  • React team for the amazing framework
  • Firebase for authentication services
  • OGL for WebGL particle effects

⭐ Star this repository if you found it helpful!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published