Skip to content

A production-ready Node.js/Express RESTful API for task management, featuring JWT authentication and MySQL persistence. It's built with MVC architecture, optimized for rootless Podman containers, and includes health checks, graceful shutdowns, and automated deployment using Docker Compose.

Notifications You must be signed in to change notification settings

Gadrawingz/tasktracker-api-containerized

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TaskTracker API

A modern Task Management API built with Node.js, Express, MySQL, and containerized with Podman.

🏗️ Architecture

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   Client App    │───▶│  TaskTracker API  │───▶│  MySQL Database │
│  (Frontend/     │    │  (Node.js/Express│    │  (Containerized) │
│   Mobile App)   │    │   Containerized)  │    │                 │
└─────────────────┘    └──────────────────┘    └─────────────────┘

Key Features

  • MVC Architecture - Clean separation of concerns
  • JWT Authentication - Stateless, secure authentication
  • RESTful API - Standard HTTP methods and status codes
  • Podman Containerization - Rootless, secure containers
  • MySQL Database - Reliable data persistence
  • Health Checks - Container and application monitoring
  • Environment Configuration - 12-factor app principles

🚀 Quick Start

Prerequisites

  • Podman and Podman-compose installed
  • Node.js 18+ (for local development)
  • Git

Installation & Setup

  1. Clone and setup project:
git clone <your-repo-url>
cd task-tracker-api
npm install
  1. Configure environment:
cp .env.example .env
# Edit .env with your settings (default password: GMX@432)
  1. Start with Podman:
./scripts/deploy.sh up
  1. Test the API:
./scripts/test-api.sh

📡 API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - User login
  • GET /api/auth/profile - Get user profile (authenticated)
  • PUT /api/auth/profile - Update profile (authenticated)
  • POST /api/auth/change-password - Change password (authenticated)

Tasks

  • GET /api/tasks - List tasks (authenticated)
  • POST /api/tasks - Create task (authenticated)
  • GET /api/tasks/:id - Get specific task (authenticated)
  • PUT /api/tasks/:id - Update task (authenticated)
  • DELETE /api/tasks/:id - Delete task (authenticated)
  • PATCH /api/tasks/:id/complete - Mark task complete (authenticated)
  • GET /api/tasks/stats - Get task statistics (authenticated)
  • GET /api/tasks/search?q=term - Search tasks (authenticated)

System

  • GET /api/health - Health check
  • GET /api - API documentation

🐳 Container Management

Using Deploy Script (Recommended)

./scripts/deploy.sh up      # Start all services
./scripts/deploy.sh down    # Stop all services
./scripts/deploy.sh logs    # View logs
./scripts/deploy.sh ps      # Check status
./scripts/deploy.sh test    # Run tests
./scripts/deploy.sh clean   # Remove everything

Manual Podman Commands

# Start services
podman-compose -f containers/compose.yml up -d

# View logs
podman-compose -f containers/compose.yml logs -f api

# Stop services
podman-compose -f containers/compose.yml down

# Check container status
podman ps

🧪 Testing

The project includes comprehensive API tests:

# Run all tests
./scripts/test-api.sh

# Manual testing with curl
curl http://localhost:3008/api/health
curl -X POST http://localhost:3008/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"testuser","email":"test@example.com","password":"password123"}'

🗄️ Database

Schema

  • users - User accounts and authentication
  • tasks - Task management with priorities and statuses
  • categories - Task categorization (optional)
  • task_categories - Many-to-many relationship

Connection

  • Host: mysql (container name)
  • Port: 3306
  • Database: tasktracker
  • User: taskuser
  • Password: GMX@432 (configurable in .env)

🔧 Development

Local Development (without containers)

# Install dependencies
npm install

# Start MySQL locally or use container
podman run -d --name mysql \
  -e MYSQL_ROOT_PASSWORD=GMX@432 \
  -e MYSQL_DATABASE=tasktracker \
  -e MYSQL_USER=taskuser \
  -e MYSQL_PASSWORD=GMX@432 \
  -p 3306:3306 mysql:8.0

# Update .env for local development
# DB_HOST=localhost

# Start development server
npm run dev

Project Structure

task-tracker-api/
├── src/
│   ├── config/         # Database and app configuration
│   ├── controllers/    # Business logic (MVC)
│   ├── models/         # Data models (MVC)
│   ├── routes/         # API routes
│   ├── middleware/     # Authentication, validation
│   ├── views/          # Response helpers
│   ├── app.js          # Express application setup
│   └── server.js       # Server startup
├── database/
│   ├── init.sql        # Database schema
│   └── seed.sql        # Sample data
├── containers/
│   ├── Containerfile   # Container image definition
│   ├── compose.yml     # Multi-container orchestration
│   ├── mysql.cnf       # MySQL configuration
│   └── nginx.conf      # Reverse proxy config
├── scripts/
│   ├── deploy.sh       # Deployment automation
│   ├── test-api.sh     # API testing
│   └── wait-for-db.sh  # Database readiness check
└── package.json        # Node.js dependencies and scripts

🔒 Security

  • JWT Authentication - Secure, stateless tokens
  • Password Hashing - bcrypt with configurable rounds
  • Input Validation - Request sanitization and validation
  • SQL Injection Prevention - Parameterized queries
  • Security Headers - Helmet.js middleware
  • Rootless Containers - Enhanced container security
  • Environment Variables - Sensitive data protection

🚀 Deployment

Development

./scripts/deploy.sh up

Production

  1. Update environment variables in .env
  2. Change Containerfile target to 'production'
  3. Enable nginx proxy in compose.yml
  4. Set up SSL/TLS certificates
  5. Configure monitoring and logging

🔍 Troubleshooting

Common Issues

Port already in use:

# Change port in .env file
PORT=3009

Database connection failed:

# Check MySQL container status
podman logs task-tracker-mysql

# Restart database
podman-compose -f containers/compose.yml restart mysql

API not responding:

# Check API logs
podman logs task-tracker-api

# Restart API
podman-compose -f containers/compose.yml restart api

Logs and Debugging

# All service logs
podman-compose -f containers/compose.yml logs -f

# Specific service logs
podman logs task-tracker-api
podman logs task-tracker-mysql

# Enter container for debugging
podman exec -it task-tracker-api sh

📈 Performance

  • Connection pooling for database efficiency
  • Request/response compression
  • Proper indexing on database queries
  • Health checks for container monitoring
  • Graceful shutdown handling

🤝 Contributing

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

📄 License

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

🙏 Acknowledgments

  • Built with modern containerization practices
  • Follows 12-factor app methodology
  • Implements RESTful API standards
  • Uses secure authentication patterns

About

A production-ready Node.js/Express RESTful API for task management, featuring JWT authentication and MySQL persistence. It's built with MVC architecture, optimized for rootless Podman containers, and includes health checks, graceful shutdowns, and automated deployment using Docker Compose.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published