Skip to content

RESTful backend service for logging user activities. Built with Node.js, Express, MySQL, and validation middleware. Clean API design with CRUD operations, error handling, and organized service-layer architecture.

Notifications You must be signed in to change notification settings

vineetagarwal54/ActivityLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Activity Logger Backend

A RESTful API service for tracking user activities with authentication and data persistence.

Features

  • User Management (Create/Update/Get)
  • Activity Logging (Single/Batch)
  • Activity History Retrieval
  • Input Validation
  • Error Handling
  • Environment Configuration

Technologies Used

  • Node.js
  • Express.js
  • MySQL
  • Express Validator
  • CORS
  • UUID
  • Dotenv

Prerequisites

  • Node.js (v14 or higher)
  • MySQL Server
  • npm or yarn

Installation

  1. Clone the repository:

    git clone [your-repo-url]
    cd activity-logger-backend
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory with the following content:

    PORT=3000
    DB_HOST=localhost
    DB_USER=your_db_user
    DB_PASSWORD=your_db_password
    DB_NAME=ActivityLogger
    
  4. Initialize the database:

    • Make sure your MySQL server is running
    • Send a POST request to /init-db endpoint to create required tables

API Endpoints

Users

  • POST /api/users - Create/Update user
  • GET /api/users/:phone_number - Get user by phone number

Activities

  • POST /api/activities/single - Create a single activity
  • POST /api/activities/batch - Create multiple activities
  • GET /api/users/:userId/activities - Get activities for a user

Error Handling

The API implements comprehensive error handling for:

  • Validation errors
  • Database errors
  • Not found errors
  • Server errors

Running the Application

Development mode:

npm start

Database Schema

Users Table

  • uuid (VARCHAR(36)) - Primary Key
  • name (VARCHAR(255))
  • phone_number (VARCHAR(20)) - Unique

Activities Table

  • id (INT AUTO_INCREMENT) - Primary Key
  • userId (VARCHAR(36)) - Foreign Key
  • activity_name (VARCHAR(255))
  • time_stamp (TIMESTAMP)
  • activity_description (TEXT)

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License.

About

RESTful backend service for logging user activities. Built with Node.js, Express, MySQL, and validation middleware. Clean API design with CRUD operations, error handling, and organized service-layer architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published