DBTex API
May 27, 2025 ยท View on GitHub
A FastAPI-based backend service for managing users and conversations, backed by PostgreSQL, Docker, and GitHub Actions CI/CD.

๐ Features
-
- User Management: Secure user registration & retrieval with hashed passwords.
-
- JWT Authentication: OAuth2 password flow using
jose.
- JWT Authentication: OAuth2 password flow using
-
- Conversations & Memories: CRUD endpoints for storing user messages and LLM responses.
-
- Voting System: Upvote/downvote conversations.
-
- Dockerized: Development & production Docker Compose configurations.
-
- CI/CD: Automated tests, Docker image build & push, Heroku & Ubuntu deployments via GitHub Actions.
-
- Thematic README: This file!
๐ฆ Project Structure
/home/siisi/dbtex-api
โโโ app
โ โโโ config.py # Pydantic settings
โ โโโ database.py # SQLAlchemy engine & session
โ โโโ main.py # FastAPI app creation & startup
โ โโโ models.py # SQLAlchemy ORM models
โ โโโ routers
โ โ โโโ auth.py
โ โ โโโ conversation.py
โ โ โโโ user.py # User endpoints (with unique-email handling)
โ โ โโโ vote.py
โ โโโ schemas.py # Pydantic request/response models
โ โโโ utils.py # Hashing & verification helpers
โโโ docker-compose-dev.yml # Dev compose (hot-reload, local Postgres)
โโโ docker-compose-prod.yml# Prod compose (image pull, nginx proxy via systemd)
โโโ Dockerfile # Production image definition
โโโ .env # Dev environment variables
โโโ .env.prod # Prod environment variables
โโโ README.md # โ this file
โโโ .github/workflows
โโโ build_deploy.yml # CI: test, build, push, deploy
๐ง Local Development
-
Clone
git clone git@github.com:YOUR_USERNAME/dbtex-api.git cd dbtex-api -
Dev environment
-
Copy
.env.exampleโ.envand fill in your credentials. -
Start services:
docker compose -f docker-compose-dev.yml up --build -
FastAPI available at
http://localhost:8009(mapped port) -
Swagger UI:
http://localhost:8009/docs
-
-
Database reset (dev only):
docker compose -f docker-compose-dev.yml down -v docker compose -f docker-compose-dev.yml up --build
โ๏ธ Production Testing
-
Prepare
.env.prodcp .env.prod.example .env.prod # Fill in your production values -
Run compose
docker compose -f docker-compose-prod.yml up -d --build -
Verify logs
docker compose -f docker-compose-prod.yml logs -f -
Access via Nginx
- Domain:
https://dbtex-api.siisi.online - Ensure Nginx proxy targets the container port (e.g. 8001)
- Domain:
๐ CI/CD Pipeline
-
- On push or PR:
- Run
pytest - Lint & type-check (optional)
- Build & push Docker image to Docker Hub
- Deploy to Heroku & Ubuntu via SSH
Edit secrets in GitHub settings:
OPENAI_API_KEY,ADMIN_DATABASE_URL,DOCKER_HUB_USERNAME, etc.
๐ API Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /users/ | Create user (409 if email exists) |
| GET | /users/{id} | Retrieve user by ID |
| POST | /login | Obtain JWT token |
| GET | /conversation/ | List conversations |
| POST | /conversation/ | Create a conversation memory |
| PUT | /conversation/{id} | Update a memory |
| DELETE | /conversation/{id} | Delete a memory |
| POST | /vote/ | Upvote/downvote a memory |
Refer to the automatic docs at /docs for full schema details.
๐ Further Improvements
- Add pagination to list endpoints.
- Integrate Redis for caching heavy queries.
- Secure cookies & CSRF for browser-based clients.
- Add OpenAPI tags grouping and descriptions.
๐ License
MIT ยฉ 2025 Siisi