https://github.com/nishantcoder108/grpc-todo-typescript
https://github.com/nishantcoder108/grpc-todo-typescript
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nishantcoder108/grpc-todo-typescript
- Owner: NishantCoder108
- Created: 2025-08-17T10:36:34.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2025-08-17T10:36:40.000Z (10 months ago)
- Last Synced: 2025-09-06T21:00:45.186Z (9 months ago)
- Language: TypeScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gRPC Todo (TypeScript)
A minimal, production‑minded gRPC service and client in TypeScript. It demonstrates unary and server‑streaming RPCs, request deadlines, metadata‑based auth, and a clean path toward codegen and TLS.
## Features
- Todo service with Create/Get/Delete (unary) and List (server‑streaming)
- Per‑request deadlines (client)
- Metadata auth (Authorization: `Bearer devtoken`)
- Contract‑first design via Protobuf (`proto/todo/v1/todo.proto`)
## Tech
- Node 18+, TypeScript
- `@grpc/grpc-js`, `@grpc/proto-loader`
## Quick start
1) Install dependencies
```bash
npm install
```
2) Run the server
```bash
npm run dev:server
# gRPC server listening on 0.0.0.0:50051
```
3) Run the client (in another terminal)
```bash
npm run dev:client
# created/got/list/deleted logs
```
## Project structure
```
proto/
todo/v1/todo.proto # Protobuf API contract (single source of truth)
src/
server.ts # gRPC server (handlers, auth, streaming)
client.ts # gRPC client (deadlines, metadata)
```
## API
`proto/todo/v1/todo.proto` defines:
- Messages: `Todo`, `CreateTodoRequest/Response`, `GetTodoRequest/Response`, `DeleteTodoRequest/Response`, `ListTodosRequest/Response`
- Service: `TodoService` with RPCs `CreateTodo`, `GetTodo`, `DeleteTodo`, `ListTodos` (server‑streaming)
Example (Node client):
```ts
client.CreateTodo({ title: "Learn gRPC" }, md, { deadline }, cb);
```
- `md` includes `authorization: Bearer devtoken`
- `deadline` is a `Date` (e.g., 3s)
## Transport & Security
- Dev: plaintext h2c via `createInsecure()`
- Prod: TLS
- Server: `ServerCredentials.createSsl(...)`
- Client: `credentials.createSsl(ca)`
- Prefer mTLS for service‑to‑service auth
## Next steps (roadmap)
- Strong typing via `ts-proto` codegen
- DB repository (SQLite/Postgres) instead of in‑memory store
- Outbox + Kafka for events
- TLS/mTLS, health, reflection, observability (OpenTelemetry)
- Tests (unit + bufconn integration) and CI
## License
MIT