A Hono-based backend API with PostgreSQL database using Drizzle ORM and JWT authentication.
npm installdocker-compose up -dnpm run db:generate
npm run db:migratenpm run devid(UUID, Primary Key)name(VARCHAR)email(VARCHAR, Unique)password(VARCHAR, Hashed)role(ENUM: customer, contractor, admin)created_at(TIMESTAMP)updated_at(TIMESTAMP)
id(UUID, Primary Key)customer_id(UUID, Foreign Key to users.id)contractor_id(UUID, Foreign Key to users.id)service_type(VARCHAR)address(TEXT)status(ENUM: pending, in_progress, completed, cancelled)scheduled_at(TIMESTAMP)created_at(TIMESTAMP)updated_at(TIMESTAMP)
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm run start- Start production servernpm run db:generate- Generate migration filesnpm run db:migrate- Run migrationsnpm run db:studio- Open Drizzle Studio
GET /- Hello worldGET /health- Health check with database connection test
POST /auth/register- Register a new userPOST /auth/login- Login with email and passwordPOST /auth/logout- Logout (client-side token removal)GET /auth/me- Get current user information
GET /protected- Example protected route (requires authentication)
The API uses JWT (JSON Web Tokens) for stateless authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Stateless - No server-side session storage
- 30-day expiration - Tokens expire after 30 days
- Role-based - Tokens include user role information
- Secure - Signed with secret key
curl -X POST http://localhost:3000/auth/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"role": "customer"
}'curl -X POST http://localhost:3000/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'curl -X GET http://localhost:3000/protected \
-H "Authorization: Bearer <your-jwt-token>"customer- Can create jobs and view their own jobscontractor- Can view and update jobs assigned to themadmin- Full access to all features
Create a .env file in the root directory:
JWT_SECRET=your-secret-key-change-in-production