This is the backend API for a Finmate. It provides functionalities for managing user accounts, portfolios, stocks, and comments.
- Technologies Used
- Prerequisites
- Getting Started
- API Endpoints
- Database
- Docker
- API Testing
- Deployment
- Contributing
- License
- .NET 8.0: The primary framework for building the API.
- C#: The programming language used.
- ASP.NET Core: Framework for building web APIs.
- Entity Framework Core: ORM for database interactions.
- ASP.NET Core Identity: For managing user authentication and authorization.
- Newtonsoft.Json: For JSON serialization and deserialization.
- Swashbuckle/OpenAPI: For generating API documentation (Swagger UI).
- Other libraries: (e.g., for JWT authentication, logging, etc.)
Before you begin, ensure you have the following installed:
- .NET SDK 8.0
- Git for version control.
- A database system (e.g., SQL Server, PostgreSQL, SQLite) - configured in
appsettings.json. - Docker (optional, for containerization).
Follow these steps to get the backend API up and running on your local machine.
-
Open your terminal or command prompt.
-
Navigate to the directory where you want to clone the repository.
-
Run the following command:
git clone <repository_url>
(Replace
<repository_url>with the actual URL of your repository)
-
Navigate to the project directory:
cd <project_directory>
(Replace
<project_directory>with the name of the cloned repository) -
Build the solution using the .NET CLI:
dotnet build api.sln
-
Navigate to the project directory (if you are not already there).
-
Run the API using the .NET CLI:
dotnet run --project ./
This will start the API server, usually on
https://localhost:5001andhttp://localhost:5000by default. Check the console output for the exact URLs.
If your project uses Entity Framework Core, you might need to apply database migrations to create or update the database schema.
-
Navigate to the project directory.
-
Run the following command:
dotnet ef database update -p ./
This command will apply any pending migrations to your configured database. Ensure your database connection string is correctly set up in
appsettings.json. The migration files are located in theMigrations/directory.
This application relies on external APIs for certain functionalities. You will need to configure the following API keys in your appsettings.json file:
-
Open the
appsettings.jsonfile located in the project root directory. -
Locate or create a section for API keys (e.g., a top-level section or within another configuration section).
-
Add the following keys with their respective values:
{ // ... other configurations "NewsKey": "YOUR_NEWS_API_KEY", "FMPKey": "YOUR_FMP_API_KEY", "DeepSeekKey": "YOUR_DEEPSEEK_API_KEY" // ... }Replace
"YOUR_NEWS_API_KEY","YOUR_FMP_API_KEY", and"YOUR_DEEPSEEK_API_KEY"with the actual API keys you have obtained for the following services:- NewsKey: Used for accessing news data, likely through the
INewsService. - FMPKey: Used for accessing financial data from Financial Modeling Prep, likely through the
IFMPService. - DeepSeekKey: Used for interacting with the DeepSeek AI service, likely through the
IAIService.
Important: Treat these API keys as sensitive information. Do not commit them directly to version control. Consider using environment variables or other secure methods for managing sensitive configuration in production environments. You might also have an
appsettings.Development.jsonfile for development-specific configurations where you can store these keys during development. - NewsKey: Used for accessing news data, likely through the
Based on the controller names, here are some of the likely API endpoints:
- Account:
/api/Account/Register(POST): For registering new users./api/Account/Login(POST): For logging in existing users.
- Stock:
/api/Stock(GET, POST, PUT, DELETE): For managing stock information.
- Comment:
/api/Comment(GET, POST, PUT, DELETE): For managing comments on stocks.
- Portfolio:
/api/Portfolio(GET, POST, PUT, DELETE): For managing user portfolios.
For detailed information about all available endpoints, their request and response formats, and authentication requirements, please refer to the generated API documentation (likely accessible via Swagger UI at a URL like https://localhost:5001/swagger/index.html or http://localhost:5000/swagger/index.html when the application is running).
The application uses Entity Framework Core to interact with a relational database. The specific database provider (e.g., SQL Server, PostgreSQL, SQLite) and connection details are configured in the appsettings.json file.
The project includes a Dockerfile for containerizing the application using Docker.
-
Navigate to the project root directory (where the
Dockerfileis located). -
Build the Docker image:
docker build -t stock-portfolio-api .(Replace
stock-portfolio-apiwith your desired image name) -
Run the Docker container:
docker run -p 8080:80 stock-portfolio-api
(Replace
8080with the desired host port and80with the container port if different)
The API will then be accessible at http://localhost:8080 (or the port you specified).
The file api.http suggests the presence of HTTP request definitions that can be used with tools like the REST Client extension in VS Code or similar HTTP client tools for testing the API endpoints.
The application can be deployed in various ways, including:
- Directly on a server: After building, the application can be run using
dotnet runon a server environment. You might need to configure a web server like Nginx or Apache as a reverse proxy. - Using Docker: The provided
Dockerfilecan be used to create a Docker image that can be deployed to container orchestration platforms like Kubernetes or Docker Compose. - Azure App Service: The application can be easily deployed to Azure App Service.
- AWS Elastic Beanstalk: Similar deployment options are available on AWS.
The contents of the /publish directory are typically used for deployment.
Contributions to this project are welcome. Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your fork.
- Submit a pull request.