FastAPI messaging app with a simple HTML frontend. Admins can create users, send messages, attach files, and view sent/inbox messages. Users can log in, read messages, mark them as read, and download attachments.
- Admin and user login with JWT authentication
- Admin user management
- Send messages from admin to users
- Optional file attachment for each message
- Inbox and sent message views
- Soft-delete users so message history remains visible
- PostgreSQL/Neon database support
- Docker and Docker Compose support
The app uses PostgreSQL through DATABASE_URL.
Example .env:
DATABASE_URL=postgresql://USER:PASSWORD@HOST/neondb?sslmode=require
SECRET_KEY=SUPER_SECRET_KEY_CHANGE_MEFor Neon, paste your Neon connection string as DATABASE_URL.
Run database.sql once in Neon SQL Editor if your database is empty.
Default login after running the schema:
username: admin
password: admin123
If the admin password is wrong, reset it in Neon SQL Editor:
UPDATE users
SET password_hash = 'admin123'
WHERE username = 'admin';After the next successful login, the app automatically upgrades that password to a bcrypt hash.
From PowerShell:
cd C:\Users\Sepehr\admin_messanger
docker compose up --buildOpen:
http://localhost:8000
Stop:
docker compose downRun in background:
docker compose up --build -dShow logs:
docker compose logs -fCheck which database Docker is using:
docker exec admin-messanger python -c "from app.database import engine; print(engine.url.render_as_string(hide_password=True))"Build:
docker build -t admin-messanger .Run:
$uploadPath = Join-Path (Get-Location) "uploads"
New-Item -ItemType Directory -Force -Path $uploadPath
docker run --rm --name admin-messanger `
--env-file .env `
-p 8000:8000 `
-v "${uploadPath}:/app/uploads" `
admin-messangerInstall dependencies:
python -m pip install -r requirements.txtStart the app:
uvicorn main:app --host 127.0.0.1 --port 8000 --reloadOpen:
http://localhost:8000
Use these settings when a FastAPI cloud host asks for commands.
Build command:
pip install -r requirements.txtStart command:
uvicorn main:app --host 0.0.0.0 --port $PORTIf your host does not provide $PORT, use:
uvicorn main:app --host 0.0.0.0 --port 8000Required environment variables:
DATABASE_URL=postgresql://USER:PASSWORD@HOST/neondb?sslmode=require
SECRET_KEY=SUPER_SECRET_KEY_CHANGE_MEImportant for attachments: uploaded files are stored in:
uploads/message_attachments
On most cloud hosts, local files disappear after redeploy unless you configure persistent storage. For production, mount persistent storage to /app/uploads.
- Open
http://localhost:8000. - Log in as
admin / admin123. - Create a normal user.
- Send a message to that user ID.
- Attach a file before sending.
- Log in as the user.
- Open inbox, open the message, and download the attachment.
FastAPI docs are available at:
http://localhost:8000/docs