# README
Task Manager
A secure and user-friendly Task Manager application built with Go for the backend and a simple HTML/CSS/JavaScript frontend. This project demonstrates authentication with JWT tokens (including refresh tokens), user-specific tasks, and includes comprehensive test coverage.
Live Demo
You can try out the application at: https://todo.mzhirnov.com
Test Credentials
- Username:
[email protected]
- Password:
123456
Features
-
User Authentication:
- Secure registration and login using hashed passwords (bcrypt).
- JWT-based authentication with access and refresh tokens.
-
User-Specific Task Management:
- Users can create, view, update, and delete their own tasks.
- Tasks are bound to user accounts, ensuring data privacy.
-
Token Refresh Mechanism:
- Automatic token renewal using refresh tokens for seamless user experience.
-
Frontend:
- Simple and clean UI for managing tasks.
- Dynamic task loading, creation, and deletion.
-
Backend:
- RESTful API built with Go.
- Database integration using PostgreSQL.
-
Dockerized Deployment:
- Fully containerized for easy deployment with Docker and Docker Compose.
-
Comprehensive Testing:
- Unit tests for models, handlers, and middleware ensure reliability.
Technologies Used
- Backend:
- Go (Golang)
- Gorilla Mux (Router)
- bcrypt (Password hashing)
- jwt-go (JSON Web Tokens)
- Frontend:
- HTML/CSS/JavaScript
- Database:
- PostgreSQL
- Containerization:
- Docker & Docker Compose
- Testing:
- sqlmock (Mock database for testing)
- testify (Assertions in tests)
Getting Started
Prerequisites
- Docker and Docker Compose installed on your machine.
- Go (Golang) installed (optional for development).
Clone the Repository
git clone https://github.com/maxzhirnov/go-task-manager.git
cd go-task-manager
Setup and Run the Application
1. Run with Docker Compose
The easiest way to run the application is using Docker Compose. It will set up the backend, database, and serve the frontend.
docker-compose up --build
- The backend will be available at:
http://localhost:8080
- The frontend can be accessed via the same address.
2. Run Locally
If you want to run the application locally without Docker:
-
Setup PostgreSQL:
- Ensure PostgreSQL is running locally.
- Create a database named
taskmanager
. - Run the SQL scripts in
scripts/db/init.sql
to set up the schema.
-
Set Environment Variables: Create a
.env
file or export the variables directly:export DB_HOST=localhost export DB_PORT=5432 export DB_USER=postgres export DB_PASSWORD=mysecretpassword export DB_NAME=taskmanager export PORT=8080
-
Run the Backend:
go run cmd/api/main.go
-
Serve the Frontend: Open the
web/index.html
file in your browser.
Endpoints
Authentication
Method | Endpoint | Description |
---|---|---|
POST | /api/register | Register a new user |
POST | /api/login | Login and get tokens |
POST | /api/refresh | Get a new access token |
Tasks
Method | Endpoint | Description |
---|---|---|
GET | /api/tasks | Get all tasks for a user |
POST | /api/tasks | Create a new task |
GET | /api/tasks/{id} | Get details of a task |
PUT | /api/tasks/{id} | Update a specific task |
DELETE | /api/tasks/{id} | Delete a specific task |
Sample .env
File
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=taskmanager
# SMTP Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your-password
SMTP_FROM_NAME=ActionHub
SMTP_BASE_URL=http://localhost:5173
SMTP_TEMPLATES_PATH=templates/email
# Server Configuration
SERVER_PORT=8080
# JWT Configuration
JWT_SECRET=your-secret-key
Testing
Run Unit Tests
go test ./... -v
Run with Coverage
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
Task Management Page
Task Management Page
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request to contribute to this project.