Smart Mess Project Coding Standard
Tech Stack:
Frontend: Flutter
Backend: Python (Flask / FastAPI / Django REST)
Database: MongoDB
1. General Guidelines
Follow clean architecture: Frontend ↔ API ↔ Database.
Each module should have one clear responsibility.
Use consistent naming, comments, and clear folder structure.
Follow null-safety, error handling, and security best practices.
2. Folder Structure
1. Frontend (Flutter)
lib/
├── core/
│ ├── constants/
│ ├── theme/
│ ├── utils/
│ └── widgets/
├── data/
│ ├── models/
│ ├── services/
│ └── repositories/
├── presentation/
│ ├── screens/
│ │ ├── login/
│ │ ├── home/
│ │ ├── menu/
│ │ ├── payment/
│ │ └── profile/
│ └── widgets/
└── providers/ # state management
2 Backend (Python)
backend/
├── app/
│ ├── __init__.py
│ ├── routes/
│ │ ├── user_routes.py
│ │ ├── menu_routes.py
│ │ ├── transaction_routes.py
│ │ └── auth_routes.py
│ ├── models/
│ │ ├── user_model.py
│ │ ├── menu_model.py
│ │ └── transaction_model.py
│ ├── controllers/
│ ├── services/
│ └── utils/
├── [Link]
└── [Link]
3 Database (MongoDB)
Collections:
o users
o menus
o transactions
o payments
Use consistent schema naming and indexes for performance.
3. Naming Conventions
Component Convention Example
Class PascalCase UserModel, TransactionService
Function camelCase getUserData(), calculateTotal()
Variable camelCase userEmail, menuList
File snake_case user_model.dart, auth_routes.py
Constant UPPER_CASE MAX_LIMIT, API_URL
4. Flutter Coding Standard
Best Practices
Use MVVM or Provider for state management.
Avoid direct API calls in UI — use Repository classes.
Keep UI responsive using MediaQuery or LayoutBuilder.
Store all colors, fonts, and paddings in [Link].
Use reusable widgets for buttons, cards, text fields, etc.
Avoid
Inline styling
Business logic inside widgets
Hardcoded strings (use constants or localization)
5. Python Backend Coding Standard
Code Style
Follow PEP8 coding style.
Indent with 4 spaces.
Use type hints:
def get_user_by_email(email: str) -> dict:
...
API Development
Use RESTful API structure:
o GET /users → fetch users
o POST /menu → add menu item
o PUT /transaction/{id} → update
o DELETE /menu/{id} → remove item
Error Handling
Use unified error response:
return jsonify({"status": "error", "message": "Invalid input"}), 400
Security
Use environment variables for secrets (.env).
Validate all inputs before saving to DB.
Use JWT authentication for login sessions.
Sanitize user data before inserting to MongoDB.
6. MongoDB Standards
Schema Example
user_schema = {
"name": "string",
"email": "string",
"room": "string",
"due_amount": "float",
"created_at": "datetime"
}
Guidelines
Always use indexes on frequently queried fields (e.g., email, room).
Use ObjectId for primary keys.
Maintain referential consistency between collections.
Validate data before insertion.
7. API & Frontend Integration
All API endpoints should return JSON.
Use consistent response format:
{
"success": true,
"message": "Data fetched successfully",
"data": [...]
}
Handle API responses in Flutter with try-catch:
try {
final response = await [Link]();
} catch (e) {
showErrorSnackBar('Server not reachable');
}
8. Security Standards
Use HTTPS for all API calls.
Never expose API URLs or keys in Flutter code — store them in .env.
Encrypt passwords (e.g., bcrypt in Python).
Validate all user input (frontend + backend).
9. Testing
Unit Tests for Python models and APIs (pytest).
Widget Tests for Flutter UI components.
Integration Tests for API and database connectivity.
10. Version Control
Branch naming:
o feature/menu-screen
o fix/login-bug
o update/api-endpoints
Commit format:
feat: add weekly meal update API
fix: resolve crash on payment screen
Do not push .env or credentials.
11. Documentation
Use clear docstrings in Python:
"""Fetch all users from database."""
Add file headers in Dart:
/// MenuScreen - displays weekly meal plan for the mess
Maintain a project README with:
o Installation steps
o Tech stack
o Folder structure
o API endpoints
o Team members
12. Final Code Review Checklist
Before submission or push:
Proper naming and folder structure
No unused imports or print statements
Error handling in all API calls
Null safety in Flutter
API tested in Postman
MongoDB schema validated
Secure credentials
Reusable widgets and clean