|
| 1 | +# Forgotten API |
| 2 | + |
| 3 | +A Twitter-like social media API built with Go. This is an ongoing project; the README and features will evolve over time. |
| 4 | + |
| 5 | +[](https://app.codacy.com/gh/nevzattalhaozcan/forgotten/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) |
| 6 | +[](https://app.codacy.com/gh/nevzattalhaozcan/forgotten/dashboard?utm_source=github.com&utm_medium=referral&utm_content=nevzattalhaozcan/forgotten&utm_campaign=Badge_Coverage) |
| 7 | +[](https://github.com/nevzattalhaozcan/forgotten/actions/workflows/ci.yml) |
| 8 | + |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +- REST API with JWT auth, user registration/login |
| 13 | +- Built with Gin and Gorm (PostgreSQL) |
| 14 | +- Structured logging, request metrics, and CORS enabled |
| 15 | +- Swagger/OpenAPI documentation (generated with swag) |
| 16 | +- Dockerized for local/dev; CI/CD via GitHub Actions |
| 17 | + |
| 18 | +## Tech stack |
| 19 | + |
| 20 | +- Go 1.23 |
| 21 | +- Gin (HTTP), Gorm (ORM, Postgres) |
| 22 | +- Swagger (swaggo), Prometheus metrics |
| 23 | +- Docker + docker-compose |
| 24 | +- GitHub Actions (CI + Deploy) |
| 25 | + |
| 26 | +## Getting started |
| 27 | + |
| 28 | +1) Prerequisites |
| 29 | +- Go 1.23+ |
| 30 | +- Docker (optional, for containerized dev) |
| 31 | +- PostgreSQL (if running locally without Docker) |
| 32 | + |
| 33 | +2) Clone and enter the project |
| 34 | +```sh |
| 35 | +git clone https://github.com/nevzattalhaozcan/forgotten.git |
| 36 | +cd forgotten |
| 37 | +``` |
| 38 | + |
| 39 | +3) Configure environment |
| 40 | +- Copy `.env.example` to `.env` and adjust as needed: |
| 41 | + - `DATABASE_URL` (e.g., postgres://user:password@localhost:5432/forgotten_db?sslmode=disable) |
| 42 | +- Seed data lives at `data/seed_users.json`. |
| 43 | + |
| 44 | +### Run locally (without Docker) |
| 45 | + |
| 46 | +```sh |
| 47 | +# run the server |
| 48 | +go run ./cmd/server |
| 49 | +# server defaults to http://localhost:8080 |
| 50 | +``` |
| 51 | + |
| 52 | +### Run with Docker Compose |
| 53 | + |
| 54 | +```sh |
| 55 | +cd docker |
| 56 | +docker-compose up -d |
| 57 | +# API available at http://localhost:8080 |
| 58 | +``` |
| 59 | + |
| 60 | +## API docs (Swagger) |
| 61 | + |
| 62 | +- The top-level annotations live in `cmd/server/main.go`. |
| 63 | +- (If needed) generate/update docs: |
| 64 | +```sh |
| 65 | +go install github.com/swaggo/swag/cmd/swag@latest |
| 66 | +swag init -g cmd/server/main.go -o ./docs |
| 67 | +``` |
| 68 | +- Swagger UI can be served at `/swagger` once wired in the router. |
| 69 | + - If not yet enabled, add a route that uses `gin-swagger` and import the generated `docs` package. |
| 70 | + |
| 71 | +Base path: `/api/v1` |
| 72 | + |
| 73 | +## Testing |
| 74 | + |
| 75 | +- Unit tests: |
| 76 | +```sh |
| 77 | +go test -v -race ./... |
| 78 | +``` |
| 79 | +- Coverage: |
| 80 | +```sh |
| 81 | +go test -v -race -coverprofile=coverage.out ./... |
| 82 | +``` |
| 83 | + |
| 84 | +Note: Most tests use an in-memory SQLite DB via `pkg/testutil`; add Postgres-backed integration tests as needed. |
| 85 | + |
| 86 | +## Metrics |
| 87 | + |
| 88 | +- Prometheus-compatible metrics middleware is included. Expose your metrics endpoint (e.g., `/metrics`) as you wire up monitoring. |
| 89 | + |
| 90 | +## Project structure (high level) |
| 91 | + |
| 92 | +- `cmd/server` – application entrypoint |
| 93 | +- `internal/` – config, database, handlers, repository, services, middleware, models |
| 94 | +- `pkg/` – shared libs (logger, metrics, utils, test utilities) |
| 95 | +- `docs/` – generated Swagger docs |
| 96 | +- `docker/` – Dockerfile, docker-compose, Prometheus config |
| 97 | +- `data/` – seed fixtures |
| 98 | + |
| 99 | +## CI/CD |
| 100 | + |
| 101 | +- `.github/workflows/ci.yml` runs tests, lint, and build on PRs/commits. |
| 102 | +- `.github/workflows/deploy.yml` builds and pushes a Docker image and deploys over SSH on main (requires repo secrets). |
| 103 | + |
| 104 | +## Roadmap |
| 105 | + |
| 106 | +- More endpoints (profiles, posts, timelines) |
| 107 | +- RBAC/permissions |
| 108 | +- Full integration test suite |
| 109 | +- Production-ready observability and hardening |
0 commit comments