- Created .env-example for environment variable setup - Updated README to reflect changes in .env file creation - Modified config.py to include new environment variables and DATABASE_URL property - Enhanced database.py with connect and disconnect functions - Updated main.py to manage database connection lifecycle - Adjusted compose.yaml for consistent environment variable usage
75 lines
1.9 KiB
Markdown
75 lines
1.9 KiB
Markdown
# Project Name
|
|
|
|
Short one-line description of what this project does.
|
|
|
|
## Tech Stack
|
|
|
|
- **[FastAPI](https://fastapi.tiangolo.com/)** — Python REST API framework
|
|
- **[PostgreSQL](https://www.postgresql.org/)** — Relational database
|
|
- **[SQLAlchemy](https://www.sqlalchemy.org/)** — Async database connection layer
|
|
- **[Docker](https://www.docker.com/) / Docker Compose** — Containerized development environment
|
|
|
|
## Project Structure
|
|
```
|
|
project/
|
|
├──Create.sql — Database schema and seed data
|
|
├──docker-compose.yml
|
|
├──Dockerfile
|
|
├──requirements.txt
|
|
├──.env — Local environment variables (not committed)
|
|
└──app/
|
|
├── main.py — App entry point, router registration
|
|
├── config.py — Environment variable configuration
|
|
├── database.py — Database connection and session
|
|
└── routers/
|
|
├── init.py
|
|
└── example.py — Route definitions
|
|
```
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- [Docker](https://docs.docker.com/get-docker/) installed
|
|
- [Docker Compose](https://docs.docker.com/compose/) installed
|
|
|
|
### Setup
|
|
|
|
Create a .env file, by copying .env-example, in the root directory and adjustign the vaulues as needed:
|
|
|
|
```text
|
|
POSTGRES_USER=exampleUser
|
|
POSTGRES_PASSWORD=examplePasswd
|
|
POSTGRES_DB=exampleDB
|
|
API_PORT=8000
|
|
DEBUG=true
|
|
```
|
|
|
|
Start the stack:
|
|
|
|
```bash
|
|
docker compose up --build
|
|
```
|
|
|
|
The API will be available at http://localhost:8000.
|
|
Interactive API docs are at http://localhost:8000/docs.
|
|
Resetting the Database
|
|
|
|
If you need to reinitialize the database (e.g. after changing Create.sql):
|
|
|
|
```bash
|
|
docker compose down
|
|
rm -rf ./postgresData
|
|
docker compose up --build
|
|
```
|
|
|
|
⚠️ This will delete all data.
|
|
Do not run in production.
|
|
|
|
```Notes
|
|
|
|
The database schema is managed via Create.sql — no ORM migrations
|
|
|
|
The .env file is excluded from version control via .gitignore
|
|
```
|