Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature / Module (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
- [ ] Documentation update

## Checklist:
- [ ] I have read the [Contribution Guidelines](CONTRIBUTING.md).
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# add the gitgnore files here

.venv/

# Sprint planning (local / team use)
documents/sprints/
149 changes: 149 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts.
# this is typically a path given in POSIX (e.g. forward slashes)
# format, relative to the token %(here)s which refers to the location of this
# ini file
script_location = %(here)s/migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
# Or organize into date-based subdirectories (requires recursive_version_locations = true)
# file_template = %%(year)d/%%(month).2d/%%(day).2d_%%(hour).2d%%(minute).2d_%%(second).2d_%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory. for multiple paths, the path separator
# is defined by "path_separator" below.
prepend_sys_path = .


# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the tzdata library which can be installed by adding
# `alembic[tz]` to the pip requirements.
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to <script_location>/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "path_separator"
# below.
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions

# path_separator; This indicates what character is used to split lists of file
# paths, including version_locations and prepend_sys_path within configparser
# files such as alembic.ini.
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
# to provide os-dependent path splitting.
#
# Note that in order to support legacy alembic.ini files, this default does NOT
# take place if path_separator is not present in alembic.ini. If this
# option is omitted entirely, fallback logic is as follows:
#
# 1. Parsing of the version_locations option falls back to using the legacy
# "version_path_separator" key, which if absent then falls back to the legacy
# behavior of splitting on spaces and/or commas.
# 2. Parsing of the prepend_sys_path option falls back to the legacy
# behavior of splitting on spaces, commas, or colons.
#
# Valid values for path_separator are:
#
# path_separator = :
# path_separator = ;
# path_separator = space
# path_separator = newline
#
# Use os.pathsep. Default configuration used for new projects.
path_separator = os

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

# database URL. This is consumed by the user-maintained env.py script only.
# other means of configuring database URLs may be customized within the env.py
# file.
sqlalchemy.url = postgresql://postgres:jgLiCYBjKkL7H8OG@db.pcqgvueodyxnvilfelmn.supabase.co:5432/postgres


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
# hooks = ruff
# ruff.type = module
# ruff.module = ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME

# Alternatively, use the exec runner to execute a binary found on your PATH
# hooks = ruff
# ruff.type = exec
# ruff.executable = ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME

# Logging configuration. This is also consumed by the user-maintained
# env.py script only.
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
qualname =

[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
207 changes: 207 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# BookMyVenue — Backend

FastAPI backend for BookMyVenue. This folder holds the API server that powers venue discovery, bookings, and admin workflows.

See the full architecture reference: [`documents/FolderArchitecture.md`](../documents/FolderArchitecture.md)

---

## Prerequisites

- Python 3.11+ (recommended)
- PostgreSQL
- Git

---

## 1. Create the backend project

From the repository root:

```bash
cd backend
```

Scaffold the **modular monolithic** layout below. One deployable app, organized by feature modules — not microservices.

```bash
backend/
├── app/
│ ├── main.py # FastAPI entry point — register routes here
│ ├── core/
│ │ ├── config.py # Settings loaded from .env
│ │ └── security.py # JWT, password hashing
│ ├── db/
│ │ ├── session.py # Database session / engine
│ │ └── base.py # SQLAlchemy declarative base
│ ├── modules/ # Feature-based modules (one folder per domain)
│ │ ├── auth/
│ │ │ ├── routes.py # HTTP handlers only
│ │ │ ├── schemas.py # Pydantic request/response models
│ │ │ ├── service.py # Business logic
│ │ │ └── models.py # SQLAlchemy tables
│ │ ├── users/
│ │ ├── venues/
│ │ ├── bookings/
│ │ └── admin/
│ └── utils/
│ └── helpers.py
├── migrations/ # Alembic migrations
├── tests/
├── .env # Local secrets (never commit)
├── .env.example # Template for contributors
├── requirements.txt
└── README.md
```

### Modular monolithic rules

| Layer | Responsibility |
|-------|----------------|
| `routes.py` | Accept requests, return responses. No business logic. |
| `service.py` | All business rules and orchestration. |
| `models.py` | Database tables (SQLAlchemy). |
| `schemas.py` | Input/output validation (Pydantic). |
| `core/` | App-wide config, security, shared settings. |
| `db/` | Database connection setup only. |

**Do not** put logic in `main.py` or route handlers. **Do not** access the database directly from routes — go through services.

Request flow:

```text
Client → routes.py → service.py → database → response
```

---

## 2. Create a virtual environment

```bash
python3 -m venv .venv
```

Activate it:

**macOS / Linux**

```bash
source .venv/bin/activate
```

**Windows**

```bash
.venv\Scripts\activate
```

Your shell prompt should show `(.venv)` when active.

---

## 3. Install dependencies

Create a `requirements.txt` with at least:

```txt
fastapi
uvicorn[standard]
sqlalchemy
psycopg2-binary
python-dotenv
pydantic-settings
python-jose[cryptography]
passlib[bcrypt]
alembic
```

Install:

```bash
pip install -r requirements.txt
```

To save your current environment after adding packages:

```bash
pip freeze > requirements.txt
```

---

## 4. Environment variables (`.env`)

Copy the example file and fill in your local values:

```bash
cp .env.example .env
```

Example `.env.example`:

```env
# App
APP_NAME=BookMyVenue
APP_ENV=development
DEBUG=true

# Server
HOST=0.0.0.0
PORT=8000

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/bookmyvenue

# Security
SECRET_KEY=change-me-to-a-long-random-string
ACCESS_TOKEN_EXPIRE_MINUTES=30
ALGORITHM=HS256

# CORS (frontend URL)
CORS_ORIGINS=http://localhost:5173,http://localhost:3000
```

Load these in `app/core/config.py` using `pydantic-settings` or `python-dotenv`. **Never commit `.env`** — it is listed in `.gitignore`.

---

## 5. Run the development server

```bash
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```

- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- OpenAPI schema: http://localhost:8000/openapi.json

---

## 6. Database migrations (Alembic)

From the `backend/` directory:

```bash
alembic revision --autogenerate -m "describe your change"
alembic upgrade head
```

---

## Adding a new feature module

1. Create a folder under `app/modules/<feature>/`.
2. Add `routes.py`, `schemas.py`, `service.py`, and `models.py`.
3. Register the router in `app/main.py`.
4. Add a migration if the module introduces new tables.

Keep each module self-contained. Shared code belongs in `core/`, `db/`, or `utils/` — not copied across modules.

---

## Related docs

- [System Design](../documents/SystemDesign.md)
- [Folder Architecture](../documents/FolderArchitecture.md)
- [Database Design](../documents/DBDesign.md)
- [Contributing](../CONTRIBUTING.md)
Loading