{"id":26027527,"url":"https://github.com/artoriascode/jwtgo","last_synced_at":"2025-03-06T16:22:33.409Z","repository":{"id":270753690,"uuid":"911352655","full_name":"ArtoriasCode/jwtgo","owner":"ArtoriasCode","description":"🔥 Example of microservice JWT authentication using MongoDB and clean architecture principles.","archived":false,"fork":false,"pushed_at":"2025-02-26T18:58:06.000Z","size":367,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T13:27:26.844Z","etag":null,"topics":["bcrypt","boilerplate","clean-architecture","cleanenv","docker","docker-compose","gin","go","golang","grpc","jwt","layout","logrus","microservice","mongodb","nginx","protobuf","reverse-proxy"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArtoriasCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-02T20:17:59.000Z","updated_at":"2025-02-26T18:58:09.000Z","dependencies_parsed_at":"2025-02-23T18:25:43.085Z","dependency_job_id":"b2156774-f67f-43ac-afde-4ea4186d4b01","html_url":"https://github.com/ArtoriasCode/jwtgo","commit_stats":null,"previous_names":["astarothcode/jwtgo","astagnar/jwtgo","cryognar/jwtgo","ornntrox/jwtgo","artoriascode/jwtgo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtoriasCode%2Fjwtgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtoriasCode%2Fjwtgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtoriasCode%2Fjwtgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtoriasCode%2Fjwtgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtoriasCode","download_url":"https://codeload.github.com/ArtoriasCode/jwtgo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242241990,"owners_count":20095472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bcrypt","boilerplate","clean-architecture","cleanenv","docker","docker-compose","gin","go","golang","grpc","jwt","layout","logrus","microservice","mongodb","nginx","protobuf","reverse-proxy"],"created_at":"2025-03-06T16:22:32.059Z","updated_at":"2025-03-06T16:22:33.395Z","avatar_url":"https://github.com/ArtoriasCode.png","language":"Go","readme":"# jwtgo\n\nA Go (Golang) backend clean architecture project with Gin, MongoDB and JWT Authentication middleware.\n\nThe project was created for educational purposes and is not ideal. It has its shortcomings, which are gradually being corrected.\n\n## Project architecture\nThe architecture of a web application consists of these layers:\n- Reverse Proxy\n- API Gateway\n- Microservice\n- Database\n\nThe architecture of the microservice application consists of these layers:\n- Server\n- Service\n- Repository\n\n![Image](https://raw.githubusercontent.com/Astagnar/jwtgo/refs/heads/main/assets/architecture.png)\n\nThe API is accessed via Reverse Proxy, in our case it is Nginx. It handles all incoming requests and prevents access to microservices and API gateway directly.\n\n## Major packages used in project\n- **[Gin](https://pkg.go.dev/github.com/gin-gonic/gin)**: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin. \n- **[gRPC](https://pkg.go.dev/google.golang.org/grpc)**: The Go implementation of gRPC: A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the Go gRPC docs, or jump directly into the quick start. \n- **[protobuf](https://pkg.go.dev/google.golang.org/protobuf)**: Go support for Google's protocol buffers.\n- **[MongoDB](https://pkg.go.dev/go.mongodb.org/mongo-driver)**: The Official Golang driver for MongoDB.\n- **[JWT](https://pkg.go.dev/github.com/golang-jwt/jwt/v5)**: Go implementation of JSON Web Tokens (JWT).\n- **[Cleanenv](https://pkg.go.dev/github.com/ilyakaznacheev/cleanenv)**: Clean and minimalistic environment configuration reader for Golang.\n- **[Bcrypt](https://pkg.go.dev/golang.org/x/crypto/bcrypt)**: Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm.\n- **[Logrus](https://pkg.go.dev/github.com/sirupsen/logrus)**: Structured, pluggable logging for Go.\n- **[Validator](https://pkg.go.dev/github.com/go-playground/validator/v10)**: Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving.\n\n## Request flow without JWT authentication middleware\n![Image](https://raw.githubusercontent.com/Astagnar/jwtgo/refs/heads/main/assets/without-jwt.png)\n\n## Request flow with JWT authentication middleware\n![Image](https://raw.githubusercontent.com/Astagnar/jwtgo/refs/heads/main/assets/with-jwt.png)\n\n## How to run the project?\nFirst, download it and navigate to the root directory:\n```bash\n# Move to your workspace\ncd your-workspace\n\n# Clone the project into your workspace\ngit clone https://github.com/Astagnar/jwtgo.git\n\n# Move to the project root directory\ncd jwtgo\n```\n\n### Run with Docker\n- Create a `.env` file, similar to `.env.sample`.\n- Install the [Docker](https://www.docker.com/get-started/), [Protoc](https://grpc.io/docs/protoc-installation/), [Taskfile](https://taskfile.dev/installation/) if it is not installed on your computer.\n- Fill in the `.env` file with your data.\n- Run the application build with the following command:\n\n  ```bash\n  task build\n  ```\n- Access API using http://localhost.\n\n## Examples of API requests and responses\n### SignUp endpoint\n- Request:\n  ```\n  curl --location 'http://localhost/auth/signup' \\\n  --header 'Content-Type: application/json' \\\n  --data-raw '{\n    \"email\": \"test@gmail.com\",\n    \"password\": \"securepassword\"\n  }'\n  ```\n  \n- Response:\n  ```\n  HTTP/1.1 200 OK\n  Content-Type: application/json\n  ```\n  ```json\n  {\n    \"message\": \"User successfully registered\"\n  }\n  ```\n\n### SignIn endpoint\n- Request:\n  ```\n  curl --location 'http://localhost/auth/signin' \\\n  --header 'Content-Type: application/json' \\\n  --data-raw '{\n    \"email\": \"test@gmail.com\",\n    \"password\": \"securepassword\"\n  }'\n  ```\n\n- Response:\n  ```\n  HTTP/1.1 200 OK\n  Content-Type: application/json\n  Set-Cookie: access_token=access_token; Path=/; HttpOnly; SameSite=Strict\n  Set-Cookie: refresh_token=refresh_token; Path=/; HttpOnly; SameSite=Strict\n  ```\n  ```json\n  {\n    \"message\": \"User successfully logged in\"\n  }\n  ```\n\n### SignOut endpoint\n- Request:\n  ```\n  curl --location 'http://localhost/auth/signout' \\\n  --header 'Content-Type: application/json' \\\n  -b 'access_token=access_token; refresh_token=refresh_token'\n  ```\n\n- Response:\n  ```\n  HTTP/1.1 200 OK\n  Content-Type: application/json\n  Set-Cookie: access_token=access_token; Path=/; HttpOnly; SameSite=Strict\n  Set-Cookie: refresh_token=refresh_token; Path=/; HttpOnly; SameSite=Strict\n  ```\n  ```json\n  {\n    \"message\": \"User successfully logged out\"\n  }\n  ```\n\n### Refresh endpoint\n- Request:\n  ```\n  curl --location 'http://localhost/auth/refresh' \\\n  --header 'Content-Type: application/json' \\\n  -b 'access_token=access_token; refresh_token=refresh_token'\n  ```\n\n- Response:\n  ```\n  HTTP/1.1 200 OK\n  Content-Type: application/json\n  Set-Cookie: access_token=access_token; Path=/; HttpOnly; SameSite=Strict\n  Set-Cookie: refresh_token=refresh_token; Path=/; HttpOnly; SameSite=Strict\n  ```\n  ```json\n  {\n    \"message\": \"Tokens successfully updated\"\n  }\n  ```\n\n## Complete project folder structure\n```\n├── build\n│   └── package\n│       ├── api.Dockerfile\n│       ├── auth.Dockerfile\n│       └── user.Dockerfile\n├── cmd\n│   ├── api\n│   │   └── main.go\n│   ├── auth\n│   │   └── main.go\n│   └── user\n│       └── main.go\n├── configs\n│   └── nginx.conf\n├── deployments\n│   └── docker-compose.yaml\n├── internal\n│   ├── app\n│   │   ├── api\n│   │   │   ├── config\n│   │   │   │   └── config.go\n│   │   │   ├── controller\n│   │   │   │   └── http\n│   │   │   │       ├── dto\n│   │   │   │       │   └── user.go\n│   │   │   │       ├── mapper\n│   │   │   │       │   └── user.go\n│   │   │   │       ├── middleware\n│   │   │   │       │   ├── security.go\n│   │   │   │       │   └── validation.go\n│   │   │   │       └── v1\n│   │   │   │           └── auth.go\n│   │   │   └── main.go\n│   │   ├── auth\n│   │   │   ├── config\n│   │   │   │   └── config.go\n│   │   │   ├── interface\n│   │   │   │   └── service\n│   │   │   │       └── auth.go\n│   │   │   ├── server\n│   │   │   │   └── grpc\n│   │   │   │       ├── dto\n│   │   │   │       │   └── user.go\n│   │   │   │       ├── mapper\n│   │   │   │       │   └── user.go\n│   │   │   │       └── v1\n│   │   │   │           └── auth.go\n│   │   │   ├── service\n│   │   │   │   └── auth.go\n│   │   │   └── main.go\n│   │   └── user\n│   │       ├── adapter\n│   │       │   └── mongodb\n│   │       │       ├── entity\n│   │       │       │   └── user.go\n│   │       │       ├── mapper\n│   │       │       │   └── user.go\n│   │       │       └── repository\n│   │       │           └── user.go\n│   │       ├── config\n│   │       │   └── config.go\n│   │       ├── entity\n│   │       │   └── user.go\n│   │       ├── interface\n│   │       │   ├── repository\n│   │       │   │   └── user.go\n│   │       │   └── service\n│   │       │       └── user.go\n│   │       ├── server\n│   │       │   └── grpc\n│   │       │       ├── dto\n│   │       │       │   └── user.go\n│   │       │       ├── mapper\n│   │       │       │   └── user.go\n│   │       │       └── v1\n│   │       │           └── user.go\n│   │       ├── service\n│   │       │   └── user.go\n│   │       └── main.go\n│   └── pkg\n│       ├── error\n│       │   ├── auth.go\n│       │   ├── jwt.go\n│       │   ├── repository.go\n│       │   └── server.go\n│       ├── interface\n│       │   └── service\n│       │       ├── jwt.go\n│       │       └── password.go\n│       ├── proto\n│       │   ├── auth\n│       │   │   ├── auth.pb.go\n│       │   │   └── auth_grpc.pb.go\n│       │   └── user\n│       │       ├── user.pb.go\n│       │       └── user_grpc.pb.go\n│       ├── request\n│       │   ├── schema\n│       │   │   └── response.go\n│       │   └── response.go\n│       └── service\n│           ├── schema\n│           │   └── jwt.go\n│           ├── jwt.go\n│           └── password.go\n├── pkg\n│   ├── client\n│   │   └── mongodb.go\n│   ├── logging\n│   │   └── logger.go\n│   └── proto\n│       ├── auth\n│       │   └── auth.proto\n│       └── user\n│           └── user.proto\n├── .env\n├── .gitignore\n├── go.mod\n├── go.sum\n├── LICENSE\n├── README.md\n└── taskfile.yaml\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartoriascode%2Fjwtgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartoriascode%2Fjwtgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartoriascode%2Fjwtgo/lists"}