MindCarrer Mental Health Management System: Team Coding Standards & Agile Development Practices
MindCarrer Mental Health Management System: Team Coding Standards & Agile Development Practices
Author: MindCarrer Development Team
Tags: #QtDevelopment #C++ #AgileDevelopment #CodingStandards #ProjectManagement
Category: #SoftwareEngineering
Introduction
In software development, unified coding standards and clear task planning are crucial to ensuring project quality and progress. This article shares our team's coding standards and agile development practices gained through developing the MindCarrer Mental Health Management System.
Project Background:
-
Tech Stack: Qt Creator 4.8.2 (Client) + Visual Studio 2019 (Server) + SQLite
-
Architecture: C/S architecture with dual-layer design (front-end server + back-end server)
-
Development Cycle: 10-day sprint iteration
-
Team Size: Small development team
All code standards in this article are extracted from actual project code to ensure the executability and consistency of the specifications.
1. Team Coding Standards
1.1 Naming Conventions: Clarity and Consistency are Key
Class Naming - PascalCase
All class names in our project use PascalCase, making it easy to distinguish types from variables.
// Correct Examples (from actual code)
class MainWindow : public QMainWindow
class FrontClient : public QObject
class AssessmentCache
class HomePage, ContactsPage, ChannelsPage
class BaseTask
class LoginTask : public BaseTask
class BackendDispatcher
Function Naming - camelCase
Function names use camelCase, start with a verb, and clearly express functionality.
// Correct Examples (from actual code)
void setupPages();
void setUserInfo(const QString& userId, const QString& userName);
bool connectToServer(const QString& host, int port);
bool isConnected() const; // Queries start with is/has
Variable Naming Standards
Member Variables: m_prefix + camelCase
class MainWindow {
private:
HomePage *m_homePage;
ContactsPage *m_contactsPage;
ChannelsPage *m_channelsPage;
};
Local Variables: Direct camelCase
void setupPages() {
QWidget *placeholder = ui->stackedWidget->widget(0);
SessionData sessionData = LocalStore::instance().loadSession();
}
1.2 Code Formatting Standards: Unified Style Enhances Readability
Indentation and Spacing
【Mandatory】 Use 4 spaces for indentation, tabs are prohibited.
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
private:
void setupPages();
};
Bracket Placement
Class and function definitions: Left brace on a new line (K&R variant)
class MainWindow : public QMainWindow
{
// ...
};
void MainWindow::setupPages()
{
// ...
}
Control statements: Left brace on the same line
if (placeholder) {
ui->stackedWidget->removeWidget(placeholder);
placeholder->deleteLater();
}
1.3 Comment Standards: Code is Written for People to Read
Single-line Comments
// Correct Examples (from actual code)
// Automatically connect to the front server (default 127.0.0.1:10001, adjustable as needed)
FrontClient::instance().connectToServer("127.0.0.1", 10001);
// Force fixed width to prevent child page content from stretching the window
setFixedWidth(400);
// Check if the user has completed today's assessment
if (lastAssessmentDate == QDate::currentDate()) {
return true; // Completed
}
Debug Log Format
Client: Use qDebug, format: [Module Name] Message Content
qDebug() << "[FrontClient] Main socket connected:" << connected;
qDebug() << "[AssessmentCache] History cached for user:" << userId;
1.4 Memory Management Standards: Avoid Memory Leaks
Qt Object Tree Management (Recommended)
Qt's object tree mechanism is one of its most powerful features. Proper use can greatly simplify memory management.
// Correct Example (from actual code)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// Specify parent, Qt manages memory automatically
m_homePage = new HomePage(this);
m_contactsPage = new ContactsPage(this);
}
MainWindow::~MainWindow()
{
delete ui; // Only need to manually delete ui
// Other child objects are automatically released by Qt
}
Manual Memory Management
【Mandatory】 new/delete must be paired, new[]/delete[] must be paired
// Correct Example (from actual code)
BaseTask::BaseTask(char* recv_msg_package, int len, int client_fd) {
this->recv_msg_package = new char[len];
memcpy(this->recv_msg_package, recv_msg_package, len);
}
BaseTask::~BaseTask() {
delete[] this->recv_msg_package; // new[]/delete[] paired
}
1.5 Qt Signal-Slot Standards: Type-Safe Connections
Signal Definition
class FrontClient : public QObject {
Q_OBJECT
signals:
void messageReceived(const QString& senderId,
const QString& content,
qint64 timestamp);
void connectionStateChanged(bool connected);
};
Signal-Slot Connections
【Mandatory】 Use the new syntax (Qt5+)
// Correct: New syntax (type-safe)
connect(m_settingsPage, &SettingsPage::showChangePasswordPage,
this, &MainWindow::onShowChangePasswordPage);
// Avoid: Old syntax (not recommended)
connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
1.6 Design Pattern Applications
Singleton Pattern
【Recommended】 Use static local variables for thread-safe singleton (C++11)
// Correct Example (from actual code)
class FrontClient : public QObject {
public:
static FrontClient& instance() {
static FrontClient inst; // C++11 ensures thread safety
return inst;
}
private:
FrontClient(); // Private constructor
FrontClient(const FrontClient&) = delete;
FrontClient& operator=(const FrontClient&) = delete;
};
2. Agile Development: 10-Day Sprint Practice
2.1 Sprint Goals and Background
Overall Objective
Complete the core functionality development of the MindCarrer system, achieving a complete closed-loop from user authentication to daily assessments, creating an integrated mental health platform featuring psychological evaluation, AI support, and social interaction.
Completed Foundation (Before 10-day Sprint)
-
✅ Server framework setup (frontend + backend)
-
✅ Partial client UI design
-
✅ Login and registration functionality
-
✅ Database design and initialization
-
✅ Interface design
-
✅ Daily questionnaire framework
To Be Completed in This Sprint (Within 10 Days)
-
✅ Login functionality enhancement
-
✅ Registration functionality enhancement
-
✅ Daily questionnaire assessment (Core functionality)
-
🔥🔥 Add friends and friend chat functionality (Core functionality)
-
🔥🔥 AI conversation (Core functionality)
-
Connection recovery mechanism
-
Community posting functionality
-
🔥🔥 Bookshelf and reader functionality (Core functionality)
-
Settings page
-
Password modification
-
Avatar selection
2.2 Task Breakdown and Timeline Planning
Days 1-2: Foundation Functionality Enhancement
Task 1.1: Login and Registration Enhancement
-
Priority: P0 (Highest)
-
Responsible Module: Client + Server
-
Estimated Hours: 16 hours
Subtasks:
-
Enhance login verification logic (password + verification code dual mode)
-
Optimize registration process (mobile number verification)
-
Implement session management (LocalStore)
-
Add auto-login functionality
-
Error message optimization
Acceptance Criteria:
-
100% login success rate
-
5-minute verification code validity
-
Password encrypted storage (SHA256)
-
Normal session persistence
-
Stable auto-login functionality
Technical Points:
// Session management
struct SessionData {
QString userId;
QString userName;
QString token;
QDateTime loginTime;
};
// Local storage implementation
LocalStore::instance().saveSession(sessionData);
SessionData s = LocalStore::instance().loadSession();
Task 1.2: Daily Questionnaire Core Functionality
-
Priority: P0
-
Responsible Module: Full-stack
-
Estimated Hours: 20 hours
Server-side Subtasks:
-
PullDailyQuestionTask (Pull daily questions)
-
SubmitAssessmentTask (Submit assessment)
-
CheckTodayAssessmentTask (Check completion status)
-
Scoring algorithm implementation
Client-side Subtasks:
-
DailyAssessmentPage interface enhancement
-
Question display logic
-
Answer submission process
-
Local caching mechanism (AssessmentCache)
Acceptance Criteria:
-
Correct daily question delivery
-
100% answer submission success rate
-
Accurate scoring algorithm
-
Effective caching mechanism (5 minutes)
Core Code:
// Scoring algorithm example
int calculateScore(const QVector<int>& answers) {
int totalScore = 0;
for (int i = 0; i < answers.size(); i++) {
totalScore += answers[i] * weights[i];
}
return totalScore;
}
Days 3-4: Social Functionality Development
Task 2.1: Add Friends and Friend Chat Functionality
-
Priority: P0 (Core functionality)
-
Responsible Module: Full-stack
-
Estimated Hours: 24 hours
Server-side Subtasks:
-
AddFriendTask (Friend request)
-
AcceptFriendTask (Accept friend)
-
FriendListTask (Friend list)
-
MessageTask enhancement (Message storage and forwarding)
-
Online status management
-
Message push mechanism
Client-side Subtasks:
-
ContactsPage enhancement (Friend list display, add friend interface)
-
ChatPage implementation (Message sending/receiving interface, history loading)
-
Push socket integration
Technical Architecture:
// Dual-socket architecture
QTcpSocket mainSocket; // Main socket: request-response
QTcpSocket* pushSocket; // Push socket: receive messages
Days 5-6: Content Functionality Development
Task 3.1: Community Posting Functionality
-
Priority: P1
-
Responsible Module: Full-stack
-
Estimated Hours: 12 hours
Features:
-
Anonymous posting support
-
Blog list display
-
Like and comment functionality
-
Content review mechanism
Task 3.2: Bookshelf and Reader Functionality
-
Priority: P0 (Core functionality)
-
Responsible Module: Client
-
Estimated Hours: 16 hours
Features:
-
PDF book display
-
Reading progress saving
-
Page turning functionality
-
Bookmark management
Day 7: Personal Settings Functionality
Task 4.1: Settings Page Development
-
Priority: P1
-
Responsible Module: Client
-
Estimated Hours: 8 hours
Functional Modules:
-
Personal information display
-
Avatar selector (3x3 grid)
-
Privacy settings
-
Notification management
Task 4.2: Password Modification Functionality
-
Priority: P1
-
Responsible Module: Full-stack
-
Estimated Hours: 6 hours
Security Requirements:
-
Old password verification
-
New password strength check
-
Session update
Day 8: AI Functionality Integration
Task 5.1: AI Conversation Functionality
-
Priority: P0 (Core functionality)
-
Responsible Module: Full-stack
-
Estimated Hours: 18 hours
Technical Implementation:
-
Baidu Wenxin API integration
-
Conversation context management
-
Session ID persistence
-
Token usage statistics
Day 9: System Stability
Task 6.1: Connection Recovery Mechanism
-
Priority: P1
-
Responsible Module: Client
-
Estimated Hours: 10 hours
Technical Features:
-
Heartbeat detection mechanism (30-second intervals)
-
Exponential backoff reconnection algorithm
-
Automatic re-login
-
Connection status indicator
Day 10: Testing and Acceptance
Task 7.1: Comprehensive Functional Testing
-
Priority: P0
-
Responsible Module: Testing Team
-
Estimated Hours: 8 hours
Test Scope:
-
Login/registration business testing (15 test cases)
-
Friend chat business testing (20 test cases)
-
Daily assessment business testing (12 test cases)
-
AI conversation business testing (10 test cases)
Task 7.2: Bug Fixing and Optimization
-
Priority: P0
-
Responsible Module: All Developers
-
Estimated Hours: 6 hours
Quality Goals:
-
100% test pass rate
-
Zero critical bugs
-
Performance indicators met
3. Agile Development Methodology
3.1 Scrum Framework Implementation
Our team follows the Scrum agile methodology, which emphasizes fixed rhythms, small rapid iterations, timely feedback, adapting to change, and rapid delivery.
Key Scrum Practices:
-
Sprint Planning: 1-4 week iterations with fixed length
-
Daily Stand-ups: 15-minute meetings focusing on progress and obstacles
-
Sprint Reviews: Demonstrating working software and collecting feedback
-
Sprint Retrospectives: Continuous improvement of work methods
3.2 User Stories and INVEST Principle
We follow the INVEST principle for user story creation:
-
Independent: Stories should be relatively independent
-
Negotiable: Details are not locked in too early
-
Valuable: Must deliver business value
-
Estimable: Can be sized appropriately
-
Small: Appropriate granularity (3-5 days ideally)
-
Testable: Clear acceptance criteria
3.3 Definition of Done (DoD)
We maintain a clear Definition of Done for each user story:
-
Code requirements met (reviewed, compliant, refactored)
-
Testing completed (unit, integration, system, regression)
-
No major defects
-
Documentation updated
-
Business acceptance obtained
Conclusion
Through strict coding standards and clear sprint planning, our team will complete the core functionality development of the MindCarrer Mental Health Management System within 10 days. Unified coding standards not only improved code quality but also significantly reduced maintenance costs. Agile development practices allowed us to quickly respond to requirement changes, ensuring on-time project delivery.
Key Takeaways:
-
Coding standards are the foundation of team collaboration
-
Reasonable task decomposition is key to project success
-
Continuous integration and automated testing are essential
-
Team communication and knowledge sharing are equally important
We hope our experience can provide reference for other development teams, and we welcome valuable suggestions!
Copyright Statement: This article is original by the MindCarrer development team, please indicate the source when reposting.
更多推荐
所有评论(0)