Account Management API Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
The Account Management API provides a secure, centralized interface for managing digital credentials, subscription details, and platform-specific metadata within the NEXUS ecosystem. It enables users to store, retrieve, update, and delete account information while maintaining strict user isolation through JWT-based authentication.
The system is designed to handle diverse account types, ranging from free tiers to paid subscriptions, and includes integrated tracking for security features like Two-Factor Authentication (2FA) and auto-renewal status. All operations are processed through the /api/accounts prefix and interact with a MongoDB backend.
Sources: backend/server.py:15-30, test_result.md:144-150
Architecture and Authentication
The API follows a RESTful architecture where every account management endpoint is protected by a Bearer Token requirement. The system uses FastAPI's HTTPBearer security scheme to verify tokens before processing any CRUD operations.
The diagram above illustrates the typical request flow for retrieving accounts, highlighting the mandatory authentication checkpoint.
Sources: backend/server.py:155-168, frontend/src/App.js:15-35
Data Models
The system utilizes Pydantic models to enforce data integrity for both storage and incoming request payloads.
Account Model Fields
The Account model represents the full state of a stored account, including internal metadata like user_id and id.
| Field | Type | Description |
|---|---|---|
id | String (UUID) | Unique identifier for the account record. |
platform_name | String | Name of the service (e.g., Netflix, GitHub). |
username | String | The login identity used for the platform. |
email_used | String | Reference to the email address identifier used. |
subscription_type | Enum | Classification: FREE, TRIAL, or PAID. |
monthly_cost | Float | Calculated monthly expenditure for the service. |
two_fa_enabled | Boolean | Security flag for Two-Factor Authentication. |
account_status | Enum | Status: ACTIVE, INACTIVE, or DELETED. |
Sources: backend/server.py:95-120, backend_test.py:160-170
Endpoint Definitions
Create Account
POST /api/accounts
Initializes a new account record. The system automatically assigns the user_id from the authenticated session to ensure the record belongs to the requesting user.
- Payload:
AccountCreatemodel. - Response: The created
Accountobject including generated UUID.
Sources: backend/server.py:236-242
Retrieve Accounts
GET /api/accounts
Returns a list of all accounts associated with the currently authenticated user.
GET /api/accounts/{account_id}
Returns a single detailed account record if it belongs to the user. Returns 404 if the account does not exist or belongs to another user.
Sources: backend/server.py:244-256, backend_test.py:194-210
Update and Delete
PUT /api/accounts/{account_id}
Updates an existing account. Requires a full AccountCreate payload.
DELETE /api/accounts/{account_id}
Permanently removes the account record from the database.
Sources: backend/server.py:258-272
Implementation Logic
The backend implementation ensures strict user isolation by always including the user_id in database queries.
# Example of user isolation in update logic
@api_router.put("/accounts/{account_id}", response_model=Account)
async def update_account(account_id: str, account_update: AccountCreate, current_user: User = Depends(get_current_user)):
# Query must match both account_id AND the current user's ID
account = await db.accounts.find_one({"id": account_id, "user_id": current_user.id})
if not account:
raise HTTPException(status_code=404, detail="Account not found")
update_dict = account_update.dict()
await db.accounts.update_one({"id": account_id}, {"$set": update_dict})
updated_account = await db.accounts.find_one({"id": account_id})
return Account(**updated_account)
Sources: backend/server.py:258-268
Dashboard Integration
The Account Management system feeds data into a specialized statistics endpoint used for the high-level Command Center overview.
This flow shows how account-level data (costs and counts) is aggregated to provide real-time dashboard updates.
The monthly_spend is calculated by summing the monthly_cost field across all accounts linked to the user's ID where the value is non-null.
Sources: backend/server.py:317-335, frontend/src/App.js:235-255
Conclusion
The Account Management API serves as the core data engine for the NEXUS platform. By combining strict JWT validation with Pydantic-enforced data structures and MongoDB's flexible storage, it provides a robust framework for digital identity and subscription tracking. The architecture ensures that users can only interact with their own data, providing a secure "Vault" experience as reflected in the frontend implementation.