My submission for Inter IIT Dev
- Language: Go
- Framework: Echo
- ORM: GORM
- Authentication: JWT
- Postgresql
- Framework: Svelte
- Runtime: Bun
- Build Tool: Vite
- Nginx: Route traffic to frontend and backend services
- Docker
- Amazon ec2 instance with docker Containerization and nginx reverse Proxy
- visit http://16.16.128.235
git clone https://github.com/saksham-kumar-14/Repliq
cd ./Repliq- Create
./backend/.envaccording to./backend/.env.exampleprovided
docker-compose up --build- The website will run on
http://localhost - Backend service will run on
http://localhost:8000
git clone https://github.com/saksham-kumar-14/repliqcd ./backend
go mod tidy
go run ./cmd/api/*.goIn another terminal,
cd ./frontend
bun install
bun run dev- The website will run on
http://localhost:5173 - Backend service will run on
http://localhost:8000
- Features
- API routes for communication
- Rate limiter: server protection by limiting request frequency per IP
- Dockerfile for Go server setup
- Api Routes
GET /v1/health: basic check for server healthGET /v1/user/:id: get specific user informationPOST /v1/user: user registrationPOST /v1/user/login: user loginGET /v1/api/token: JWT verification
** The following routes use JWT middleware for user verification.
- API request must contain
headers:{Authorization: "Bearer <jwt-token>"}
GET /v1/post: get all postsPOST /v1/post: create postGET /v1/post/:id: get specific postPATCH /v1/post/:id: update specific postDELETE /v1/post/:id: delete specific post
- Features
/:- Displays Login/Registration if not loggedin
- Else displays posts.
- Sorting comments by Oldest, Newest, Upvotes
- Collapsable Replies
- Notifications
- Avatar for users
├── backend/
├── cmd/
├── api/
├── api.go # for api and server config
├── main.go # main file to run
├── errors.go # api resp errors are defined
├── json.go # for writing json responses and reading json requests
├── middleware.go # for JWT auth
├── user.go # user api functions
├── comment.go # posts api functions
└── health.go # api function for basic health check
├── internal/
├── auth/ # JWT auth
├── db/ # initialize db
├── rateLimiter/ # rate limiting
└── store/ # db store for user and comments
└── Dockerfile
├── frontend/
│ ├── src/
│ │ ├── lib/ # Svelte components
│ │ ├── store/ # API service functions
│ │ ├── utils/ # util functions
│ │ └── App.svelte
├── nginx
| ├── Dockerfile # This first builds svelte frontend, then host it with nginx on PORT 80
| ├── nginx.conf # configuration for nginx
├── docker-compose.yml
└── README.md
type User struct {
ID uint `json:"id" gorm:"primaryKey"`
Username string `json:"username" gorm:"uniqueIndex"`
Avatar string `json:"avatar"`
Email string `json:"email" gorm:"uniqueIndex"`
Password []byte `json:"-"`
CreatedAt time.Time `json:"created_at"`
}
type Comment struct {
ID uint `json:"id" gorm:"primaryKey"`
ParentId int `json:"parent_id"`
Text string `json:"text"`
Upvotes int `json:"upvotes"`
UserId uint `json:"user_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}