Skip to content

anurag5sh/task-management-system-in-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project: Real-time Task Management System

Overview: This is a task management system where users can create, read, update, and delete tasks. The system will use WebSockets for real-time updates and a database for persistent storage.

Key components:

  1. HTTP server for API endpoints
  2. WebSocket server for real-time updates
  3. Database integration (e.g., PostgreSQL)
  4. CRUD operations for tasks
  5. Channels for handling concurrent operations

Features:

  1. User authentication
  2. Create, read, update, and delete tasks
  3. Real-time task updates for all connected clients
  4. Task filtering and sorting
  5. Task assignment to users

Implementation steps:

  1. Set up the project structure and database
  2. Implement HTTP server with basic CRUD operations
  3. Add WebSocket support for real-time updates
  4. Use channels for handling concurrent operations
  5. Implement user authentication
  6. Add advanced features like filtering and sorting

This project will help you learn:

  • Go's HTTP package for creating a web server
  • Database operations using a SQL driver (e.g., lib/pq for PostgreSQL)
  • WebSocket implementation in Go
  • Concurrency with goroutines and channels
  • JSON marshaling and unmarshaling
  • Error handling in Go
  • Project structure and organization

  1. Project Setup

    • Initialize a new Go module
    • Set up a project structure with separate packages for handlers, models, and database operations
    • Choose and set up a SQL database (e.g., PostgreSQL)
  2. Database Schema

    • Users table: id, username, password_hash, email, created_at
    • Tasks table: id, title, description, status, created_at, updated_at, user_id (foreign key to users)
  3. User Authentication

    • Implement user registration with username, email, and password
    • Implement user login with JWT token generation
    • Create middleware for authenticating protected routes
  4. HTTP Server

    • Set up an HTTP server using the standard "net/http" package
    • Implement the following RESTful API endpoints:
      • POST /register - User registration
      • POST /login - User login
      • GET /tasks - Retrieve all tasks for the authenticated user
      • GET /tasks/:id - Retrieve a specific task
      • POST /tasks - Create a new task
      • PUT /tasks/:id - Update an existing task
      • DELETE /tasks/:id - Delete a task
  5. WebSocket Server

    • Implement a WebSocket server for real-time updates
    • Create a handler for WebSocket connections
    • Implement a mechanism to broadcast task updates to all connected clients
  6. CRUD Operations

    • Implement Create, Read, Update, and Delete operations for tasks
    • Use prepared statements for database queries to prevent SQL injection
    • Implement proper error handling for database operations
  7. Concurrency with Channels

    • Use channels to handle communication between HTTP handlers and WebSocket broadcasts
    • Implement a goroutine to listen for task updates and broadcast them to WebSocket clients
  8. Task Filtering and Sorting

    • Implement query parameters for the GET /tasks endpoint to allow filtering by status and sorting by creation date
  9. Error Handling

    • Implement custom error types for different scenarios (e.g., NotFoundError, ValidationError)
    • Return appropriate HTTP status codes and error messages in API responses
  10. Logging

    • Implement logging for server events, errors, and access logs
  11. Configuration

    • Use environment variables or a configuration file for database credentials, server port, and JWT secret
  12. Testing

    • Write unit tests for critical functions
    • Implement integration tests for API endpoints
  13. Documentation

    • Create API documentation using a tool like Swagger
    • Write a README.md file with project setup and running instructions
  14. (Optional) Docker

    • Create a Dockerfile for the application
    • Set up docker-compose for easy deployment with the database

Detailed Implementation Steps:

  1. Project Setup

    mkdir task-management-system
    cd task-management-system
    go mod init github.com/yourusername/task-management-system
    
  2. Create main.go file with basic server setup

    package main
    
    import (
        "log"
        "net/http"
    )
    
    func main() {
        // TODO: Initialize database connection
        // TODO: Set up routes
        log.Println("Server starting on :8080")
        log.Fatal(http.ListenAndServe(":8080", nil))
    }
  3. Set up database connection in a separate package

  4. Implement user authentication

  5. Create handlers for CRUD operations

  6. Implement WebSocket functionality

  7. Add channels for real-time updates

  8. Implement filtering and sorting

  9. Add error handling and logging

  10. Write tests

  11. Document the API

This structure provides a solid foundation for building the Real-time Task Management System. As you implement each part, you'll gain experience with Go's core concepts, including HTTP servers, database operations, WebSockets, channels, and concurrency.

About

A task management system created in GO

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages