Sign inSign up

h4mid2019/flask-react-backend

By h4mid2019

•Updated 3 months ago

Simple file management API built with Flask and PostgreSQL.

Image
0

2.4K

h4mid2019/flask-react-backend repository overview

⁠Backend Overview

Simple file management API built with Flask and PostgreSQL.

⁠What it does

The backend handles file operations like creating folders, uploading files, and managing permissions. It runs as separate services for better performance.

⁠Services

The backend splits into 4 services:

  • READ services (2x) - Handle GET requests, load balanced
  • WRITE service (1x) - Handle POST requests (uploads, creates)
  • OPERATIONS service (1x) - Handle PUT/DELETE requests (rename, delete)

All services share the same database. Nginx routes requests by HTTP method.

⁠Key files

apps/backend/
├── app_factory.py       # Creates Flask apps
├── routes_read.py       # GET endpoints
├── routes_write.py      # POST endpoints
├── routes_operations.py # PUT/DELETE endpoints
├── models.py            # Database tables
├── run_bjoern.py        # Production server
├── start_local.py       # Development server
└── tests/               # Unit tests

⁠Database

Uses SQLAlchemy with these tables:

  • users - User accounts (Auth0 integration)
  • filesystem_items - Files and folders
  • file_permissions - Who can access what

Key features:

  • Each user has isolated file system
  • Folders can contain other folders (parent/child)
  • Deleting folder removes everything inside
  • No duplicate names in same folder

⁠API endpoints

File operations:

  • GET /api/filesystem - List files in folder
  • POST /api/filesystem - Create new folder
  • GET /api/filesystem/{id} - Get file details
  • PUT /api/filesystem/{id} - Rename file/folder
  • DELETE /api/filesystem/{id} - Delete file/folder
  • POST /api/filesystem/upload - Upload file
  • GET /api/filesystem/{id}/download - Download file

System:

  • GET /api/health - Check if service is running

⁠Authentication

Uses Auth0 JWT tokens. Set TEST_MODE=true to skip auth during development.

⁠Environment setup

Create apps/backend/.env:

DATABASE_URL=postgresql://user:pass@localhost:5432/flask_react_db
SECRET_KEY=your-secret-key
AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_AUDIENCE=your-api-identifier
TEST_MODE=false

⁠Development

Start local server:

cd apps/backend
python start_local.py

Run tests:

cd apps/backend
pytest tests/ -v

Database migrations:

cd apps/backend
flask db upgrade

⁠Production

Uses bjoern WSGI server for performance. Docker containers run each service separately. Nginx handles load balancing and routing.

⁠Common issues

Database connection fails:

  • Check PostgreSQL is running
  • Verify DATABASE_URL format
  • Make sure database exists

Auth errors:

  • Set TEST_MODE=true for development
  • Check Auth0 domain and audience

Port conflicts:

  • Services use ports 6001, 6002, 6003
  • Change in start_local.py if needed

Tag summary

Content type

Image

Digest

sha256:1b0f585af…

Size

159.9 MB

Last updated

3 months ago

docker pull h4mid2019/flask-react-backend