Skip to content
cloak720Public

About

Campus lost & found portal built with Flask, MySQL and React

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฆ Lost-It: Campus Lost & Found Office

Lost-It is a full-stack web app that helps students get lost things back, built as a campus Lost & Found Office:

  • ๐Ÿ“ฆ The Found Room. Found items are sorted into 3D cardboard boxes, one per category. Hover a box and its flaps lift while the items peek out. Click it to open the box and browse a catalogue of everything inside.
  • ๐Ÿ“œ The Wanted Board. Lost items become bounty-style WANTED posters nailed to a wooden wall, with a reward.
  • ๐Ÿ”Ž Smart matching links posters to boxed items automatically, and people message each other inside the app.
  • โ˜… Admins moderate posts, block users, manage categories and places, and see dashboard charts.
  • โ˜€๏ธ / ๐ŸŒ™ Day & Night themes. One click swaps the whole palette: a sunny notebook-paper look by day, an indigo late-night-library look by night (the Found Room's bulb even switches on).

Tech stack: Python ยท Flask (REST API) ยท MySQL ยท React (Vite) ยท pure CSS 3D (no 3D libraries)

Open in GitHub Codespaces

Click the button to run the whole app (Flask + MySQL + React) in your browser. Nothing to install. See Run it in GitHub Codespaces below.


โœจ Features

Feature What it does
๐Ÿ” Accounts & roles Sign up / log in, passwords hashed with Werkzeug, JWT tokens, two roles: user and admin
๐Ÿ“ฆ Found Room Category boxes built from 6 CSS faces; flaps animate open; a catalogue per box with search and filters
๐Ÿ“œ Wanted Board Parchment bounty posters with photo, last-seen place, date and reward
๐Ÿ“ Report form Live preview of your poster or claim tag as you type, plus optional photo upload
๐Ÿค Smart matching Scores lost โ†” found items by category, place, date and shared keywords
๐Ÿ’ฌ Messaging Contact the finder or owner without sharing phone numbers, with an unread badge
โœ… Case closed Owners (or admins) mark items returned, and they get a RECOVERED / CLAIMED stamp
โ˜… Admin desk Stats, charts by category and location, block/unblock users, promote admins, moderate items, manage categories and places
โ˜€๏ธ๐ŸŒ™ Themes Day/Night toggle with its own colour palette for each mode, remembered per browser; follows the device setting on first visit
๐Ÿ“ฑ Mobile App-style bottom tab bar on phones

Roles

User Admin
Post, browse, search, see matches, message โœ… โœ…
Close / delete own items โœ… โœ…
Close / delete any item โŒ โœ…
Block / unblock users, make admins โŒ โœ…
Add / delete categories and places โŒ โœ…
Admin dashboard โŒ โœ…
Read other people's messages โŒ โŒ (privacy)

Roles are enforced in the backend with two custom Python decorators in backend/auth_utils.py:

@bp.post("")
@user_required          # logged in AND not blocked
def create_item(): ...

@bp.get("/stats")
@admin_required         # logged in, not blocked, AND role == 'admin'
def dashboard(): ...

The role and blocked status are read from the database on every request, so blocking someone takes effect immediately, even if they're already logged in.

How matching works

For every item, Lost-It looks at open items of the opposite type in the same category within 30 days, then scores them:

Rule Points
Same category (required) 40
Same location 30
Shared keywords in title/description up to 20 (7 per word)
Dates within 3 days / 7 days 10 / 5

Items scoring 50 or more are shown, best first, with the reasons listed. See backend/routes/matching.py.


๐Ÿ—๏ธ Architecture

flowchart LR
    U[Browser<br/>React app] -- "fetch /api/... (JSON + JWT)" --> F[Flask REST API]
    F -- "@user_required / @admin_required" --> F
    F -- "SQL via PyMySQL" --> D[(MySQL<br/>lost_it)]
    F -- "save / serve" --> I[/uploads folder<br/>item photos/]
Loading

๐Ÿ—„๏ธ Database design (ER diagram)

erDiagram
    USERS ||--o{ ITEMS : posts
    CATEGORIES ||--o{ ITEMS : groups
    LOCATIONS ||--o{ ITEMS : "lost/found at"
    ITEMS ||--o{ MESSAGES : "is about"
    USERS ||--o{ MESSAGES : sends
    USERS ||--o{ MESSAGES : receives

    USERS {
        int id PK
        varchar name
        varchar email UK
        varchar password_hash
        varchar phone
        enum role "user | admin"
        boolean is_active
        timestamp created_at
    }
    CATEGORIES {
        int id PK
        varchar name UK
        varchar icon
    }
    LOCATIONS {
        int id PK
        varchar name UK
    }
    ITEMS {
        int id PK
        int user_id FK
        enum type "lost | found"
        varchar title
        text description
        int category_id FK
        int location_id FK
        date item_date
        varchar image
        varchar reward
        enum status "open | resolved"
        timestamp created_at
    }
    MESSAGES {
        int id PK
        int item_id FK
        int sender_id FK
        int receiver_id FK
        text body
        boolean is_read
        timestamp created_at
    }
Loading

Full SQL: backend/schema.sql


๐Ÿ“ Project structure

lost-it/
โ”œโ”€โ”€ backend/                 Flask + MySQL API (Python)
โ”‚   โ”œโ”€โ”€ app.py               App setup, blueprints, image serving
โ”‚   โ”œโ”€โ”€ config.py            Settings loaded from .env
โ”‚   โ”œโ”€โ”€ db.py                MySQL connection + query helpers
โ”‚   โ”œโ”€โ”€ auth_utils.py        @user_required / @admin_required decorators
โ”‚   โ”œโ”€โ”€ schema.sql           Tables + categories/locations
โ”‚   โ”œโ”€โ”€ init_db.py           Creates the database from schema.sql
โ”‚   โ”œโ”€โ”€ seed.py              Demo students, items, messages + the admin from .env
โ”‚   โ”œโ”€โ”€ make_admin.py        Promote an account to admin
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.py          /api/auth      register, login, me
โ”‚   โ”‚   โ”œโ”€โ”€ items.py         /api/items     browse, post, matches, resolve, delete
โ”‚   โ”‚   โ”œโ”€โ”€ matching.py      Match-scoring logic
โ”‚   โ”‚   โ”œโ”€โ”€ messages.py      /api/messages  private chat
โ”‚   โ”‚   โ”œโ”€โ”€ meta.py          /api/meta, /api/stats, /api/found-room
โ”‚   โ”‚   โ””โ”€โ”€ admin.py         /api/admin     dashboard, users, categories, places
โ”‚   โ””โ”€โ”€ uploads/             Uploaded photos
โ””โ”€โ”€ frontend/                React (Vite)
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ api.js           fetch wrapper (adds JWT token)
        โ”œโ”€โ”€ AuthContext.jsx  Logged-in user state
        โ”œโ”€โ”€ confetti.js      ๐ŸŽ‰ when an item is marked returned
        โ”œโ”€โ”€ components/      CrateBox (3D box), WantedPoster, FoundCard, MatchBadge,
        โ”‚                    Navbar, ThemeToggle, PageHeader
        โ”œโ”€โ”€ pages/           Home, FoundRoom, FoundBox, WantedBoard, ItemDetail,
        โ”‚                    PostItem, MyItems, Messages, Admin, Login, Register
        โ””โ”€โ”€ styles/
            โ”œโ”€โ”€ tokens.css   fonts, spacing, and the Day + Night colour themes
            โ”œโ”€โ”€ base.css     buttons, form fields, chips, stamps
            โ”œโ”€โ”€ layout.css   top bar, mobile tab bar, page headers, scenes, footer
            โ”œโ”€โ”€ home.css     home page
            โ”œโ”€โ”€ crate.css    the 3D cardboard box
            โ”œโ”€โ”€ poster.css   the WANTED poster
            โ”œโ”€โ”€ cards.css    found-item cards + match badges
            โ”œโ”€โ”€ pages.css    item page, report form, login pass, chat
            โ””โ”€โ”€ admin.css    admin desk + charts

โ˜๏ธ Run it in GitHub Codespaces (no install)

  1. On the repo page click Code โ†’ Codespaces โ†’ Create codespace on main (or the button at the top of this README).
  2. Wait 2โ€“4 minutes the first time. The Codespace installs Python, Node and MySQL, creates the database and loads the demo data (.devcontainer/setup.sh).
  3. Flask and React start by themselves in two terminals, and the site opens on port 5173.
  4. To share it: open the Ports tab, right-click port 5173 โ†’ Port Visibility โ†’ Public, and copy the link.

The Codespace stops itself after about 30 minutes of inactivity. Reopen it from the Code โ†’ Codespaces menu and everything is still there.

Admin password in Codespaces: add a Codespaces secret named ADMIN_PASSWORD (GitHub Settings โ†’ Codespaces โ†’ Secrets, allowed for this repo) before creating the Codespace. If you don't, a random admin password is generated. It's printed at the end of the creation log and saved in backend/.env inside the Codespace.

๐Ÿš€ Running it locally

You need: Python 3.10+, Node.js 18+, MySQL 8 running locally.

1. Backend (Flask)

cd backend
python -m venv .venv
.venv\Scripts\activate          # Windows  (macOS/Linux: source .venv/bin/activate)
pip install -r requirements.txt

copy .env.example .env          # macOS/Linux: cp .env.example .env
# open .env and set your MySQL password (and port, if it isn't 3306),
# plus ADMIN_NAME / ADMIN_EMAIL / ADMIN_PASSWORD for the admin account

python init_db.py               # creates the lost_it database and tables
python seed.py                  # adds demo students + creates the admin from .env
python app.py                   # API runs on http://localhost:5000

2. Frontend (React)

In a second terminal:

cd frontend
npm install
npm run dev                     # open http://localhost:5173

The React dev server forwards /api and /uploads to Flask, so both run together without extra setup.

Demo accounts (after seed.py)

Name Email Password Role
admin1 admin1@campus.edu whatever ADMIN_PASSWORD is in your .env admin
Asha Menon asha@campus.edu demo1234 user
Rahul Nair rahul@campus.edu demo1234 user
Fathima K fathima@campus.edu demo1234 user
Arjun Das arjun@campus.edu demo1234 user

The admin password lives only in .env, which is git-ignored, so it never ends up on GitHub. Change it in .env and run python seed.py again to update it. To make any other account an admin: python make_admin.py someone@campus.edu

Try this: open the Found Room and click the Electronics box. Then log in as Asha (the login page has a "Fill in a demo student" button), open the Black JBL wireless earphones poster, and scroll to Possible sightings. Rahul's found earbuds are a 100% match. Flip the โ˜€๏ธ/๐ŸŒ™ switch in the top bar to see both themes.


๐Ÿ”Œ API reference

Method Endpoint Access Description
POST /api/auth/register public Create account โ†’ token
POST /api/auth/login public Log in โ†’ token (blocked users refused)
GET /api/auth/me user Current user
GET /api/items?type=&category=&location=&q=&status= public Browse / search items
POST /api/items user Report item (multipart, optional image, reward)
GET /api/items/mine user My items
GET /api/items/<id> public Item details
GET /api/items/<id>/matches public Suggested matches with score and reasons
PATCH /api/items/<id>/status owner / admin {"status": "resolved" | "open"}
DELETE /api/items/<id> owner / admin Delete item
GET /api/found-room public Boxes per category with counts and previews
GET /api/meta ยท /api/stats public Categories, places, home page counts
GET /api/messages user My conversations
POST /api/messages user Send {item_id, body, receiver_id?}
POST /api/messages/read user Mark a chat as read
GET /api/messages/unread-count user Unread badge count
GET /api/admin/stats admin Totals, by-category and hotspot data
GET /api/admin/users admin All users with item counts
PATCH /api/admin/users/<id> admin {"is_active": false} or {"role": "admin"}
POST /api/admin/categories ยท /api/admin/locations admin Add a category / place
DELETE /api/admin/categories/<id> ยท /api/admin/locations/<id> admin Delete one that is unused

๐Ÿ”ฎ Future scope

  • Email notifications when a new match appears
  • Image-based matching
  • QR-code stickers for valuables
  • Mobile app

๐Ÿ“„ License

MIT

About

Campus lost & found portal built with Flask, MySQL and React

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages