{"id":18698185,"url":"https://github.com/dodycode/nodejs-typescript-boilerplate","last_synced_at":"2025-04-12T07:32:50.079Z","repository":{"id":256682591,"uuid":"856117773","full_name":"dodycode/nodejs-typescript-boilerplate","owner":"dodycode","description":" a boilerplate for building a NodeJS API using TypeScript, Hono, Drizzle ORM, and Zod, that implemented Repository Design Pattern.","archived":false,"fork":false,"pushed_at":"2024-09-14T22:26:21.000Z","size":55,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-15T06:19:44.373Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dodycode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-12T02:47:24.000Z","updated_at":"2024-09-14T22:26:22.000Z","dependencies_parsed_at":"2024-09-15T06:19:45.361Z","dependency_job_id":null,"html_url":"https://github.com/dodycode/nodejs-typescript-boilerplate","commit_stats":null,"previous_names":["dodycode/nodejs-typescript-boilerplate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodycode%2Fnodejs-typescript-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodycode%2Fnodejs-typescript-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodycode%2Fnodejs-typescript-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dodycode%2Fnodejs-typescript-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dodycode","download_url":"https://codeload.github.com/dodycode/nodejs-typescript-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223504961,"owners_count":17156437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T11:27:20.988Z","updated_at":"2024-11-07T11:27:21.580Z","avatar_url":"https://github.com/dodycode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript Hono Drizzle Zod API Boilerplate\n\nThis project is a boilerplate for building a NodeJS API using TypeScript, Hono, Drizzle ORM, and Zod, that implemented Repository Design Pattern.\n\n## Features\n\n- **TypeScript**: For type-safe JavaScript development\n- **Hono**: A lightweight and fast web framework\n- **Drizzle ORM**: TypeScript ORM for SQL databases\n- **Zod**: Runtime type checking and validation\n- **PostgreSQL**: As the database backend\n- **Repository Pattern**: For clean separation of data access logic\n- **Generic Base Repository**: Reduces code repetition for CRUD operations\n- **Input Validation**: Using Zod schemas and custom middleware\n- **Docker**: Easy PostgreSQL setup with Docker Compose\n- **Prettier**: For consistent code formatting\n- **ESLint**: For identifying and fixing code quality issues\n\n## Prerequisites\n\n- Node.js (v14 or later recommended)\n- Docker and Docker Compose\n- npm or yarn package manager\n\n## Project Structure\n\n```\n.\n├── src/\n│   ├── controllers/\n|   |   ├── todoController.ts\n│   │   └── your-controller\n│   ├── db/\n│   │   ├── db.ts\n│   │   └── schema.ts\n│   ├── middleware/\n│   │   └── validator.ts\n│   ├── models/\n|   |   ├── todo.ts\n│   │   └── your-entity-model\n│   ├── repositories/\n│   │   ├── baseRepository.ts\n│   │   ├── todoRepository.ts\n│   │   └── your-repository\n│   ├── routes/\n|   |   ├── todoRoutes.ts\n│   │   └── your-routes\n│   └── index.ts\n├── drizzle/\n│   └── your-database-migration-files\n├── .env.example\n├── .eslintrc.js\n├── .gitignore\n├── .prettierrc\n├── docker-compose.yml\n├── drizzle.config.ts\n├── package.json\n├── README.md\n└── tsconfig.json\n```\n\n## Getting Started\n\n1. Clone the repository:\n\n   ```\n   git clone https://github.com/dodycode/ts-hono-drizzle-zod-boilerplate.git\n   cd ts-hono-drizzle-zod-boilerplate\n   ```\n\n2. Install dependencies:\n\n   ```\n   npm install\n   ```\n\n3. Set up the PostgreSQL database using Docker:\n\n   ```\n   docker-compose up -d\n   ```\n\n4. Set up your environment variables:\n\n   - Copy `.env.example` to `.env`\n   - Update `DATABASE_URL` in `.env`:\n     ```\n     DATABASE_URL=postgres://myuser:mypassword@localhost:5432/myapp\n     ```\n     Note: You can configure postgre user in `docker-compose.yml`\n\n5. Create database migrations:\n\n   ```\n   npm run generate\n   ```\n\n6. Run database migrations:\n\n   ```\n   npm run migrate\n   ```\n\n7. Start the development server:\n   ```\n   npm run dev\n   ```\n\nThe server should now be running on `http://localhost:3000`.\n\n## Database Management\n\nThis project uses Drizzle ORM for database management. Here are the available scripts and when to use them:\n\n- `npm run generate`: Generate Drizzle migration files (run this after making changes to your schema)\n- `npm run migrate`: Run Drizzle migrations (use this for the initial setup and when you want to apply migrations)\n- `npm run push`: Push schema changes to the database (use this during development to quickly apply schema changes)\n- `npm run studio`: Open Drizzle Studio for database management\n\n### Workflow for Schema Changes\n\n1. Make changes to your schema in `/src/server/db/schema/`\n2. Run `pnpm generate` or `npm run generate` to create a new migration\n3. Run `pnpm push` or `npm run push` to apply the changes to your development database\n\nFor production or when you need to keep track of migrations:\n\n1. Make changes to your schema\n2. Run `pnpm generate` or `npm run generate`\n3. Run `pnpm migrate` or `npm run migrate` to apply the migrations\n\nRemember to commit the generated migration files to your version control system.\n\n## API Endpoints\n\n- `GET /api/todos`: Retrieve all todos\n- `GET /api/todos/:id`: Retrieve a specific todo\n- `POST /api/todos`: Create a new todo\n- `PUT /api/todos/:id`: Update an existing todo\n- `DELETE /api/todos/:id`: Delete a todo\n\n## Scripts\n\n- `npm start`: Start the development server\n- `npm run build`: Compile TypeScript to JavaScript\n- `npm run migrate`: Run database migrations\n- `npm run lint`: Run ESLint to check for code quality issues\n- `npm run format`: Run Prettier to automatically format your code\n- `npm run format:check`: Check if your code is properly formatted without making changes\n\n## Docker Commands\n\n- Start the PostgreSQL container: `docker-compose up -d`\n- Stop the PostgreSQL container: `docker-compose down`\n- View container logs: `docker-compose logs`\n\n## Adding New Entities\n\n1. Define the entity schema in `src/db/schema.ts`\n2. Create a model file in `src/models/` with Zod schemas and type definitions\n3. Create a repository in `src/repositories/` extending the `BaseRepository`\n4. Create a controller in `src/controllers/`\n5. Define routes in `src/routes/`\n6. Update `src/index.ts` to include the new routes\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdodycode%2Fnodejs-typescript-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdodycode%2Fnodejs-typescript-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdodycode%2Fnodejs-typescript-boilerplate/lists"}