{"id":18963418,"url":"https://github.com/pashamakhilkumarreddy/fastapi-mongodb","last_synced_at":"2026-04-07T09:32:19.764Z","repository":{"id":114635210,"uuid":"350292855","full_name":"pashamakhilkumarreddy/fastapi-mongodb","owner":"pashamakhilkumarreddy","description":"This is a RESTful API built using Python and FastAPI. The application leverages Docker for containerization, MongoDB as the database, poetry for managing Python versions, and Swagger for API documentation and testing.","archived":false,"fork":false,"pushed_at":"2024-06-17T17:16:59.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-02T06:35:33.149Z","etag":null,"topics":["commitlint","docker","docker-compose","fastapi","makefile","nginx","pre-commit","python","uvicorn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pashamakhilkumarreddy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2021-03-22T10:01:20.000Z","updated_at":"2024-06-17T17:17:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"46b001c2-460a-42c0-9a6f-0c2833450cfb","html_url":"https://github.com/pashamakhilkumarreddy/fastapi-mongodb","commit_stats":null,"previous_names":["pashamakhilkumarreddy/fastapi-mongodb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pashamakhilkumarreddy/fastapi-mongodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pashamakhilkumarreddy%2Ffastapi-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pashamakhilkumarreddy%2Ffastapi-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pashamakhilkumarreddy%2Ffastapi-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pashamakhilkumarreddy%2Ffastapi-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pashamakhilkumarreddy","download_url":"https://codeload.github.com/pashamakhilkumarreddy/fastapi-mongodb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pashamakhilkumarreddy%2Ffastapi-mongodb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31508048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["commitlint","docker","docker-compose","fastapi","makefile","nginx","pre-commit","python","uvicorn"],"created_at":"2024-11-08T14:19:18.341Z","updated_at":"2026-04-07T09:32:19.735Z","avatar_url":"https://github.com/pashamakhilkumarreddy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI MongoDB\n\nThis is a RESTful API built using Python and FastAPI. The application leverages Docker for containerization, MongoDB as the database, pyenv, poetry for managing Python versions, and Swagger for API documentation and testing.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n  - [Prerequisites](#prerequisites)\n  - [Steps](#steps)\n    - [Database](#database)\n    - [Docker](#docker)\n    - [Swagger](#swagger)\n- [Project Structure](#project-structure)\n- [Testing](#testing)\n- [Linting and Formatting](#linting-and-formatting)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Introduction\n\nThis REST API serves as a robust backend solution using FastAPI and MongoDB. It facilitates key functionalities including CRUD operations, user authentication, data validation, and seamless interaction between the FastAPI framework and MongoDB database.\n\n## Installation\n\n### Prerequisites\n\n- Python version 3.12.x (LTS)\n- MongoDB\n- [Poetry](https://python-poetry.org/)\n- Docker\n- Docker Compose\n- [Pyenv](https://github.com/pyenv/pyenv) (optional, for managing Python versions)\n\n### Steps\n\nFollow these steps to set up and run the application:\n\n1. **Clone the repository:**\n\n   ```bash\n   git clone https://github.com/pashamakhilkumarreddy/fastapi-mongodb\n   ```\n\n2. **Change into the project directory:**\n\n   ```bash\n   cd fastapi-mongodb\n   ```\n\n3. **Create and activate a virtual environment:**\n\n   ```bash\n   python -m venv venv\n   source venv/bin/activate # On Windows, use `venv\\Scripts\\activate`\n   ```\n\n   or \n\n   ```bash\n   pyenv local 3.12.4\n   poetry shell\n   ```\n\n4. **Create a `.env` file in the project root directory and add the required environment variables (see `.env.example` as a reference):**\n\n   ```bash\n   cp .env.example .env\n   ```\n\n5. **Install the dependencies:**\n\n   ```bash\n   pip install -r requirements.txt\n   ```\n   or\n\n   ```bash\n   poetry install\n   ```\n\n6. **Install pre-commit hooks:**\n\n - Install `pre-commit`: https://pre-commit.com/ (should be installed globally)\n\n - Install pre-commit hooks:\n\n   `make install-git-hooks`\n\n7. **Run the application:**\n\n   ```bash\n   uvicorn app.main:app --reload\n   ```\n\n8. For additional details, please refer to the [Makefile](Makefile) for this project. It includes various commands to manage the setup, running, and maintenance of the application.\n\n#### Database\n\nThis application uses [MongoDB](https://www.mongodb.com/) as its database. Follow these steps to set up and configure the database for the FastAPI project:\n\n- Ensure that you have MongoDB installed on your machine. You can download it from [MongoDB Downloads](https://www.mongodb.com/try/download/community).\n- Start the MongoDB server by running the following command:\n\n  ```bash\n  mongod\n  ```\n\n- Connect to MongoDB and create a new database and user for the FastAPI project. You can run these commands in the MongoDB shell (`mongo`):\n\n  ```bash\n  # Connect to MongoDB shell\n  mongo\n\n  # Switch to the new database (it will be created if it doesn't exist)\n  use fs-mongo;\n\n  # Create a new user with roles\n  db.createUser({\n    user: \"admin\",\n    pwd: \"your_password\",\n    roles: [{ role: \"readWrite\", db: \"fs-mongo\" }]\n  });\n\n  # Exit the MongoDB shell\n  exit;\n  ```\n\nThis setup will create a MongoDB database named `fs-mongo` and a user named `admin` with read and write privileges on the `fs-mongo` database.\n\n#### Docker\n\nThis project includes Docker Compose files for production and staging environments. Before using Docker, ensure you have the required environment variables set in the corresponding `.env` files (see `.env.example` as a reference).\n\nTo build and run Docker containers:\n\n1. Ensure Docker is installed and running on your system.\n\n2. **Build and run the MongoDB Docker image:**\n\n   ```bash\n   docker run -it -p 27017:27017 -d mongo\n   ```\n\n3. **Build and run the API using Docker Compose:**\n\n   ```bash\n   docker-compose up\n   ```\n\n4. **To stop and clean Docker containers, use the following command:**\n\n   ```bash\n   docker-compose down\n   ```\n\n#### Swagger\n\nAccess the Swagger UI at [Swagger API Docs](http://localhost:8000/api-docs).\n\n## Project Structure\n\n```bash\n├── .github\n├── nginx\n├── app\n│ ├── config\n│ ├── helpers\n│ ├── models\n│ ├── routes\n│ ├── schemas\n│ ├── services\n│ ├── main.py\n├── .commitlintrc.json\n├── .dockerignore\n├── .editorconfig\n├── .env\n├── .env.example\n├── .pre-commit-config.yaml\n├── .secrets.baseline\n├── CONTRIBUTING.md\n├── docker-compose.yml\n├── Dockerfile\n├── LICENSE\n├── Makefile\n├── poetry.lock\n├── pyproject.toml\n├── README.md\n├── requirements.txt\n```\n\nThis repository follows a structured organization to facilitate clarity, maintainability, and scalability. Below is an overview of the key directories and files:\n\n- `nginx`: Configuration files for NGINX, if applicable.\n- `app`: The main source code directory containing the application's codebase.\n  - `config`: Contains additional configuration files for the application.\n  - `helpers`: Helper functions and utilities.\n  - `models`: Database entities representing data models.\n  - `routes`: FastAPI route definitions.\n  - `schemas`: Pydantic schemas for data validation.\n  - `services`: Service layer for business logic.\n  - `main.py`: The entry point of the application.\n- `static`: Static files such as images, if applicable.\n- `tests`: Unit and integration tests for the application.\n- `.commitlintrc.json`: Configuration file for Commitlint.\n- `.dockerignore`: Files and directories to be ignored when building Docker images.\n- `.editorconfig`: Configuration for maintaining consistent coding styles across different editors.\n- `.env` and `.env.example`: Environment variables configuration.\n- `.gitignore`: Files and directories to be ignored by Git.\n- `.pre-commit-config.yaml`: Configuration for pre-commit hooks.\n- `CONTRIBUTING.md`: Guidelines for contributing to the project.\n- `docker-compose.yml`: Docker Compose files for production and development.\n- `Dockerfile`: Dockerfile for building Docker images.\n- `Makefile`: Contains various commands for setting up, building, and managing the project.\n- `poetry.lock`: Poetry lock file that locks the dependencies to specific versions.\n- `pyproject.toml`: Configuration file for Poetry, specifying project dependencies and metadata.\n- `README.md`: This file contains information about the project and instructions on how to use it.\n- `requirements.txt`: List of dependencies for the project, used by pip for installing the necessary packages.\n\n## Testing\n\nTo run tests, use the following command:\n\n```bash\npoetry run pytest\n```\n\n## Linting and Formatting\n\nTo run ESLint, use the following command:\n\n```bash\npoetry run blue .\n```\n\n### Pre-commit Hook\n\nLinting and formatting are enforced through the pre-commit hook using Husky and lint-staged. Make sure to address any issues reported by the hook. If you want to temporarily disable pre-commit hooks, you can use the `--no-verify` or `-n` option with your Git commit command. This option skips the pre-commit and commit-msg hooks for that specific commit.\n\n```bash\ngit commit --no-verify -m \"Your commit message\"\n```\n\n## Contributing\n\nWe welcome contributions to enhance the functionality of this API. To contribute, please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/your-feature`).\n3. Implement your changes.\n4. Test your changes thoroughly.\n5. Commit your changes (`git commit -am 'Add some feature'`).\n6. Push to the branch (`git push origin feature/your-feature`).\n7. Create a new Pull Request.\n\nFor additional contributing guidelines, see the [Contributing guide](./CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the [License Name]. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpashamakhilkumarreddy%2Ffastapi-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpashamakhilkumarreddy%2Ffastapi-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpashamakhilkumarreddy%2Ffastapi-mongodb/lists"}