An open API service indexing awesome lists of open source software.

https://github.com/pulgamecanica/matcha

Matcha - 42
https://github.com/pulgamecanica/matcha

api ruby sinatra sinatra-applications

Last synced: about 1 year ago
JSON representation

Matcha - 42

Awesome Lists containing this project

README

          

# πŸ§ͺ Matcha API β€” Love & Ruby πŸ’˜

[![Sinatra](https://img.shields.io/badge/Made%20with-Sinatra-ff69b4?logo=sinatra)](http://sinatrarb.com/)
[![PostgreSQL](https://img.shields.io/badge/Database-PostgreSQL-336791?logo=postgresql)](https://www.postgresql.org/)
[![Dockerized](https://img.shields.io/badge/Dockerized-Yes-blue?logo=docker)](https://www.docker.com/)
[![Tested with RSpec](https://img.shields.io/badge/Tested%20with-RSpec-ff4155?logo=ruby)](https://rspec.info/)
[![TDD](https://img.shields.io/badge/TDD-Driven-%23cc0066?logo=testing-library)]()
[![Custom DSL](https://img.shields.io/badge/DSL-api_doc-%23bada55)]()

> The only thing better than a Matcha latte is a **match made in Ruby**.
> This is a fully-documented, TDD-driven Sinatra API for the Matcha dating platform. It’s modular, dockerized, and optimized for love at first request πŸ’˜

---

## πŸ“¦ Tech Stack

| Layer | Tech |
|---------------|-------------------------|
| Framework | Sinatra (modular style) |
| Language | Ruby 3.2 |
| Database | PostgreSQL 14 |
| Persistence | Raw SQL + SQLHelper |
| Auth | JWT (handrolled) |
| Container | Docker + Compose |
| Testing | RSpec + Rack::Test |
| Docs | `api_doc` DSL (custom) |
| Console | IRB via bin/console |
| Tasks | Rake + Makefile |

---

## βš™οΈ Features

- πŸ” **Authentication**: Email/password & social (Google, Facebook, Snapchat)
- πŸ§ͺ **TDD-first** with RSpec specs for everything
- 🧼 **Clean architecture**: Helpers, controllers, and models separated
- πŸ”’ **JWT-based sessions** (no gem dependencies)
- 🧠 **Robust validation** with reusable DSL-based `Validator`
- 🌍 **RESTful routes**: `/auth`, `/me`, `/users/:username`, etc.
- 🚫 **Ban & Confirm logic**: No banned or unconfirmed user can access the API
- πŸ’Ύ **Smart SQL helper**: `SQLHelper.create`, `update`, `find_by`, etc.
- 🧾 **API docs**: Exportable via `make docs`
- 🐳 **Fully dockerized**
- πŸ’¬ Friendly, readable logs

---

## πŸ—‚οΈ Project Structure

```
.
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ controllers/ # Modular Sinatra apps (AuthController, UsersController)
β”‚ β”œβ”€β”€ helpers/ # Validators, SQLHelper, Request parsing, Auth, Database
β”‚ β”œβ”€β”€ models/ # Models (User, ...)
β”‚ β”œβ”€β”€ lib/ # Shared error classes, doc
β”œβ”€β”€ config/
β”‚ └── database.yml # Database settings
β”‚ └── environment.rb # Loads everything
β”œβ”€β”€ db/
β”‚ β”œβ”€β”€ migrate/ # DB migrations
β”‚ └── seeds.rb # (optional)
β”œβ”€β”€ spec/ # RSpec suite
β”œβ”€β”€ docker/ # Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Rakefile
β”œβ”€β”€ Makefile
β”œβ”€β”€ .env
β”œβ”€β”€ config.ru
└── README.md
```

---

## πŸš€ Getting Started

---

### πŸ“˜ Postman Collection

> Visit the [Postman Colleciton](https://pulgamecanica.postman.co/workspace/pulgamecanica~fddcef76-1724-4c9d-8f90-c24cfe79c2b9/collection/13231501-422c8247-c0ee-4bec-834b-ede0215c4e05?action=share&creator=13231501) to run all the API endpoints.

---

### πŸ”§ Local Dev (Dockerized)

```bash
git clone https://github.com/pulgamecanica/matcha
cd matcha

# Build containers
docker compose build

# Start the app
docker compose up

# Open dev console
make console

# Run the test suite
make test
```

---

## πŸ§ͺ Testing

RSpec tests live in `spec/`, with:
- Integration tests for endpoints
- Unit tests for helpers
- Full TDD on auth, validation, sessions, and core models

```bash
make test
```

---

## πŸ› οΈ Developer Shortcuts (Makefile)

```bash
make create # db:create
make migrate # db:migrate
make test # run all specs
make console # open IRB console
make docs # export route documentation
```

---

## πŸ” Authentication

Stateless JWT (no libraries!) via `SessionToken`.

```rb
SessionToken.generate(user_id) # => "encoded.jwt.token"
SessionToken.decode(token) # => { "user_id" => 42, ... }
```

---

## πŸ“˜ API Documentation

Each route is documented inline with the `api_doc` DSL.
To export to markdown:

```bash
make docs
```

➑ Output: `docs/exported.md`

Example:

```ruby
api_doc "/auth/register", method: :post do
description "Register a new user"
param :email, String, required: true
param :username, String, required: true
param :password, String, required: true
response 201, "User created"
end
```

---

## πŸš€ Endpoints (Implemented)

- `POST /auth/register`
- `POST /auth/login`
- `POST /auth/social`
- `GET /me`
- `PATCH /me`
- `DELETE /me`
- `GET /users/:username`

(⚠️ All protected endpoints require JWT via `Authorization: Bearer `)

---

## 🎯 Roadmap

- [x] JWT session system
- [x] Login, Register, Social Auth
- [x] Patch & Delete `/me`
- [x] Ban, confirm & protect endpoints
- [x] Public profiles `/users/:username`
- [x] API Docs via DSL
- [x] Validation system
- [x] SQLHelper abstraction
- [x] Tag system
- [x] Connections, Likes
- [X] Notifications
- [ ] Commonly used English words should not be accepted as passwords.
- [ ] Real-time messaging (WebSocket or polling)
- [ ] Full CI/CD pipeline

---

## πŸ’‘ Philosophy

> πŸ“œ Everything documented
> πŸ§ͺ Everything tested
> 🚫 No unhandled JSON
> πŸ’₯ No silent failures
> πŸ’Ž Code should read like Ruby poetry

---