Skip to content

itsmefabian/cassandra-bun

Repository files navigation

# Bun + Cassandra CRUD API

This project is a simple REST API built with [Bun](https://bun.sh/) and [Apache Cassandra](https://cassandra.apache.org/) to demonstrate basic CRUD operations.

## Features

- Written in TypeScript using Bun
- Apache Cassandra integration
- CRUD operations for users
- Dockerized setup with `bun` app and `cassandra`
- Unit tests using `bun:test`

## Getting Started

### Prerequisites

- [Docker](https://www.docker.com/)
- [Bun](https://bun.sh/) (for local testing, optional)

### Environment Variables

You can configure Cassandra using the following environment variables:

```bash
CASSANDRA_CONTACT_POINTS=cassandra
CASSANDRA_LOCAL_DC=datacenter1
CASSANDRA_KEYSPACE=mykeyspace
PORT=3000
```

### Running the Project

To build and run the project using Docker:

```bash
docker compose up --build
```

This will start both the Cassandra service and the Bun application.

### Running Locally

For local development, make sure Cassandra is running and then run:

```bash
bun install
bun run index.ts
```

Adjust `CASSANDRA_CONTACT_POINTS=localhost` if you are connecting to a local Cassandra instance.

### Running Tests

You can run the test suite with:

```bash
bun test
```

Or inside the Docker container:

```bash
docker exec -it bun-app bun test ./test/crud.tests.ts
```

## File Structure

- `index.ts`: Entry point with HTTP server and routes
- `database/cassandra.client.ts`: Cassandra connection and initialization logic
- `services/user.service.ts`: User-related CRUD operations
- `test/crud.tests.ts`: Automated tests
- `Dockerfile` and `docker-compose.yml`: Containerization setup

## Notes

- The server checks if the desired port is available before starting.
- You can configure separate Cassandra contact points for local and Docker environments.
- Test coverage includes all CRUD operations.

## License

This project is open source and available under the [MIT License](LICENSE).

About

This project was created using Bun as technology and Cassandra as a repository

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published