A RESTful API backend for managing checklist items with Firebase Authentication.
- Overview
- Features
- Tech Stack
- Project Structure
- Getting Started
- Database
- Authentication
- API Documentation
- Development
This backend service provides a RESTful API for managing checklist items. It uses Firebase for authentication and PostgreSQL for data storage with Drizzle ORM.
- User authentication via Firebase
- CRUD operations for checklist items
- Filtering, sorting, and pagination for checklist items
- User-specific data isolation
- Node.js - JavaScript runtime
- Express - Web framework
- TypeScript - Type-safe JavaScript
- PostgreSQL - Database
- Drizzle ORM - Database ORM
- Firebase Admin SDK - Authentication
- dotenv - Environment variable management
checklist-backend/
├── drizzle/ # Drizzle ORM migrations
├── src/
│ ├── db/ # Database configuration
│ │ ├── index.ts # Database connection setup
│ │ ├── migrate.ts # Database migration script
│ │ └── schema.ts # Database schema definitions
│ ├── lib/
│ │ └── firebase-admin.ts # Firebase Admin SDK setup
│ ├── middleware/
│ │ └── auth.ts # Authentication middleware
│ ├── routes/
│ │ ├── auth.ts # Authentication routes
│ │ └── checklist.ts # Checklist CRUD routes
│ └── index.ts # Main application entry point
├── .env # Environment variables
├── drizzle.config.ts # Drizzle ORM configuration
├── package.json # Project dependencies
└── tsconfig.json # TypeScript configuration
- Node.js (v14 or higher)
- PostgreSQL database
- Firebase project with Authentication enabled
-
Clone the repository:
git clone <repository-url> cd checklist-backend
-
Install dependencies:
npm install
-
Set up environment variables (see Environment Variables)
-
Run database migrations:
npm run db:migrate
-
Start the development server:
npm run dev
Create a .env file in the root directory with the following variables:
# Database
DATABASE_URL=postgresql://username:password@localhost:5432/checklist_db
# Firebase
FIREBASE_SERVICE_ACCOUNT={"your-firebase-service-account-json"}
# OR
FIREBASE_SERVICE_ACCOUNT_PATH=/path/to/service-account-file.json
# Server
PORT=3000
NODE_ENV=development
The application uses PostgreSQL with Drizzle ORM. The schema includes:
id- UUID primary keyfirebase_uid- Firebase user ID (unique)name- User's nameemail- User's email (unique)
id- UUID primary keyuserId- Foreign key to users tabletitle- Item titledescription- Item description (optional)category- Item category (optional)completed- Completion status (boolean)dueDate- Due date (optional)priority- Priority level (1-5, default: 3)createdAt- Creation timestampupdatedAt- Last update timestamp
Authentication is handled via Firebase. The application uses Firebase Admin SDK to verify ID tokens sent from the client.
- Users authenticate with Firebase on the client side
- The client sends the Firebase ID token in the Authorization header
- The server verifies the token and identifies the user
- New users are synced to the database via the
/api/auth/syncendpoint
Syncs a Firebase user with the database.
Request:
{
"uid": "firebase-user-id",
"email": "user@example.com",
"name": "User Name"
}Response:
{
"user": {
"id": "uuid",
"firebase_uid": "firebase-user-id",
"name": "User Name",
"email": "user@example.com"
},
"created": true
}Gets the current authenticated user.
Response:
{
"user": {
"id": "uuid",
"firebase_uid": "firebase-user-id",
"name": "User Name",
"email": "user@example.com"
}
}Gets paginated checklist items.
Query Parameters:
page- Page number (default: 1)limit- Items per page (default: 30)category- Filter by categorysearch- Search in titlesortField- Field to sort by (default: priority)sortDirection- Sort direction (asc/desc, default: asc)
Response:
{
"items": [
{
"id": "uuid",
"userId": "user-uuid",
"title": "Item title",
"description": "Item description",
"category": "Category",
"completed": false,
"dueDate": "2023-06-15T00:00:00.000Z",
"priority": 3,
"createdAt": "2023-06-01T00:00:00.000Z",
"updatedAt": "2023-06-01T00:00:00.000Z"
}
],
"totalCount": 100,
"currentPage": 1,
"totalPages": 4
}Creates a new checklist item.
Request:
{
"title": "New item",
"description": "Item description",
"category": "Category",
"dueDate": "2023-06-15T00:00:00.000Z",
"priority": 2
}Response:
{
"id": "uuid",
"userId": "user-uuid",
"title": "New item",
"description": "Item description",
"category": "Category",
"completed": false,
"dueDate": "2023-06-15T00:00:00.000Z",
"priority": 2,
"createdAt": "2023-06-01T00:00:00.000Z",
"updatedAt": "2023-06-01T00:00:00.000Z"
}Updates a checklist item.
Request:
{
"title": "Updated title",
"completed": true
}Response:
{
"id": "uuid",
"userId": "user-uuid",
"title": "Updated title",
"description": "Item description",
"category": "Category",
"completed": true,
"dueDate": "2023-06-15T00:00:00.000Z",
"priority": 2,
"createdAt": "2023-06-01T00:00:00.000Z",
"updatedAt": "2023-06-02T00:00:00.000Z"
}Deletes a checklist item.
Response:
{
"success": true
}npm run dev- Start development server with hot reloadingnpm run build- Build the TypeScript projectnpm start- Start the production servernpm run db:generate- Generate Drizzle ORM migrationsnpm run db:migrate- Run database migrations