{"id":21630525,"url":"https://github.com/mdgspace/codephile-backend","last_synced_at":"2025-04-11T14:07:20.232Z","repository":{"id":37938040,"uuid":"190446990","full_name":"mdgspace/codephile-backend","owner":"mdgspace","description":"Back-end for Official Codephile App ","archived":false,"fork":false,"pushed_at":"2023-08-12T10:59:15.000Z","size":22682,"stargazers_count":16,"open_issues_count":15,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T10:12:22.610Z","etag":null,"topics":["elasticsearch","mongodb","odyssey","rest-api"],"latest_commit_sha":null,"homepage":"https://codephile.mdg.iitr.ac.in/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdgspace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-06-05T18:23:29.000Z","updated_at":"2023-05-17T14:23:06.000Z","dependencies_parsed_at":"2024-11-25T02:21:27.493Z","dependency_job_id":null,"html_url":"https://github.com/mdgspace/codephile-backend","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdgspace%2Fcodephile-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdgspace%2Fcodephile-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdgspace%2Fcodephile-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdgspace%2Fcodephile-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdgspace","download_url":"https://codeload.github.com/mdgspace/codephile-backend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248413072,"owners_count":21099252,"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":["elasticsearch","mongodb","odyssey","rest-api"],"created_at":"2024-11-25T02:11:19.726Z","updated_at":"2025-04-11T14:07:20.213Z","avatar_url":"https://github.com/mdgspace.png","language":"Go","readme":"# Codephile | [![CircleCI](https://circleci.com/gh/mdg-iitr/Codephile.svg?style=svg\u0026circle-token=f989c04ad5d3a6578d45296b18cdca223e504bde)](https://circleci.com/gh/mdg-iitr/Codephile)\n## Services\nWe use the following services in our server,\n\n* MongoDB: Main database of the server, stores user info, submission, profile,etc. Install from [here](https://docs.mongodb.com/manual/installation/)\n* Redis: Used to logout and blacklist users. Serves as cache for contests API. Download from [here](https://redis.io/download)\n* Firebase storage: The profile pictures are stored in firebase storage. Create a firebase account.\n\n## Environment Variables\n\nEnvironment variable is a way to store/pass some sensitive/config information that is required by the software. This can include passwords, secret keys, config variables.\n\nTo setup environment variables, create a `.env` file at conf directory of project containing following information:\n```\nENVIRONMENT=\u003cdev/prod\u003e\nPORT=\u003cThe port to be used: optional\u003e\nDBPath=\u003cConnection string of local database\u003e\nHMACKEY=\u003cHMAC Encryption key\u003e\nREDISURL=\u003cconnection string of redis server\u003e\nFIREBASE_CONFIG=\u003cFirebase config including bucket name(json)\u003e\nFIREBASE_CREDENTIALS=\u003cFirebase admin SDK credentials(json)\u003e\nSENTRY_DSN=\u003cData source name of sentry server: optional\u003e\nEMAIL_CLIENT_SECRET=\u003cClient secret of google client\u003e\nEMAIL_CLIENT_ID=\u003cClient ID of google client\u003e\nEMAIL_REFRESH_TOKEN=\u003cRefresh token of above client have these scopes: send, compose, mail.google.com\u003e\n```\nNOTE: Before proceeding further, ensure that your local .env file is present with above configuration variables.\n\nAsk for codechef creds from the maintainer\n```\nCLIENT_ID=\u003ccodechef id\u003e\nCLIENT_SECRET=\u003ccodechef secret\u003e\n```\n\n## Setup Instructions\n\nDownload golang from [here](https://golang.org/dl/) and setup GOPATH\n\nIn order to ensure the GOPATH environment variable is setup run: \n```shell script\n$ echo $GOPATH\n```\nThis should give non empty output\n\nNow clone the repo in the appropriate directory.\n```shell script\n$ mkdir -p $GOPATH/src/github.com/mdg-iitr/Codephile \u0026\u0026 cd $_ \n$ git clone https://github.com/mdg-iitr/Codephile.git\n```\nNow install the following services - [redis](https://redis.io/topics/quickstart) and [mongodb](https://docs.mongodb.com/guides/server/install/) to run the project locally. Use these env variables in the .env file:\n```\nREDISURL=redis://redis:6379\nDBPath=mongodb://mongoadmin:secret@mongo:27017/admin\n```\n\nWe used beego framework to bootstrap the project. Download and setup bee command line program from [here](https://beego.vip/docs/quickstart/).\n\n\nIn order to generate documentation from comments, run:\n```shell script\n$ bee run -downdoc=true -gendoc=true\n```\nIf you didn't make any changes in documentation comment, simply run:\n```shell script\n$ bee run\n```\nCustom programs could be run using\n```shell script\n$ go run cmd/\u003cpath to main package go file\u003e\n```\nE.g.\n```shell script\n $ go run cmd/blacklist-user/blacklist_user.go\n```\n\nNote: During commiting changes, always run `go mod vendor` if there are any changes in 3rd party dependency.\n\n## Setup using docker\nYou can use the `dev_docker-compose.yml` file to spin up containers with Mongo \u0026 Redis services easily.\nUse these env variables\n```\nREDISURL=redis://redis:6379\nDBPath=mongodb://mongoadmin:secret@mongo:27017/admin\n```\nAnd run this command\n```shell script\n$ docker-compose -f dev_docker-compose.yml up\n```\n## Accessing the APIs\n- Navigate to https://localhost/docs to access and test all the Codephile APIs. - Before testing, create a new user using the signup API, login and unlock the other APIs.\n\n- In order to test the gmail APIs: \n   - Navigate to https://console.cloud.google.com and select APIs and Services -\u003e Credentials.\n   - Click on Create Credentials -\u003e OAuth Client IDs and fill in the following details - \n     - Application Type: Web Application\n     - Application Name: Codephile\n     - Authorized JavaScript origins: \n        - https://codephile-dummy.firebaseapp.com\n        - http://localhost\n        - http://localhost:5000\n        - https://codephile.mdg.iitr.ac.in\n     - Authorized redirect URIs:\n        - https://developers.google.com/oauthplayground\n   - Click on `Create Credentials` button and copy the client ID and Client Secret generated. Add them to your .env file.\n   - Navigate to [Google OAuth Playground](https://developers.google.com/oauthplayground) and select the  [mail.google.com](https://mail.google.com/), [send](https://www.googleapis.com/auth/gmail.send), [modify](https://www.googleapis.com/auth/gmail.modify) APIs under Gmail API.\n   - Click `Authorize APIs` and after getting an Authorization code select `Exchange authorization code for tokens` Copy the refresh token and add it to your .env file.\n   - Now you may test sending and recieving mails with the API!\n\nNote: If the `DBPath` in the `.env` file is of a local database, the API `/user/search` will not work, as it uses [MongoDB Atlas Search](https://www.mongodb.com/docs/atlas/atlas-search/) which needs a [MongoDB Atlas cloud Database](https://www.mongodb.com/atlas/database).\n\n \n\n## Tests\n\nChange the `DBPath` in .env file \n\nRun the tests\n```shell script\n$ go test -mod=vendor -v ./tests\n```\n\n## Components\n\n* `cmd`: Contains standalone programs for specific tasks like updating user submissions, deleting, blacklist users.\n\n* `conf`: Contains global app level constants and configuration files. This package has to be imported first in the main package, as it loads various global variables and inits various clients(sentry).\n\n* `controller`:  Responsible for handling the requests corresponding to various endpoints. Contains separate files for separate namespaces.\n\n* `errors`: Contains custom error messages and json response structs to respond with, in case of errors.\n\n* `middleware`: Sits before controllers. Mainly authenticates user and extracts uid from user token\n\n* `models`:\n    * `models/db`: Handles db connection and manages connection pool. Provides a clean interface to establish db connections.\n    * `models/types`: Contains the types for various database schema and response models.\n    * `/`: Contains database operations, queries.\n    \n* `routers`: Registers endpoints. Beego generates the routes from comments inside controllers. See [this](https://beego.me/docs/mvc/controller/router.md#annotations) for more information.\n\n* `scrappers`: Contains the main logic for scrapping user data(submission, profile) from platforms. Each platform's logic is contained in packages with the platform name and a simple interface to scrappers is exposed through `interface.go` \n\n* `services`: Creates and exposes the clients for various services like redis. Also contains code for worker routines that are activated on request to POST `/user/submission`\n\n* `swagger`: Contains the static files and `swagger.json` and `swagger.yml` for API documentation. Documentation could be generated using bee command line tool `bee run -downdoc=true -gendoc=true`\n\n* `test`: Will contain tests for various endpoints and unit tests. Currently, only test for `/user/all` is present. Run the tests using \n`go test  ./tests/...` \n\nBeginners are advised to begin with writing some tests.\n\n## CI\n\nWhen a pull request is submitted, continuous integration jobs are run automatically to ensure the code builds and is relatively well-written. The jobs are run on circleci.\nAt present, the build, tests and linters are run on CI.\n\nWe use [golang-ci](https://github.com/golangci/golangci-lint) lint for linting jobs. Download and run the linter locally before submitting a PR.\n\n## 💬 For commit messages\n\nPlease start your commits with these prefixes for better understanding among collaborators, based on the type of commit:\n\n    feat: (addition of a new feature)\n    rfac: (refactoring the code: optimization/ different logic of existing code - output doesn't change, just the way of execution changes)\n    docs: (documenting the code, be it readme, or extra comments)\n    bfix: (bug fixing)\n    chor: (chore - beautifying code, indents, spaces, camelcasing, changing variable names to have an appropriate meaning)\n    ptch: (patches - small changes in code, mainly UI, for example color of a button, increasing size of tet, etc etc)\n    conf: (configurational settings - changing directory structure, updating gitignore, add libraries, changing manifest etc)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdgspace%2Fcodephile-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdgspace%2Fcodephile-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdgspace%2Fcodephile-backend/lists"}