└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Backend Golang Coding Test 2 | 3 | ## Objective 4 | Build a simple RESTful API in Golang that manages a list of users. Use MongoDB for persistence, JWT for authentication, and follow clean code practices. 5 | 6 | --- 7 | 8 | ## Requirements 9 | 10 | ### 1. User Model 11 | Each user should have: 12 | - `ID` (auto-generated) 13 | - `Name` (string) 14 | - `Email` (string, unique) 15 | - `Password` (hashed) 16 | - `CreatedAt` (timestamp) 17 | 18 | --- 19 | 20 | ### 2. Authentication 21 | 22 | #### Functions 23 | - Register a new user. 24 | - Authenticate user and return a JWT. 25 | 26 | #### JWT 27 | - Use JWT for protecting endpoints. 28 | - Use middleware to validate tokens. 29 | - Use HMAC (HS256) with a secret key. 30 | 31 | --- 32 | 33 | ### 3. User Functions 34 | 35 | - Create a new user. 36 | - Fetch user by ID. 37 | - List all users. 38 | - Update a user's name or email. 39 | - Delete a user. 40 | 41 | --- 42 | 43 | ### 4. MongoDB Integration 44 | - Use the official Go MongoDB driver. 45 | - Store and retrieve users from MongoDB. 46 | 47 | --- 48 | 49 | ### 5. Middleware 50 | - Logging middleware that logs HTTP method, path, and execution time. 51 | 52 | --- 53 | 54 | ### 6. Concurrency Task 55 | - Run a background goroutine every 10 seconds that logs the number of users in the DB. 56 | 57 | --- 58 | 59 | ### 7. Testing 60 | Write unit tests 61 | 62 | Use Go’s `testing` package. Mock MongoDB where possible. 63 | 64 | --- 65 | 66 | ## Bonus (Optional) 67 | 68 | - Add Docker + `docker-compose` for API + MongoDB. 69 | - Use Go interfaces to abstract MongoDB operations for testability. 70 | - Add input validation (e.g., required fields, valid email). 71 | - Implement graceful shutdown using `context.Context`. 72 | - **gRPC Version** 73 | - Create a `.proto` file for `CreateUser` and `GetUser`. 74 | - Implement a gRPC server. 75 | - (Optional) Secure gRPC with token metadata. 76 | - **Hexagonal Architecture** 77 | - Structure the project using hexagonal (ports & adapters) architecture: 78 | - Separate domain, application, and infrastructure layers. 79 | - Use interfaces for data access and external dependencies. 80 | - Keep business logic decoupled from frameworks and DB drivers. 81 | 82 | --- 83 | 84 | ## Submission Guidelines 85 | 86 | - Submit a GitHub repo or zip file. 87 | - Include a `README.md` with: 88 | - Project setup and run instructions 89 | - JWT token usage guide 90 | - Sample API requests/responses 91 | - Any assumptions or decisions made 92 | 93 | --- 94 | 95 | ## Evaluation Criteria 96 | 97 | - Code quality, structure, and readability 98 | - REST API correctness and completeness 99 | - JWT implementation and security 100 | - MongoDB usage and abstraction 101 | - Bonus: gRPC, Docker, validation, shutdown 102 | - Testing coverage and mocking 103 | - Use of idiomatic Go --------------------------------------------------------------------------------