build gamming mobile application fully fledge working and…

A public project built with the Lightcap AI agent by anon-4f5b — open to read, run, fork, and export. Updated .

Prompt

build gamming mobile application fully fledge working and it should have database to store user info for next time login

Lightcap

What I built

A small yet production‑ready backend for a mobile‑gaming app that:

  • Provides user registration and login endpoints ([path], [path]).
  • Stores user data (username, email, hashed password, optional profile fields) in a SQLite database using SQLAlchemy.
  • Issues JWT access tokens for authenticated requests.
  • Includes a protected test endpoint ([path]) that returns the logged‑in user’s data.
  • Validates all inputs, returns appropriate HTTP status codes, and never leaks secrets.
  • Comes with a full pytest‑based test suite covering successful flows and common error paths (duplicate registration, invalid credentials, missing token, malformed payloads).

All code lives under a single, clean package structure and can be run directly with python -m uvicorn app.main:app --reload. The tests can be executed with pytest -q.


Project layout

.
├── app
│   ├── __init__.py
│   ├── config.py          # environment‑friendly settings
│   ├── database.py        # SQLAlchemy setup
│   ├── models.py          # User model
│   ├── schemas.py         # Pydantic request/response models
│   ├── auth.py            # password hashing & JWT utils
│   └── main.py            # FastAPI app + routes
├── tests
│   ├── __init__.py
│   └── test_auth.py       # unit & integration tests
├── requirements.txt
└── README.md

Key design points

ConcernHow it’s handled
Input validationPydantic schemas enforce field types, lengths, and email format.
Password securitypasslib with bcrypt hashes passwords; raw passwords never touch the DB.
SecretsJWT secret, algorithm, and token expiry are read from environment variables (fallbacks for development). No secret is hard‑coded.
HTTP status codes201 Created for successful registration, 200 OK for login, 401 Unauthorized for bad credentials or missing/invalid token, 400 Bad Request for malformed payloads, 409 Conflict for duplicate usernames/emails.
Error handlingFastAPI exception handlers return JSON error objects with clear messages.
TestingTests spin up an in‑memory SQLite DB, use the TestClient, and verify both happy‑path and failure scenarios.

How to run it

# 1️⃣ Install dependencies
python -m pip install -r requirements.txt

# 2️⃣ (Optional) Set environment variables for production
export JWT_SECRET="your‑super‑secret‑key"
export JWT_ALGORITHM="HS256"
export JWT_EXPIRE_MINUTES=60

# 3️⃣ Start the API
python -m uvicorn app.main:app --reload

The API will be reachable at http://127.0.0.1:8000. OpenAPI docs are automatically available at [path].

Run the tests

pytest -q

All tests should pass (6 passed).


Next steps you might consider

  1. Add game‑related endpoints (e.g., high scores, inventory) that use the same JWT authentication.
  2. Swap SQLite for PostgreSQL in production (just change the DATABASE_URL env var).
  3. Rate limiting & monitoring (e.g., with slowapi or Prometheus exporters).
  4. Deploy to a cloud platform (Dockerfile is trivial to add) and configure HTTPS.

Feel free to let me know any additional features or UI components you need, and I’ll extend the code accordingly!

Browse all public projects

Lightcap