Here’s an updated README.md for your project that includes the project structure and how to run it:
# Greenhouse App
This project is a FastAPI-based application for managing job listings, with full CRUD operations. It uses SQLAlchemy for ORM with SQLite as the database.
## Project Structure
greenhouse/ ├── app/ │ ├── core/ │ │ ├── jobs/ │ │ │ ├── create_job.py │ │ │ ├── interfaces.py │ │ │ ├── list_jobs.py │ │ │ ├── models.py │ │ │ ├── repository.py │ │ ├── ... │ ├── infrastructure/ │ │ ├── api/ │ │ │ ├── jobs_controller.py │ │ ├── db/ │ │ │ ├── models.py │ │ │ ├── database.py │ │ │ ├── repository.py │ │ ├── ... │ ├── schemas/ │ │ ├── job_schemas.py │ ├── main.py ├── requirements.txt ├── Dockerfile ├── docker-compose.yml ├── seed_data.json ├── .gitignore
- `core/`: Contains business logic, repository patterns, and services (e.g., `create_job.py` and `list_jobs.py`).
- `infrastructure/`: Contains infrastructure-level code such as database models, database access logic, and API controllers.
- `schemas/`: Contains Pydantic models for validating request/response data for job APIs.
- `main.py`: The entry point of the application, where the FastAPI instance is created and the routers are included.
- `Dockerfile`: The Dockerfile used for building the Docker image for the app.
- `docker-compose.yml`: Docker Compose configuration to run the application and database in containers.
- `seed_data.json`: A JSON file for seeding initial data into the database.
## Installation and Setup
### Prerequisites
Ensure you have the following installed:
- Python 3.9 or higher
- Docker and Docker Compose (for containerization)
- Git (for version control)
### 1. Clone the repository
```bash
git clone https://github.com/yourusername/greenhouse-app.git
cd greenhouse-app
pip install -r requirements.txtAlternatively, you can use Docker to build and run the app in a containerized environment (recommended for consistency):
docker-compose buildTo run the application locally using Uvicorn:
uvicorn app.main:app --reloadThis will start the FastAPI application on http://localhost:8000.
If you prefer to run the app in Docker containers, you can use the following command:
docker-compose upThis will start both the FastAPI app and the database in containers. The app will be available at http://localhost:8000.
If you want to populate the database with some initial data (e.g., sample job listings), you can run the seed_data.py script:
python seed_data.pyThis will insert predefined job listings into the database.
You can test the APIs by navigating to http://localhost:8000/docs, where you will find an auto-generated Swagger UI that allows you to test all the available endpoints.
-
POST /api/v1/jobs: Create a new job listing.
- Request body:
{ "name": "Software Engineer", "department_id": "1", "status": "open", "employment_type": "full_time", "description": "Develop software applications.", "requirements": "Experience with Python, FastAPI, SQLAlchemy." } -
GET /api/v1/jobs: Retrieve a list of jobs, optionally filtered by name or status.
- Example query:
http://localhost:8000/api/v1/jobs?name=Software%20Engineer&status=open&page=1&per_page=10
- Example query:
To run the tests, you can use pytest:
pytestThe Dockerfile and Docker Compose file are already set up to containerize your application.
To build and run the app in a Docker container, run:
docker-compose up --buildThis will build the Docker image and start the app and database containers.
- Your Name
- Additional Contributors (if any)
This project is licensed under the MIT License - see the LICENSE file for details.
This `README.md` provides clear instructions on how to set up, run, and test the project, as well as an overview of the project structure. It also includes Docker setup instructions for containerization.