TaskMaster - Task Management System
TaskMaster - Complete Task Management System
Section titled โTaskMaster - Complete Task Management SystemโTaskMaster is a comprehensive backend example that demonstrates the full capabilities of Veloce-TS. This example showcases how to build a production-ready task management system with authentication, authorization, real-time features, and more.
:::tip Current releases
This walkthrough targets Veloce-TS v0.4.x on npm. Cross-check imports and plugin APIs with the changelogโolder snippets in this page may predate VeloceTS, usePlugin, or RFC 9457 errors.
:::
:::note Basic Example This is a basic backend-only example designed to demonstrate Veloce-TS capabilities. It focuses on API development and doesnโt include a frontend interface. :::
๐ Features Demonstrated
Section titled โ๐ Features Demonstratedโโ Core Framework Features
Section titled โโ Core Framework Featuresโ- Decorator-based routing (
@Controller,@Get,@Post, etc.) - Dependency Injection with singleton scope
- Request validation using Zod schemas
- Automatic OpenAPI documentation
- Custom middleware (logging, analytics, performance)
- Error handling with custom exceptions
- Plugin system integration
โ Authentication & Authorization
Section titled โโ Authentication & Authorizationโ- JWT-based authentication with access/refresh tokens
- Role-Based Access Control (RBAC) with 5 role levels
- Granular permissions system
- Protected routes and endpoints
โ Database & Persistence
Section titled โโ Database & Persistenceโ- SQLite integration using Bunโs native database
- CRUD operations for all entities
- Data validation and type safety
- Relationship management
โ Advanced Features
Section titled โโ Advanced Featuresโ- GraphQL support with custom resolvers
- WebSocket handlers for real-time notifications
- Analytics middleware for performance tracking
- Admin panel endpoints for system management
๐ Project Structure
Section titled โ๐ Project Structureโtaskmaster/โโโ src/โ โโโ controllers/ # REST API controllersโ โ โโโ auth.controller.tsโ โ โโโ task.controller.tsโ โ โโโ user.controller.tsโ โ โโโ team.controller.tsโ โ โโโ admin.controller.tsโ โโโ services/ # Business logic servicesโ โ โโโ user.service.tsโ โ โโโ task.service.tsโ โ โโโ team.service.tsโ โ โโโ notification.service.tsโ โโโ resolvers/ # GraphQL resolversโ โ โโโ task.resolver.tsโ โ โโโ user.resolver.tsโ โโโ websockets/ # WebSocket handlersโ โ โโโ notification.websocket.tsโ โโโ middleware/ # Custom middlewareโ โ โโโ logging.middleware.tsโ โ โโโ analytics.middleware.tsโ โโโ models/ # TypeScript typesโ โ โโโ types.tsโ โโโ config/ # Configuration filesโ โ โโโ auth.config.tsโ โ โโโ database.tsโ โโโ index.ts # Application entry pointโโโ package.jsonโโโ README.md๐ ๏ธ Setup & Installation
Section titled โ๐ ๏ธ Setup & InstallationโPrerequisites
Section titled โPrerequisitesโ- Bun >= 1.0.0
- Node.js >= 18.0.0
Quick Start
Section titled โQuick Startโ- Clone the example:
git clone <repository-url>cd examples/veloce-taskmaster- Install dependencies:
bun install- Run the development server:
bun run dev- Access the API:
- API Documentation: http://localhost:3001/docs
- Health Check: http://localhost:3001/health
- API Info: http://localhost:3001/api
๐ Key Implementation Examples
Section titled โ๐ Key Implementation Examplesโ๐ Authentication Controller
Section titled โ๐ Authentication Controllerโ@Controller('/api/auth')export class AuthController { @Post('/login') @ApiDoc({ summary: 'User login' }) async login( @Body(LoginSchema) credentials: LoginCredentials, @Depends(UserService) userService: UserService, @Depends(AuthService) authService: AuthService ) { const user = await userService.validateCredentials( credentials.username, credentials.password );
if (!user) { throw new AuthenticationException('Invalid credentials'); }
const tokens = await authService.generateTokens({ sub: user.id, username: user.username, role: user.role, permissions: user.permissions });
return { user, tokens }; }}๐ฏ Task Controller with RBAC
Section titled โ๐ฏ Task Controller with RBACโ@Controller('/api/tasks')export class TaskController { @Get('/') @Auth() @MinimumRole('developer') async listTasks( @Query() filters: TaskFilters, @CurrentUser() user: JWTPayload, @Depends(TaskService) taskService: TaskService ) { // Role-based filtering if (user.role !== 'admin' && user.role !== 'manager') { filters.assigneeId = user.sub; }
return await taskService.findAll(filters); }
@Post('/') @Auth() @MinimumRole('developer') @Permissions(['tasks:create']) async createTask( @Body(CreateTaskSchema) data: CreateTaskDTO, @CurrentUser() user: JWTPayload, @Depends(TaskService) taskService: TaskService ) { return await taskService.create(data, user.sub); }}๐๏ธ Service Layer with SQLite
Section titled โ๐๏ธ Service Layer with SQLiteโexport class TaskService { private db: Database;
constructor() { this.db = getDatabase(); }
async create(data: CreateTaskDTO, creatorId: string): Promise<Task> { const stmt = this.db.prepare(` INSERT INTO tasks (title, description, priority, creator_id, status) VALUES (?, ?, ?, ?, ?) `);
const result = stmt.run( data.title, data.description, data.priority, creatorId, 'todo' );
return await this.findById(result.lastInsertRowid.toString()); }}๐ GraphQL Resolver
Section titled โ๐ GraphQL Resolverโ@Resolver('Task')export class TaskResolver { @GQLQuery('tasks') @Arg('filters', () => TaskFiltersInput) async getTasks( @Arg('filters') filters: TaskFilters, @Depends(TaskService) taskService: TaskService ) { return await taskService.findAll(filters); }
@GQLMutation('createTask') @Arg('input', () => CreateTaskInput) async createTask( @Arg('input') input: CreateTaskDTO, @Depends(TaskService) taskService: TaskService, @CurrentUser() user: JWTPayload ) { return await taskService.create(input, user.sub); }}๐ WebSocket Handler
Section titled โ๐ WebSocket Handlerโ@WebSocket('/ws/notifications')export class NotificationWebSocket { @OnConnect() async onConnect(connection: WebSocketConnection) { console.log('User connected:', connection.id); }
@OnMessage() async onMessage( connection: WebSocketConnection, message: any ) { // Broadcast notification to all connected clients await this.broadcast(message); }}๐ก๏ธ Custom Middleware
Section titled โ๐ก๏ธ Custom Middlewareโexport const loggingMiddleware = async (c: Context, next: Next) => { const start = Date.now(); const requestId = crypto.randomUUID();
c.set('requestId', requestId); c.set('startTime', start);
console.log(`[${requestId}] โ ${c.req.method} ${c.req.url}`);
await next();
const duration = Date.now() - start; console.log(`[${requestId}] โ ${c.req.method} ${c.req.url} ${c.res.status} (${duration}ms)`);};๐ฎ Demo Users
Section titled โ๐ฎ Demo UsersโThe example includes pre-configured demo users for testing:
| Username | Password | Role | Permissions |
|---|---|---|---|
admin | admin123 | admin | Full access |
manager1 | manager123 | manager | Team management |
teamlead1 | lead123 | team_lead | Project leadership |
dev1 | dev123 | developer | Task management |
dev2 | dev123 | developer | Task management |
๐ก API Endpoints
Section titled โ๐ก API EndpointsโAuthentication
Section titled โAuthenticationโPOST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutPOST /api/auth/refresh- Token refreshGET /api/auth/me- Get current user
GET /api/tasks- List tasks (with filtering)GET /api/tasks/:id- Get task by IDPOST /api/tasks- Create new taskPUT /api/tasks/:id- Update taskDELETE /api/tasks/:id- Delete taskPOST /api/tasks/:id/status- Update task statusPOST /api/tasks/:id/assign- Assign taskGET /api/tasks/stats/overview- Task statistics
Users & Teams
Section titled โUsers & TeamsโGET /api/users- List usersGET /api/teams- List teamsPOST /api/teams- Create teamPOST /api/teams/:id/members- Add team member
Admin (Admin only)
Section titled โAdmin (Admin only)โGET /api/admin/users- All usersGET /api/admin/tasks- All tasksPUT /api/admin/users/:id/role- Change user roleGET /api/admin/stats/system- System statistics
๐ง Configuration
Section titled โ๐ง ConfigurationโEnvironment Variables
Section titled โEnvironment Variablesโ# Server ConfigurationPORT=3001NODE_ENV=development
# DatabaseDATABASE_URL=./taskmaster.db
# JWT ConfigurationJWT_SECRET=your-super-secret-keyJWT_EXPIRES_IN=1hJWT_REFRESH_EXPIRES_IN=7dDatabase Schema
Section titled โDatabase SchemaโThe example automatically creates the following tables:
users- User accounts and profilestasks- Task managementteams- Team organizationnotifications- Real-time notifications
๐ Production Considerations
Section titled โ๐ Production ConsiderationsโWhile this is a basic example, here are considerations for production use:
๐ Security
Section titled โ๐ Securityโ- Use environment variables for secrets
- Implement proper password hashing (bcrypt)
- Add rate limiting
- Enable HTTPS
- Configure CORS properly
๐๏ธ Database
Section titled โ๐๏ธ Databaseโ- Use PostgreSQL or MySQL for production
- Implement database migrations
- Add connection pooling
- Set up database backups
๐ Monitoring
Section titled โ๐ Monitoringโ- Add comprehensive logging
- Implement health checks
- Set up error tracking
- Monitor performance metrics
๐ Scaling
Section titled โ๐ Scalingโ- Use Redis for session storage
- Implement horizontal scaling
- Add load balancing
- Set up CDN for static assets
๐ Learning Path
Section titled โ๐ Learning PathโThis example demonstrates:
- Basic Setup - Project structure and configuration
- Authentication - JWT and RBAC implementation
- CRUD Operations - Database interactions
- Middleware - Custom request/response handling
- GraphQL - Alternative API approach
- WebSockets - Real-time features
- Validation - Request data validation
- Documentation - OpenAPI/Swagger integration
๐ Related Resources
Section titled โ๐ Related Resourcesโ:::tip Next Steps Ready to build your own application? Check out the Getting Started Guide to create your first Veloce-TS project! :::