How munsoc-mpstme/mundra works
Project type and purpose
• This is a RESTful backend service built with FastAPI (“MUNDRA – MUNSoc Delegate Resource Application”).
• It provides authentication, delegate management, event-specific routes (Mumbai MUN), email notifications (verification/reset), QR code generation, and backup capabilities.
• It serves mobile apps (iOS/Android “Delego”) and minimal HTML pages for QR scanning, food preferences, and password reset.
File structure
Top-level files
• app.py – FastAPI app, route registration
• auth.py – JWT and password-hashing logic
• database.py – SQLite connection / CRUD abstractions
• models.py – Pydantic schemas / domain models
• mails.py – Email sending (FastMail)
• utils.py – Helpers: QR code generation, etc.
• config.py – Environment and secret configuration
• backups/ – Placeholder for backup archives
• databases/ – Placeholder for DB files
• qrcodes/ – Directory where generated QR images are stored
• email_templates/ – HTML templates for email bodies
• templates/ – HTML pages served by some routes
• static/ – Static assets (CSS, JS, images)
Config & env
• requirements.txt, sample.env, .python-version
• .gitignore
README
• Confirms FastAPI, SQLite (main and mm.db), JWT auth, bcrypt, email via FastMail
• Lists all routes: auth, admin, delegate, Mumbai MUN, QR-related
• Highlights key features: two databases, QR generation/storage, backup endpoint
Main components & interactions
A. External clients
1. Mobile apps (iOS/Android)
2. Admin scripts or HTTP tools (curl, Postman)
3. Browser (for minimal HTML pages)
B. API Gateway (FastAPI app in app.py)
• Receives HTTP(S) requests
• Applies middleware: CORS, request validation
• Routes to handlers (auth, delegate, admin, mm, qr, food)
C. Authentication & Authorization
• auth.py issues/verifies JWT tokens
• Dependencies in routes enforce user/auth checks (get_current_user, is_admin)
D. Business Logic Modules
• Delegate management (in app.py + database.py + models.py)
• Mumbai MUN module (separate DB “mm.db”)
• QR code generation (utils.py)
• Backup service (zips both DB files)
E. Persistence Layer
• SQLite databases (main.db, mm.db) via database.py
• File storage:
– qrcodes/ for QR image files
– backups/ for zipped DB backups
F. Email Service
• mails.py uses FastMail to send verification & reset emails
• email_templates/ holds HTML templates for message bodies
G. Presentation (minimal)
• templates/ – HTML pages (scan, food, reset) rendered by FastAPI
• static/ – served assets for HTML pages
Architectural patterns and design principles
• Modular layering:
1. API layer (FastAPI routes)
2. Service layer (auth, delegate, QR, backup logic)
3. Data access layer (database.py)
• Separation of concerns: Authentication logic separated from route definitions.
• Single process, monolithic backend (no microservices) with two distinct DB files.
• Dependency injection via FastAPI’s Depends().
• Pydantic models for request/response validation.