A comprehensive task management API built with Ruby on Rails, featuring teams, projects, tasks, and collaboration capabilities.
- Features
- Getting Started
- API Documentation
- Authentication
- Configuration
- Testing
- Deployment
- ERD Diagram
- Contributing
- License
- User authentication (signup, login, logout, password reset)
- Team management (create, update, delete teams)
- Project management within teams
- Task and sub-task management
- Role-based access control (owner, admin, member)
- Activity tracking
- File attachments and comments
- Real-time notifications
- API documentation with Swagger
- Ruby 3.4.4
- Rails 8.0.2.1
- PostgreSQL 13+
- Node.js 16+ (for asset compilation)
- Yarn 1.22+ (for asset dependencies)
-
Clone the repository:
git clone https://github.com/your-username/task_manager_api.git cd task_manager_api -
Install dependencies:
bundle install
-
Install additional tools:
gem install foreman # For process management
-
Create the database:
rails db:create
-
Run migrations:
rails db:migrate
-
(Optional) Seed the database with sample data:
rails db:seed
You can run the application in two ways:
- Make sure PostgreSQL is running on your system
- Set up the database:
rails db:create rails db:migrate
- Start the Rails server:
rails server
-
Build and start the services:
docker-compose up --build
-
On first run, set up the database:
docker-compose exec web rails db:create docker-compose exec web rails db:migrate
The application will be available at http://localhost:3000.
This API is fully documented using Swagger UI. All endpoints, parameters, request/response formats, and examples are available through the interactive documentation.
-
Start the Rails server:
rails server
-
Open your browser and navigate to:
http://localhost:3000/api-docs -
You'll see the Swagger UI interface with all available endpoints organized by category.
-
Authentication: Most endpoints require authentication. Click the "Authorize" button at the top of the Swagger UI and enter your Bearer token.
-
Exploring Endpoints:
- Expand any endpoint to see details
- Click "Try it out" to test endpoints directly in the browser
- View example requests and responses
- See required parameters and data formats
If you're a developer who wants to integrate this Task Manager API into your own application, you can explore all available endpoints through the Swagger UI documentation.
- Teams: Top-level organizational units
- Projects: Belong to teams
- Tasks: Belong to projects
- Sub-tasks: Belong to tasks
- Memberships: Users can have different roles (owner, admin, member) in teams, projects, and tasks
- Invitations: Users can invite others to teams and projects
All API requests (except signup and login) require authentication using JWT tokens. Refer to the Swagger documentation for specific authentication endpoints and flows.
This API can be easily integrated with any frontend framework. Here are instructions for common scenarios:
Example using fetch API:
// User Login
async function login(username, password) {
const response = await fetch('/api/v1/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
});
if (response.ok) {
const data = await response.json();
// Store the access token in localStorage or state management
localStorage.setItem('access_token', data.access_token);
return data;
}
throw new Error('Login failed');
}
// Making Authenticated Requests
async function apiRequest(endpoint, options = {}) {
const token = localStorage.getItem('access_token');
const defaultOptions = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
...options.headers,
},
};
const response = await fetch(`/api/v1${endpoint}`, {
...options,
...defaultOptions,
});
return response.json();
}The API is configured to allow cross-origin requests. In production, make sure to:
- Set the
CORS_ORIGINSenvironment variable to your frontend domain(s) - Example:
CORS_ORIGINS=https://yourapp.com,https://app.yourapp.com
For file attachments, use multipart form data:
async function uploadAttachment(taskId, file, name) {
const formData = new FormData();
formData.append('file', file);
formData.append('name', name);
const response = await fetch(`/api/v1/tasks/${taskId}/attachments`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token')}`,
},
body: formData,
});
return response.json();
}Implement consistent error handling across your application:
async function handleApiError(response) {
if (response.status === 401) {
// Token expired, redirect to login
localStorage.removeItem('access_token');
window.location.href = '/login';
} else if (response.status === 422) {
// Validation errors
const errorData = await response.json();
throw new Error(errorData.errors.join(', '));
} else {
// Other errors
throw new Error('An error occurred');
}
}- State Management: Use a state management solution (Redux, Context API, etc.) to manage user data and authentication state
- Loading States: Show loading indicators during API requests
- Error Boundaries: Implement error boundaries to handle API failures gracefully
- Caching: Implement caching strategies to reduce unnecessary API calls
- Security: Never store sensitive tokens in plain text; use secure storage mechanisms
Currently, there are no official SDKs for this API. However, you can:
- Use the Swagger documentation to generate client code in your preferred language
- Use standard HTTP libraries to make requests
- Follow REST best practices for your integration
This API follows semantic versioning:
- Major versions (v1, v2) may introduce breaking changes
- Minor versions (v1.1, v1.2) add functionality without breaking changes
- Patch versions (v1.0.1, v1.0.2) include bug fixes
Currently, the API is at v1. When new versions are released:
- Old versions will be supported for a transition period
- Deprecation notices will be provided in advance
- Migration guides will be provided for breaking changes
To ensure compatibility:
- Always specify the API version in your requests (
/api/v1/...) - Monitor release notes for breaking changes
- Test your integration with new versions before upgrading
Create a .env file in the root directory based on .env.example:
cp .env.example .envKey configuration variables include:
DATABASE_URL: PostgreSQL database connection stringJWT_SECRET: Secret key for JWT token signingRAILS_ENV: Application environment (development, test, production)RAILS_MASTER_KEY: Master key for encrypted credentials
The API is configured to allow cross-origin requests. Modify config/initializers/cors.rb to adjust allowed origins for your deployment.
For password reset functionality, configure your email service in config/environments/production.rb.
Run the test suite with:
rspecRun tests with coverage report:
COVERAGE=true rspecIn production, ensure these environment variables are set:
DATABASE_URL: Production database connectionJWT_SECRET: Strong secret key (userails secretto generate)SECRET_KEY_BASE: Rails secret key base (userails secretto generate)RAILS_ENV: Set to "production"RAILS_SERVE_STATIC_FILES: Set to "true" if serving assets with RailsRAILS_LOG_TO_STDOUT: Set to "true" for containerized deploymentsCORS_ORIGINS: Comma-separated list of allowed origins (e.g., "https://yourfrontend.com,https://app.yourfrontend.com")SMTP_ADDRESS,SMTP_PORT,SMTP_DOMAIN,SMTP_USERNAME,SMTP_PASSWORD: Email configuration for password resets
-
Strong Secrets:
- Generate new
JWT_SECRETandSECRET_KEY_BASEfor production - Never commit secrets to version control
- Use environment variables or encrypted credentials
- Generate new
-
HTTPS:
- Always use HTTPS in production
- Configure SSL termination at the load balancer or reverse proxy level
-
Database Security:
- Use strong database credentials
- Restrict database access to application servers only
- Enable database encryption for sensitive data
-
CORS:
- Restrict allowed origins in
config/initializers/cors.rbor viaCORS_ORIGINSenvironment variable - Never use "*" in production
- Restrict allowed origins in
-
Rate Limiting:
- Implement rate limiting at the infrastructure level
- Consider adding Rack attack middleware for application-level rate limiting
-
File Uploads:
- Validate file types and sizes
- Store uploaded files securely (consider using cloud storage like AWS S3)
- Sanitize filenames
-
Authentication:
- Use secure password policies
- Implement account lockout after failed attempts
- Regularly rotate JWT secrets
-
Database:
- Add appropriate database indexes, especially on foreign keys and frequently queried columns
- Use connection pooling (configured via
RAILS_MAX_THREADS) - Consider read replicas for read-heavy workloads
-
Caching:
- Implement HTTP caching headers
- Use Redis for caching frequently accessed data
- Consider fragment caching for complex views
-
Background Jobs:
- Use Active Job with a backend like Sidekiq for time-consuming operations
- Process email sending and notifications asynchronously
-
Asset Precompilation:
RAILS_ENV=production rails assets:precompile
-
Monitoring:
- Set up application performance monitoring (APM)
- Monitor database query performance
- Track error rates and response times
-
Create a new Heroku app:
heroku create your-app-name
-
Set environment variables:
heroku config:set JWT_SECRET=$(rails secret) heroku config:set SECRET_KEY_BASE=$(rails secret)
-
Add PostgreSQL database:
heroku addons:create heroku-postgresql:hobby-dev
-
Deploy:
git push heroku main
-
Run migrations:
heroku run rails db:migrate
-
Build the Docker image:
docker build -t task_manager_api . -
Run with Docker (example with environment variables):
docker run -d \ -p 80:80 \ -e DATABASE_URL=postgresql://user:pass@dbhost:5432/dbname \ -e JWT_SECRET=your-secret-here \ -e SECRET_KEY_BASE=your-secret-key-base-here \ --name task_manager_api \ task_manager_api
For production-like deployments with separate services:
- Update
docker-compose.ymlwith production settings - Run:
docker-compose up -d
- Set up a reverse proxy (Nginx) to serve static assets and proxy requests to Rails
- Use a process manager like systemd or PM2 to manage the Rails server process
- Set up log rotation for Rails logs
- Configure automated backups for the database
- Set up SSL certificates (Let's Encrypt)
- Configure firewall rules to restrict access
The application includes a health check endpoint at /up that returns 200 if the app is running properly. This can be used by load balancers and uptime monitors.
- Regularly backup your database
- Store backups in a secure, geographically distributed location
- Test backup restoration procedures regularly
- Consider point-in-time recovery for critical data
The Entity Relationship Diagram shows the database structure including Users, Teams, Projects, Tasks, and their relationships.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.