Backend Server Configuration
Relevant source files
The following files were used as context for generating this wiki page:
The NEXUS backend server is a FastAPI-based application designed to manage digital accounts, email addresses, and free trial tracking. It serves as the "Digital Command Center," providing a robust API for the Frontend Application to perform CRUD operations, manage authentication via JWT, and retrieve dashboard statistics.
The server utilizes an asynchronous architecture with motor for MongoDB interactions and incorporates security measures such as bcrypt password hashing and HTTP Bearer token validation.
Sources: backend/server.py:1-25, test_result.md:65-70
Architecture and Core Components
The backend is structured around a central FastAPI instance that handles routing, middleware, and database connectivity. The application logic is divided into specialized routers and dependency-injected authentication helpers.
Technology Stack
| Component | Technology | Description |
|---|---|---|
| Framework | FastAPI | High-performance Python web framework. |
| Database | MongoDB | NoSQL database accessed via the motor async driver. |
| Authentication | JWT & HTTPBearer | Secure token-based access control. |
| Security | Bcrypt | Password hashing for user credentials. |
| Schema | Pydantic | Data validation and settings management. |
Sources: backend/server.py:1-20, frontend/package.json:65-75
Database Integration
The system connects to MongoDB using environment variables for the connection string (MONGO_URL) and database name (DB_NAME). It uses AsyncIOMotorClient to ensure non-blocking I/O operations.
The diagram shows the relationship between the FastAPI application and the asynchronous MongoDB collections.
Sources: backend/server.py:27-31
Authentication System
The server implements a JWT (JSON Web Token) authentication flow. Users must register or log in to obtain a Bearer token, which is then required for all protected API endpoints.
Authentication Flow
- Registration/Login: User provides credentials to
/api/registeror/api/login. - Token Generation: Server validates credentials, hashes passwords using bcrypt, and returns an
access_token. - Verification: Subsequent requests include the token in the
Authorizationheader. - Dependency Injection: The
get_current_userfunction usesverify_tokento decode the JWT and fetch the user from the database.
This sequence illustrates the login and subsequent protected route access.
Sources: backend/server.py:175-225, backend_test.py:75-125
Configuration Parameters
| Parameter | Default Value | Description |
|---|---|---|
SECRET_KEY | nexus-super-secret... | Key used for JWT signature. |
ALGORITHM | HS256 | Hashing algorithm for tokens. |
ACCESS_TOKEN_EXPIRE_MINUTES | 30 | Token validity duration. |
Sources: backend/server.py:39-42
API Modules and Models
The backend exposes several CRUD modules, each governed by specific Pydantic models to ensure data integrity.
Account Management
Manages platform credentials and subscription details.
- Endpoint Prefix:
/api/accounts - Key Fields:
platform_name,subscription_type,monthly_cost,two_fa_enabled.
Email Management
Tracks email addresses used for various digital services.
- Endpoint Prefix:
/api/emails - Key Fields:
email_address,provider,purpose(Enum: PERSONAL, WORK, TRIALS, etc.).
Trial Tracking
Monitors free trial periods and cancellation deadlines.
- Endpoint Prefix:
/api/trials - Logic: Calculates
cancellation_deadlineand tracksis_cancelledstatus.
Sources: backend/server.py:112-168, backend_test.py:130-330
Dashboard Statistics
The /api/dashboard/stats endpoint aggregates data across all collections for the authenticated user to provide a high-level overview of their digital footprint.
| Statistic | Calculation Logic |
|---|---|
total_accounts | Count of documents in accounts collection for user_id. |
monthly_spend | Sum of monthly_cost from all user accounts. |
active_trials | Count of trials where is_cancelled is False. |
security_score | Placeholder logic (defaulting to 75.0) for future implementation. |
Sources: backend/server.py:378-403, backend_test.py:335-355
Middleware and CORS Configuration
The server includes CORSMiddleware to facilitate communication with the React frontend.
- Allowed Origins: Configurable via
CORS_ORIGINSenvironment variable (defaults to*). - Allowed Methods: Supports all standard HTTP methods (
GET,POST,PUT,DELETE). - Logging: Configured at the
INFOlevel to track requests and system errors.
Sources: backend/server.py:408-423, frontend/src/App.js:7-10
The Backend Server Configuration ensures a secure, scalable, and isolated environment for users to manage their sensitive account data, providing the foundational logic for the NEXUS ecosystem.